/** * Generate values for payment. * Ensure that post data is setted to request with SagepayAbstractApi::setData() * * @see SagepayAbstractApi::createRequest() * @return array The response from Sage Pay */ public function createRequest() { $this->data = SagepayCommon::encryptedOrder($this); $this->addConfiguredValues(); $this->checkMandatoryFields(); $ttl = $this->config->getRequestTimeout(); $caCert = $this->config->getCaCertPath(); return SagepayCommon::requestPost($this->_vpsDirectUrl, $this->data, $ttl, $caCert); }
/** * Remove token from Sagepay Service * * @param string $token Token GUID provided by Sagepay service on card registration * * @return boolean */ public function remove($token) { $data = $this->_prepareRemoveData($token); $ttl = $this->_config->getRequestTimeout(); $caCert = $this->_config->getCaCertPath(); $response = SagepayCommon::requestPost($this->_removeUrl, $data, $ttl, $caCert); return ($response['Status'] == SAGEPAY_REMOTE_STATUS_OK); }
/** * 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(); }
/** * Generate values for payment. * Ensure that post data is setted to request with SagepayAbstractApi::setData() * * @see SagepayAbstractApi::createRequest() * @uses SagepayCommon::encryptedOrder * @return array The response from Sage Pay */ public function createRequest() { $this->addConfiguredValues(); return SagepayCommon::encryptedOrder($this); }
/** * 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)); }