function post_xhr($type) { if ($this->checkAuth()) { $headers = getallheaders(); $userPay = new PaymentSystem(); $userPay->loadUser(mb_strtolower($headers['Auth-User'])); if ($type == 'profiles') { if (isset($_POST['cardType'], $_POST['cardEnding'], $_POST['cardName'], $_POST['beanStreamProfileID'])) { $return = $userPay->addPaymentProfile($_POST['cardType'], $_POST['cardEnding'], $_POST['cardName'], $_POST['beanStreamProfileID']); if ($return !== false) { echo json_encode(StatusReturn::S200(array('paymentProfileID' => $return)), JSON_NUMERIC_CHECK); } else { echo json_encode(StatusReturn::E400('Saving Profile Failed!')); } } else { echo json_encode(StatusReturn::E400('Missing Variables!')); } } else { if ($type == 'invoices') { if (isset($_POST['invoiceIDs'], $_POST['paymentMethodID']) && PaymentMethod::isValidValue($_POST['paymentMethodID'], false)) { if ($_POST['paymentMethodID'] == PaymentMethod::BitPay) { if (isset($_POST['markAsPending'])) { $return = $userPay->updateInvoicesPending($_POST['invoiceIDs']); if ($return) { echo json_encode(StatusReturn::S200()); } else { echo json_encode(StatusReturn::E400('One or More Failed To be Marked as Pending!')); } } else { $return = $userPay->makePayment($_POST['invoiceIDs'], $_POST['paymentMethodID']); if ($return != '' && $return !== false) { echo json_encode(StatusReturn::S200(array('bitPayURL' => $return))); } else { echo json_encode(StatusReturn::E400('Creating BitPayURL Failed!')); } } } else { if ($_POST['paymentMethodID'] == PaymentMethod::CreditCard) { $return = $userPay->makePayment($_POST['invoiceIDs'], $_POST['paymentMethodID']); if ($return) { echo json_encode(StatusReturn::S200()); } else { echo json_encode(StatusReturn::E400('One or More Failed To be Marked as Pending!')); } } else { echo json_encode(StatusReturn::E400('Incorrect Payment Method!')); } } } else { echo json_encode(StatusReturn::E400('Missing Variables!')); } } else { echo json_encode(StatusReturn::E404('404 Not Found!')); } } } }