/** * 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(); }