コード例 #1
0
 /**
  * Cancel payments automatically after 90 days (30 days for Maestro)
  */
 protected function cancelPayments()
 {
     $i = 0;
     $sql = "SELECT `vendorTxCode` FROM payment WHERE status = ? AND " . "((cardType='MAESTRO' AND created <= ?) OR created <= ?)";
     $params = array(SAGEPAY_REMOTE_STATUS_AUTHENTICATED, date('Y-m-d H:i:s', strtotime('-30 days')), date('Y-m-d H:i:s', strtotime('-90 days')));
     $cancelStatus = array('Status' => SAGEPAY_REMOTE_STATUS_CANCELLED);
     $payment = new ModelPayment();
     $paymentStm = $this->dbHelper->execute($sql, $params);
     if (!$paymentStm) {
         exit('Invalid query');
     }
     $payments = $paymentStm->fetchAll(PDO::FETCH_ASSOC);
     foreach ($payments as $row) {
         if ($payment->update($row['vendorTxCode'], $cancelStatus)) {
             $i++;
         }
     }
     printf('Updated %d payments', $i);
 }
コード例 #2
0
ファイル: admin.php プロジェクト: adrianlinner333/laravel-5
 /**
  * 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();
 }
コード例 #3
0
ファイル: direct.php プロジェクト: adrianlinner333/laravel-5
 /**
  * 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));
 }
コード例 #4
0
ファイル: server.php プロジェクト: adrianlinner333/laravel-5
 /**
  * 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");
 }