示例#1
0
 /**
  * Get payment data for SERVER and DIRECT
  *
  * @param boolean $statusOk
  *
  * @return array
  */
 protected function getPaymentResultData($statusOk = false)
 {
     $result = array();
     if (filter_input(INPUT_GET, 'vtx')) {
         $payment = new ModelPayment();
         $result = $payment->getByVendorTxCode(filter_input(INPUT_GET, 'vtx'));
     }
     if (empty($result)) {
         $this->helperError('Transaction code is invalid: this can happen if you try to pay for multiple baskets at the same time. ' . 'Please contact [your customer service details] to check the status of your order.', url(array('server')));
     }
     $items = array();
     $basket = $this->getBasketFromProducts();
     if ($basket) {
         foreach ($basket->getItems() as $item) {
             $items[] = array('quantity' => $item->getQuantity(), 'urlImage' => $this->getProductUrlImage($item->getDescription()), 'description' => $item->getDescription());
         }
     }
     $errorMessage = '';
     if (!$statusOk) {
         switch ($result['status']) {
             case 'REJECTED':
                 $errorMessage = 'Your order did not meet our minimum fraud screening requirements.';
                 break;
             case 'ABORT':
                 $errorMessage = 'You chose to Cancel your order on the payment pages.';
                 break;
             default:
                 $errorMessage = 'ERROR.';
         }
     }
     return array('env' => $this->sagepayConfig->getEnv(), 'vendorName' => $this->sagepayConfig->getVendorName(), 'integrationType' => $this->integrationType, 'basket' => array('items' => $items), 'ord' => $result, 'stOk' => $statusOk, 'errorMessage' => $errorMessage);
 }
示例#2
0
 /**
  * Action PayPal response for direct payment
  */
 public function actionPaypalResponse()
 {
     if (!filter_input(INPUT_GET, 'vtx')) {
         $this->redirect('direct', 'failure');
     }
     $modelPayment = new ModelPayment();
     $paymentTx = $modelPayment->getByVendorTxCode(filter_input(INPUT_GET, 'vtx'));
     $data = array('VPSProtocol' => $this->sagepayConfig->getProtocolVersion(), 'TxType' => SAGEPAY_TXN_COMPLETE, 'VPSTxId' => filter_input(INPUT_POST, 'VPSTxId'), 'Amount' => number_format($paymentTx['amount'], 2), 'Accept' => filter_input(INPUT_POST, 'Status') == SAGEPAY_REMOTE_STATUS_PAYPAL_OK ? 'YES' : 'NO');
     $result = SagepayCommon::requestPost($this->sagepayConfig->getPurchaseUrl('paypal'), $data);
     $paymentDetails = array_merge(filter_input_array(INPUT_POST), $result);
     $status = 'failure';
     if ($result['Status'] == SAGEPAY_REMOTE_STATUS_OK || $result['Status'] == SAGEPAY_REMOTE_STATUS_REGISTERED) {
         $status = 'success';
         $surcharge = isset($result['Surcharge']) ? floatval($result['Surcharge']) : 0.0;
         $paymentDetails['Amount'] = floatval($paymentTx['amount']) + $surcharge;
         if ($result['Status'] == SAGEPAY_REMOTE_STATUS_OK && $paymentTx['transactionType'] !== SAGEPAY_TXN_DEFERRED) {
             $paymentDetails['CapturedAmount'] = $paymentDetails['Amount'];
         }
     }
     $modelPayment->update(filter_input(INPUT_GET, 'vtx'), $paymentDetails);
     $this->redirect('direct', $status, filter_input_array(INPUT_GET));
 }
示例#3
0
 /**
  * Action authorise the transaction
  */
 public function actionAuthorise()
 {
     $errorMessage = '';
     // Check if form was submitted
     if (filter_input(INPUT_POST, 'origVtx')) {
         $payment = new ModelPayment();
         $paymentTxOrig = $payment->getByVendorTxCode(filter_input(INPUT_POST, 'origVtx'));
         $data = array('VPSProtocol' => $this->sagepayConfig->getProtocolVersion(), 'TxType' => SAGEPAY_TXN_AUTHORISE, 'Vendor' => $this->sagepayConfig->getVendorName(), 'VendorTxCode' => filter_input(INPUT_POST, 'VendorTxCode'), 'Amount' => filter_input(INPUT_POST, 'Amount'), 'Description' => filter_input(INPUT_POST, 'Description'), 'RelatedVPSTxID' => $paymentTxOrig['vpsTxId'], 'RelatedVendorTxCode' => filter_input(INPUT_POST, 'origVtx'), 'RelatedSecurityKey' => $paymentTxOrig['securityKey'], 'ApplyAVSCV2' => filter_input(INPUT_POST, 'ApplyAvsCv2'));
         $errorMessage = $this->validateAuthoriseAction($paymentTxOrig, $data);
         // Check if authorise was failed
         if (!$errorMessage) {
             $response = SagepayCommon::requestPost($this->sagepayConfig->getSharedUrl('authorise'), $data);
             if ($response['Status'] == SAGEPAY_REMOTE_STATUS_OK) {
                 $paymentTxOrig['CapturedAmount'] = $paymentTxOrig['capturedAmount'] + filter_input(INPUT_POST, 'Amount');
                 $paymentTxOrig['Status'] = SAGEPAY_REMOTE_STATUS_AUTHENTICATED;
                 $payment->update(filter_input(INPUT_POST, 'origVtx'), $paymentTxOrig);
                 $paymentTxOrig = $this->ucFirstFields($paymentTxOrig);
                 $paymentTx = array_merge($paymentTxOrig, $data, $response);
                 $paymentTx['StatusDetail'] = SAGEPAY_TXN_AUTHORISE . ' transaction taken through Order Admin area.';
                 $paymentTx['CapturedAmount'] = filter_input(INPUT_POST, 'Amount');
                 $payment->insert($paymentTx);
             }
             $query = array('requestBody' => SagepayUtil::arrayToQueryString($data), 'resultBody' => SagepayUtil::arrayToQueryString($response), 'status' => $response['Status'], 'command' => SAGEPAY_TXN_AUTHORISE);
             $this->redirect($this->integrationType, 'admin_result', $query);
         }
     } else {
         if (filter_input(INPUT_GET, 'origVtx')) {
             $payment = new ModelPayment();
             $paymentTxOrig = $payment->getByVendorTxCode(filter_input(INPUT_GET, 'origVtx'));
         } else {
             $this->redirect($this->integrationType, 'admin');
         }
     }
     $view = new HelperView('admin/authorise');
     $view->setData(array('env' => $this->sagepayConfig->getEnv(), 'vendorName' => $this->sagepayConfig->getVendorName(), 'integrationType' => $this->integrationType, 'result' => $paymentTxOrig, 'val' => array('ok' => true), 'newVtx' => SagepayCommon::vendorTxCode(time(), SAGEPAY_TXN_AUTHORISE, $this->sagepayConfig->getVendorName()), 'actionUrl' => url(array($this->integrationType, 'authorise')) . '?origVtx=' . filter_input(INPUT_GET, 'origVtx'), 'error' => $errorMessage ? true : false, 'message' => $errorMessage));
     $view->render();
 }
示例#4
0
 /**
  * Notify page, used for server ONLY
  */
 public function actionNotify()
 {
     $payment = new ModelPayment();
     $result = $payment->getByVendorTxCode(filter_input(INPUT_POST, 'VendorTxCode'));
     $siteFqdn = $this->sagepayConfig->getSiteFqdn();
     SagepayUtil::log('NOTIFY:' . PHP_EOL . json_encode(filter_input_array(INPUT_POST)));
     $vtxData = filter_input_array(INPUT_POST);
     if (in_array(filter_input(INPUT_POST, 'Status'), array(SAGEPAY_REMOTE_STATUS_OK, SAGEPAY_REMOTE_STATUS_AUTHENTICATED, SAGEPAY_REMOTE_STATUS_REGISTERED))) {
         $surcharge = floatval(filter_input(INPUT_POST, 'Surcharge', FILTER_VALIDATE_FLOAT));
         $vtxData['Amount'] = $result['amount'] + $surcharge;
         if (filter_input(INPUT_POST, 'TxType') == SAGEPAY_REMOTE_STATUS_PAYMENT) {
             $vtxData['CapturedAmount'] = $vtxData['Amount'];
         }
         $data = array("Status" => SAGEPAY_REMOTE_STATUS_OK, "RedirectURL" => $siteFqdn . 'server/success?vtx=' . filter_input(INPUT_POST, 'VendorTxCode'), "StatusDetail" => 'The transaction was successfully processed.');
     } else {
         $data = array("Status" => SAGEPAY_REMOTE_STATUS_OK, "RedirectURL" => $siteFqdn . 'server/failure?vtx=' . filter_input(INPUT_POST, 'VendorTxCode'), "StatusDetail" => filter_input(INPUT_POST, 'StatusDetail'));
     }
     $vtxData['AllowGiftAid'] = filter_input(INPUT_POST, 'GiftAid');
     $payment->update(filter_input(INPUT_POST, 'VendorTxCode'), $vtxData);
     echo SagepayUtil::arrayToQueryString($data, "\n");
 }