Example #1
0
    /**
     * Populate data that is read from configurations
     */
    protected function addConfiguredValues()
    {
        $data = array(
            'Vendor' => $this->config->getVendorName(),
            'VPSProtocol' => $this->config->getProtocolVersion(),
            'Currency' => $this->config->getCurrency(),
            'TxType' => $this->config->getTxType(),
            'SendEMail' => $this->config->getSendEmail(),
            'VendorEMail' => $this->config->getVendorEmail(),
            'Apply3DSecure' => $this->config->getApply3dSecure(),
            'ApplyAVSCV2' => $this->config->getApplyAvsCv2(),
        );

        $partnerId = $this->config->getPartnerId();
        if (!empty($partnerId))
        {
            $data['ReferrerID'] = $partnerId;
        }
        if ($data['SendEMail'] == 1)
        {
            $data['eMailMessage'] = $this->config->getEmailMessage();
        }
        $allowGiftAid = $this->config->getAllowGiftAid();
        if (!isset($this->data['AllowGiftAid']))
        {
            $data['AllowGiftAid'] = $allowGiftAid;
        }

        $this->updateData($data);
    }
Example #2
0
 /**
  * Build Api for transaction
  *
  * @return SagepayAbstractApi
  */
 protected function buildApi()
 {
     $details = HelperCommon::getStore('details');
     if (HelperCommon::getStore('isDeliverySame')) {
         // set default delivery
         $fields = array('Firstnames', 'Surname', 'Address1', 'Address2', 'City', 'PostCode', 'Country', 'State', 'Phone');
         $details = $this->setDefaultDelivery($details, $fields);
         HelperCommon::setStore('details', $details);
     }
     $basket = $this->getBasketFromProducts();
     $basket->setDeliveryNetAmount(1.5);
     $basket->setDeliveryTaxAmount(0.05);
     $basket->setDescription('DVDs from Sagepay Demo Page');
     $extra = HelperCommon::getStore('extra');
     $api = SagepayApiFactory::create($this->integrationType, $this->sagepayConfig);
     if (is_null($api)) {
         $this->redirect('index');
     }
     // Save extra information to API
     if (is_array($extra)) {
         foreach ($extra as $key => $value) {
             $call = 'set' . ucfirst($key);
             if (method_exists($basket, $call)) {
                 $basket->{$call}($value);
             } else {
                 if (!empty($value)) {
                     // Save Recipient Details
                     $api->updateData(array(ucfirst($key) => $value));
                 }
             }
         }
     }
     $api->setBasket($basket);
     // Add billing and delivery details
     $address1 = $this->createCustomerDetails($details, 'billing');
     $address2 = $this->createCustomerDetails($details, 'delivery');
     $api->addAddress($address1);
     $api->addAddress($address2);
     $account = HelperCommon::getStore('account');
     if ($account) {
         $customer = new SagepayCustomer();
         $customer->setCustomerId($account['id']);
         $api->setCustomer($customer);
     }
     $this->addData('api', $api);
     $this->addData('env', $this->sagepayConfig->getEnv());
     $this->addData('deliveryGrossPrice', number_format($api->getBasket()->getDeliveryGrossAmount(), 2) . ' ' . $this->sagepayConfig->getCurrency());
     $this->addData('totalGrossPrice', number_format($api->getBasket()->getAmount(), 2) . ' ' . $this->sagepayConfig->getCurrency());
     $details['BillingAddress2'] = $details['BillingAddress2'] ? $details['BillingAddress2'] . '<br>' : '';
     $details['BillingState'] = $details['BillingState'] ? $details['BillingState'] . '<br>' : '';
     $details['BillingPostCode'] = $details['BillingPostCode'] ? $details['BillingPostCode'] . '<br>' : '';
     $details['DeliveryAddress2'] = $details['DeliveryAddress2'] ? $details['DeliveryAddress2'] . '<br>' : '';
     $details['DeliveryState'] = $details['DeliveryState'] ? $details['DeliveryState'] . '<br>' : '';
     $details['DeliveryPostCode'] = $details['DeliveryPostCode'] ? $details['DeliveryPostCode'] . '<br>' : '';
     $this->addData('details', $details);
     return $api;
 }
Example #3
0
 /**
  * Prepare data for register request
  * 
  * @param array $cardDetails
  * @return array
  */
 private function _prepareRegisterData(array $cardDetails) 
 {
     return array(
         'VPSProtocol' => $this->_config->getProtocolVersion(),
         'TxType' => self::TOKEN,
         'Vendor' => $this->_config->getVendorName(),
         'Currency' => $this->_config->getCurrency(),
         'CardHolder' => isset($cardDetails['cardHolder']) ? $cardDetails['cardHolder'] : NULL,
         'CardNumber' => isset($cardDetails['cardNumber']) ? $cardDetails['cardNumber'] : NULL,
         'ExpiryDate' => isset($cardDetails['expiryDate']) ? $cardDetails['expiryDate'] : NULL,
         'CV2' => isset($cardDetails['cv2']) ? $cardDetails['cv2'] : NULL,
         'CardType' => isset($cardDetails['cardType']) ? $cardDetails['cardType'] : NULL,
     );
 }