Esempio n. 1
0
 /**
  * Constructor for SagepayServerApi
  *
  * @param SagepaySettings $config
  */
 public function __construct(SagepaySettings $config)
 {
     parent::__construct($config);
     $this->_vpsServerUrl = $config->getPurchaseUrl('server');
     $this->mandatory = array(
         'VPSProtocol',
         'TxType',
         'Vendor',
         'VendorTxCode',
         'Amount',
         'Currency',
         'Description',
         'NotificationURL',
         'BillingSurname',
         'BillingFirstnames',
         'BillingAddress1',
         'BillingCity',
         'BillingPostCode',
         'BillingCountry',
         'DeliverySurname',
         'DeliveryFirstnames',
         'DeliveryAddress1',
         'DeliveryCity',
         'DeliveryPostCode',
         'DeliveryCountry',
         'StoreToken'
     );
 }
Esempio n. 2
0
 /**
  *
  * @param SagepaySettings $config
  */
 public function __construct(SagepaySettings $config)
 {
     parent::__construct($config);
     $this->mandatory = array(
         'VendorTxCode',
         'Amount',
         'Currency',
         'Description',
         'SuccessURL',
         'FailureURL',
         'BillingSurname',
         'BillingFirstnames',
         'BillingAddress1',
         'BillingCity',
         'BillingPostCode',
         'BillingCountry',
         'DeliverySurname',
         'DeliveryFirstnames',
         'DeliveryAddress1',
         'DeliveryCity',
         'DeliveryPostCode',
         'DeliveryCountry',
     );
 }
Esempio n. 3
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');
     }
 }