Exemplo n.º 1
0
 /**
  * Action repeat the transaction
  */
 public function actionRepeat()
 {
     $message = '';
     $result = array();
     $deferred = false;
     // Check original VendorTxCode
     if (filter_input(INPUT_GET, 'origVtx')) {
         $payment = new ModelPayment();
         $result = $payment->getByVendorTxCode(filter_input(INPUT_GET, 'origVtx'));
         $deferred = filter_input(INPUT_GET, 'deferred');
         $txType = $deferred == 'true' ? 'REPDEF' : 'REPEAT';
     } else {
         if (filter_input(INPUT_POST, 'origVtx')) {
             $payment = new ModelPayment();
             $result = $payment->getByVendorTxCode(filter_input(INPUT_POST, 'origVtx'));
             $txType = SAGEPAY_TXN_REPEAT;
             if (filter_input(INPUT_POST, 'deferred') == 'true') {
                 $txType = SAGEPAY_TXN_REPEATDEFERRED;
             }
             $data = array('VPSProtocol' => $this->sagepayConfig->getProtocolVersion(), 'TxType' => $txType, 'Vendor' => $this->sagepayConfig->getVendorName(), 'VendorTxCode' => filter_input(INPUT_POST, 'VendorTxCode'), 'Amount' => filter_input(INPUT_POST, 'Amount'), 'Currency' => $this->sagepayConfig->getCurrency(), 'Description' => filter_input(INPUT_POST, 'Description'), 'RelatedVPSTxId' => $result['vpsTxId'], 'RelatedVendorTxCode' => $result['vendorTxCode'], 'RelatedSecurityKey' => $result['securityKey'], 'RelatedTxAuthNo' => $result['txAuthNo'], 'DeliverySurname' => $result['deliverySurname'], 'DeliveryFirstnames' => $result['deliveryFirstnames'], 'DeliveryAddress1' => $result['deliveryAddress1'], 'DeliveryAddress2' => $result['deliveryAddress2'], 'DeliveryCity' => $result['deliveryCity'], 'DeliveryPostCode' => $result['deliveryPostCode'], 'DeliveryCountry' => $result['deliveryCountry'], 'DeliveryState' => $result['deliveryState'], 'DeliveryPhone' => $result['deliveryPhone']);
             if (!empty($result['basketXml'])) {
                 $data['BasketXML'] = $result['basketXml'];
             } else {
                 $data['Basket'] = $result['basket'];
             }
             $surchargeConfigs = $this->sagepayConfig->getSurcharges();
             if (!empty($surchargeConfigs)) {
                 $surcharge = new SagepaySurcharge();
                 $surcharge->setSurcharges($surchargeConfigs);
                 $data['SurchargeXML'] = $surcharge->export();
             }
             if (filter_input(INPUT_POST, 'cv2')) {
                 $data['CV2'] = filter_input(INPUT_POST, 'cv2');
             }
             $errors = $this->validate($this->_rules, $data);
             $helperMessage = new HelperMessage();
             $message = $helperMessage->getAllMessages($errors);
             // Check if repeat was failed
             if (!$errors) {
                 $response = SagepayCommon::requestPost($this->sagepayConfig->getSharedUrl('repeat'), $data);
                 if ($response['Status'] == SAGEPAY_REMOTE_STATUS_OK) {
                     $response['StatusDetail'] = 'REPEAT transaction taken through Order Admin area';
                     if (filter_input(INPUT_POST, 'deferred') != 'true') {
                         $response['CapturedAmount'] = $data['Amount'];
                     }
                 }
                 $result = $this->ucFirstFields($result);
                 $repeatedTx = array_merge($result, $data, $response);
                 if ($txType == SAGEPAY_TXN_REPEATDEFERRED) {
                     unset($repeatedTx['CapturedAmount']);
                 }
                 $payment->insert($repeatedTx);
                 $query = array('requestBody' => SagepayUtil::arrayToQueryString($data), 'resultBody' => SagepayUtil::arrayToQueryString($response), 'status' => $response['Status'], 'command' => $txType);
                 $this->redirect($this->integrationType, 'admin_result', $query);
             }
             $this->error = true;
         }
     }
     // render repeat page
     if (!empty($result)) {
         $view = new HelperView('admin/repeat');
         $view->setData(array('env' => $this->sagepayConfig->getEnv(), 'vendorName' => $this->sagepayConfig->getVendorName(), 'integrationType' => $this->integrationType, 'result' => $result, 'newVtx' => SagepayCommon::vendorTxCode(time(), $txType, $this->sagepayConfig->getVendorName()), 'val' => array('ok' => !$this->error, 'errorStatusString' => $message), 'deferred' => $deferred));
         $view->render();
     } else {
         $this->redirect($this->integrationType, 'admin');
     }
 }
Exemplo n.º 2
0
 /**
  * Encrypt the order details ready to send to SagePay Server.
  *
  * @param SagepayAbstractApi $request   The request instance.
  * @throws SagepayApiException
  *
  * @return array|string  Returns a String for Form integration method or an array for Server / Direct.
  */
 public static function encryptedOrder(SagepayAbstractApi $request)
 {
     $settings = $request->getConfig();
     $basket = $request->getBasket();
     $address = $request->getAddressList();
     $integrationMethod = $request->getIntegrationMethod();
     $paneValues = $request->getPaneValues();
     // Determine the transaction type based on the payment gateway settings.
     $txType = $settings->getTxType();
     $billingAddress = $address[0];
     $deliveryAddress = isset($address[1]) ? $address[1] : null;
     $query = array('VPSProtocol' => $settings->getProtocolVersion(), 'Vendor' => $settings->getVendorName(), 'VendorTxCode' => self::vendorTxCode($basket->getId(), $txType, $settings->getVendorName()), 'Amount' => number_format($basket->getAmount(), 2, '.', ''), 'Currency' => $settings->getCurrency(), 'Description' => $basket->getDescription(), 'CustomerName' => $billingAddress->firstname . ' ' . $billingAddress->lastname, 'CustomerEMail' => $billingAddress->email, 'VendorEMail' => $settings->getVendorEmail(), 'SendEMail' => $settings->getSendEmail(), 'eMailMessage' => $settings->getEmailMessage(), 'BillingSurname' => $billingAddress->lastname, 'BillingFirstnames' => $billingAddress->firstname, 'BillingAddress1' => $billingAddress->address1, 'BillingAddress2' => $billingAddress->address2, 'BillingCity' => $billingAddress->city, 'BillingPostCode' => $billingAddress->getPostCode(), 'BillingCountry' => $billingAddress->country, 'BillingPhone' => $billingAddress->phone, 'ApplyAVSCV2' => $settings->getApplyAvsCv2(), 'Apply3DSecure' => $settings->getApply3dSecure(), 'AllowGiftAid' => $settings->getAllowGiftAid(), 'BillingAgreement' => $settings->getBillingAgreement());
     $query += $request->getData();
     $customer = $request->getCustomer();
     if ($customer instanceof SagepayCustomer) {
         $query += self::_setAuxValue($query, 'CustomerXML', $customer->export());
     }
     $query += self::_setAuxValue($query, 'VendorData', $settings->getVendorData());
     $query += self::_setAuxValue($query, 'ReferrerID', $settings->getPartnerId());
     $query += self::_setAuxValue($query, 'Language', $settings->getLanguage());
     // Add check for state for US addresses only.
     if ($billingAddress->country == 'US') {
         $query['BillingState'] = $billingAddress->state;
     }
     //Override with supplied delivery address if we have one .
     $query += self::_populateDeliveryDetails($billingAddress, $deliveryAddress);
     if (isset($paneValues['cardType']) && empty($paneValues['cardType'])) {
         $integrationMethod = SAGEPAY_TOKEN;
     }
     // Check if we need to encode cart.
     if (!$settings->basketAsXmlDisabled()) {
         $query['BasketXML'] = $basket->exportAsXml();
     } else {
         $query['Basket'] = $basket->exportAsXml(false);
     }
     if (count($settings->getSurcharges()) > 0) {
         $surcharges = new SagepaySurcharge();
         $surcharges->setSurcharges($settings->getSurcharges());
         $query['SurchargeXML'] = $surcharges->export();
     }
     switch ($integrationMethod) {
         case SAGEPAY_FORM:
             // Unset unused values
             unset($query['VPSProtocol']);
             unset($query['Vendor']);
             unset($query['TxType']);
             $env = $settings->getEnv();
             $query['SuccessURL'] = $settings->getFullFormSuccessUrl();
             $query['FailureURL'] = $settings->getFullFormFailureUrl();
             $request->setData($query);
             $queryStr = SagepayUtil::arrayToQueryString($query);
             $formValues = array();
             $formValues['Vendor'] = $settings->getVendorName();
             $formValues['VPSProtocol'] = $settings->getProtocolVersion();
             $formValues['TxType'] = $txType;
             $formValues['Crypt'] = SagepayUtil::encryptAes($queryStr, $settings->getFormEncryptionPassword($env));
             // Encrypt order details using base64 and the secret key from the settings.
             return $formValues;
         case SAGEPAY_SERVER:
             $query['NotificationURL'] = $settings->getFullServerNotificationUrl();
             $query['TxType'] = $txType;
             $query['Profile'] = $settings->getServerProfile();
             $query['StoreToken'] = 1;
             $query += self::_setAuxValue($query, 'AccountType', $settings->getAccountType());
             return $query;
         case SAGEPAY_DIRECT:
             $query = array_merge($query, self::_getCardDetails($paneValues));
             $query['TxType'] = $txType;
             $query['CardHolder'] = $billingAddress->firstname . ' ' . $billingAddress->lastname;
             // Add 3D Secure flag only if the 3d Secure module is enabled for DIRECT.
             $query['Apply3DSecure'] = $settings->getApply3dSecure();
             $query += self::_setAuxValue($query, 'AccountType', $settings->getAccountType());
             return $query;
         case SAGEPAY_PAYPAL:
             $query['TxType'] = $txType;
             $query['CardType'] = 'PAYPAL';
             $query['PayPalCallbackURL'] = $settings->getPaypalCallbackUrl() . '?vtx=' . $query['VendorTxCode'];
             return $query;
         case SAGEPAY_TOKEN:
             $query['TxType'] = $txType;
             $query['Token'] = $paneValues['token'];
             $query['CV2'] = $paneValues['cv2'];
             $query['AllowGiftAid'] = $paneValues['giftAid'] ? 1 : 0;
             $query += self::_setAuxValue($query, 'AccountType', $settings->getAccountType());
             $query['StoreToken'] = 1;
             $query['ApplyAVSCV2'] = 2;
             return $query;
         default:
             throw new SagepayApiException('Invalid integration type');
     }
 }