예제 #1
0
 public function postback()
 {
     $logger = OW::getLogger('billingccbill');
     $logger->addEntry(print_r($_POST, true), 'postback.data-array');
     $logger->writeLog();
     $clientAccnum = $_POST['clientAccnum'];
     $clientSubacc = $_POST['clientSubacc'];
     $amount = $_POST['initialPrice'] ? $_POST['initialPrice'] : $_POST['recurringPrice'];
     $saleHash = $_POST['custom'];
     $transId = $_POST['subscription_id'];
     $digest = $_POST['responseDigest'];
     if (!mb_strlen($saleHash) || !mb_strlen($transId)) {
         exit;
     }
     $billingService = BOL_BillingService::getInstance();
     $adapter = new BILLINGCCBILL_CLASS_CcbillAdapter();
     $sale = $billingService->getSaleByHash($saleHash);
     if (!$sale) {
         exit;
     }
     if ($amount != $sale->totalAmount) {
         $logger->addEntry("Wrong amount: " . $amount, 'postback.amount-mismatch');
         $logger->writeLog();
         exit;
     }
     if ($billingService->getGatewayConfigValue(BILLINGCCBILL_CLASS_CcbillAdapter::GATEWAY_KEY, 'clientAccnum') != $clientAccnum) {
         $logger->addEntry("Wrong CCBill account: " . $clientAccnum, 'postback.account-mismatch');
         $logger->writeLog();
         exit;
     }
     if ($adapter->transactionApproved($clientAccnum, $clientSubacc, $transId, $digest)) {
         if ($sale->status != BOL_BillingSaleDao::STATUS_DELIVERED) {
             $sale->transactionUid = $transId;
             if ($billingService->verifySale($adapter, $sale)) {
                 $sale = $billingService->getSaleById($sale->id);
                 $productAdapter = $billingService->getProductAdapter($sale->entityKey);
                 if ($productAdapter) {
                     $billingService->deliverSale($productAdapter, $sale);
                 }
             }
         }
     }
     exit;
 }