function post() { if ($this->checkAuth()) { if (AvailablePaymentMethodsData::hasBitPay()) { $jsonObj = json_decode(file_get_contents("php://input")); if (json_last_error() == JSON_ERROR_NONE) { //file_put_contents('IPNData.txt', print_r($jsonObj, true)); $payment = new PaymentSystem(); $posDataObj = json_decode($jsonObj->posData); $invoiceArr = explode(',', $posDataObj->invoiceList); if (json_last_error() == JSON_ERROR_NONE) { //file_put_contents('IPNPosData.txt', print_r($invoiceArr, true)); // todo: maybe confirm posData for extra Security? if ($payment->confirmBitPayPaidComplete($jsonObj->id)) { // todo: compare amounts paid vs invoice amount //file_put_contents('here1.txt', $posDataObj->userID); $payment->updateInvoicesPaid($invoiceArr, $jsonObj->id, PaymentMethod::BitPay, $posDataObj->userID); } else { if ($payment->confirmBitPayPending($jsonObj->id)) { //file_put_contents('here2.txt', $posDataObj->userID); $payment->updateInvoicesPending($invoiceArr, $posDataObj->userID); } } } else { // todo: record error somewhere } echo json_encode(StatusReturn::S200()); } else { echo json_encode(StatusReturn::E400('Bad JSON!')); } } else { echo json_encode(StatusReturn::E404('404 Not Found!')); } } }
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!')); } } } }