/** * Action register page for server payment */ public function actionRegister() { $profile = HelperCommon::getStore(self::SESSION_KEY_PROFILE); $this->sagepayConfig->setServerProfile($profile); $api = $this->buildApi(); $api->setVpsServerUrl($this->purchaseUrl); $result = $api->createRequest(); if ($result['Status'] != SAGEPAY_REMOTE_STATUS_OK) { $this->redirect('server', 'confirm', array('error' => base64_encode($result['StatusDetail']))); } $data = array_merge($api->getData(), $result); // Insert Payment in db $payment = new ModelPayment(); $payment->insert($data); // Clear all session not products HelperCommon::clearStore(array('sagepay_server_profile', 'isDeliverySame', 'details', 'extra', 'VendorTxCode')); if ($profile == SAGEPAY_SERVER_PROFILE_LOW) { HelperCommon::setStore('txData', $result); $this->redirect('server', 'low-profile'); } header('Location: ' . $result['NextURL']); exit; }
/** * 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(); }
/** * Action register page for direct payment */ public function actionRegister() { $api = $this->buildApi(); $card = HelperCommon::getStore('card'); $siteFqdn = $this->sagepayConfig->getSiteFqdn(); // Check cardType if ($card['cardType'] == 'PAYPAL') { $api->setIntegrationMethod(SAGEPAY_PAYPAL); $this->sagepayConfig->setPaypalCallbackUrl(url('direct/paypal-response', $siteFqdn)); } $account = HelperCommon::getStore('account'); $api->setPaneValues($card + $account); $api->setVpsDirectUrl($this->purchaseUrl); $response = $api->createRequest(); $data = $api->getData(); $data += $response; // Insert in database $payment = new ModelPayment(); $payment->insert($data); // Redirect $vtxQuery = array('vtx' => $data['VendorTxCode']); if ($response['Status'] == SAGEPAY_REMOTE_STATUS_PAYPAL_REDIRECT) { header('Location: ' . $response['PayPalRedirectURL']); exit; } else { if ($response['Status'] == "3DAUTH") { $threeDSecure = array('MD' => $response['MD'], 'ACSURL' => $response['ACSURL'], 'PaReq' => $response['PAReq'], 'TermUrl' => url(array('direct', 'three-d-secure-result'), $siteFqdn) . '?' . SagepayUtil::arrayToQueryString($vtxQuery)); HelperCommon::setStore('3DAUTH', $threeDSecure); $this->redirect('direct', 'three-d-secure', $vtxQuery); } else { if (in_array($response['Status'], array(SAGEPAY_REMOTE_STATUS_OK, SAGEPAY_REMOTE_STATUS_REGISTERED))) { if ($data['TxType'] == SAGEPAY_REMOTE_STATUS_PAYMENT) { $surcharge = isset($response['Surcharge']) ? floatval($response['Surcharge']) : 0.0; $paymentTx = array('CapturedAmount' => floatval($data['Amount']) + $surcharge, 'Amount' => floatval($data['Amount']) + $surcharge); $payment->update($data['VendorTxCode'], $paymentTx); } $this->redirect('direct', 'success', $vtxQuery); } } } $this->redirect('direct', 'failure', $vtxQuery); }