Ejemplo n.º 1
0
 public function makePayment($invoiceIDs, $paymentMethodID)
 {
     $amount = 0;
     $invoiceList = '';
     $beanStreamProfileID = null;
     if (is_null($this->currentInvoices)) {
         $this->loadCurrentInvoices();
     }
     foreach ($this->currentInvoices as $invoiceValue) {
         $currentCount = 0;
         foreach ($invoiceIDs as $invoiceID) {
             $currentCount++;
             if ($invoiceValue['invoiceID'] == $invoiceID) {
                 $amount += $invoiceValue['amount'];
                 $invoiceList .= $invoiceID;
                 if (count($invoiceIDs) > $currentCount) {
                     $invoiceList .= ',';
                 }
             }
         }
     }
     if ($paymentMethodID == PaymentMethod::CreditCard && AvailablePaymentMethodsData::hasCreditCard()) {
         return $this->makePaymentCC($invoiceIDs, $invoiceList, $amount);
     } else {
         if ($paymentMethodID == PaymentMethod::BitPay && AvailablePaymentMethodsData::hasBitPay()) {
             return $this->createBitPayInvoice($invoiceList, $amount);
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 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!'));
         }
     }
 }