Example #1
0
 /**
  * Return commno data for *all* transactions.
  * @return array Data
  */
 public function _getGeneralTrnData(Varien_Object $payment, $adminParams = array())
 {
     $order = $payment->getOrder();
     $quoteObj = $this->_getQuote();
     $vendorTxCode = $this->_getTrnVendorTxCode();
     if ($payment->getCcNumber()) {
         $vendorTxCode .= $this->_cleanString(substr($payment->getCcOwner(), 0, 10));
     }
     $payment->setVendorTxCode($vendorTxCode);
     $request = new Varien_Object();
     $request->setVPSProtocol((string) $this->getVpsProtocolVersion($this->getConfigData('mode')))->setReferrerID($this->getConfigData('referrer_id'))->setVendor($this->getConfigData('vendor'))->setVendorTxCode($vendorTxCode);
     $request->setClientIPAddress($this->getClientIp());
     if ($payment->getIntegra()) {
         //Server
         if (is_array($adminParams) && !empty($adminParams)) {
             $confParam = isset($adminParams['order']['send_confirmation']) ? '&e=' . (int) $adminParams['order']['send_confirmation'] : '';
             if (isset($adminParams['order']['account']['email'])) {
                 $confParam .= '&l=' . urlencode($adminParams['order']['account']['email']);
             }
             if (isset($adminParams['order']['account']['group_id'])) {
                 $confParam .= '&g=' . $adminParams['order']['account']['group_id'];
             }
         } else {
             $confParam = '';
         }
         $this->getSageSuiteSession()->setLastVendorTxCode($vendorTxCode);
         $request->setIntegration($payment->getIntegra());
         $request->setData('notification_URL', $this->getNotificationUrl() . '&vtxc=' . $vendorTxCode . $confParam);
         $request->setData('success_URL', $this->getSuccessUrl());
         $request->setData('redirect_URL', $this->getRedirectUrl());
         $request->setData('failure_URL', $this->getFailureUrl());
     }
     if ($this->_getIsAdminOrder()) {
         $request->setAccountType('M');
     }
     if ($payment->getAmountOrdered()) {
         $this->_setRequestCurrencyAmount($request, $quoteObj);
     }
     if (!empty($order)) {
         $billing = $order->getBillingAddress();
         if (!empty($billing)) {
             $request->setBillingAddress($billing->getStreet(1) . ' ' . $billing->getCity() . ' ' . $billing->getRegion() . ' ' . $billing->getCountry())->setBillingSurname($this->ss($billing->getLastname(), 20))->setBillingFirstnames($this->ss($billing->getFirstname(), 20))->setBillingPostCode($this->sanitizePostcode($this->ss($billing->getPostcode(), 10)))->setBillingAddress1($this->ss($billing->getStreet(1), 100))->setBillingAddress2($this->ss($billing->getStreet(2), 100))->setBillingCity($this->ss($billing->getCity(), 40))->setBillingCountry($billing->getCountry())->setContactNumber(substr($this->_cphone($billing->getTelephone()), 0, 20));
             if ($billing->getCountry() == 'US') {
                 $request->setBillingState($billing->getRegionCode());
             }
             $request->setCustomerEMail($billing->getEmail());
         }
         if (!$request->getDescription()) {
             $request->setDescription('.');
         }
         $shipping = $order->getShippingAddress();
         if (!$quoteObj->isVirtual()) {
             $request->setDeliveryAddress($shipping->getStreet(1) . ' ' . $shipping->getCity() . ' ' . $shipping->getRegion() . ' ' . $shipping->getCountry())->setDeliverySurname($this->ss($shipping->getLastname(), 20))->setDeliveryFirstnames($this->ss($shipping->getFirstname(), 20))->setDeliveryPostCode($this->sanitizePostcode($this->ss($shipping->getPostcode(), 10)))->setDeliveryAddress1($this->ss($shipping->getStreet(1), 100))->setDeliveryAddress2($this->ss($shipping->getStreet(2), 100))->setDeliveryCity($this->ss($shipping->getCity(), 40))->setDeliveryCountry($shipping->getCountry())->setDeliveryPhone($this->ss(urlencode($this->_cphone($shipping->getTelephone())), 20));
             if ($shipping->getCountry() == 'US') {
                 $request->setDeliveryState($shipping->getRegionCode());
             }
         } else {
             #If the cart only has virtual products, I need to put an shipping address to Sage Pay.
             #Then the billing address will be the shipping address to
             $request->setDeliveryAddress($billing->getStreet(1) . ' ' . $billing->getCity() . ' ' . $billing->getRegion() . ' ' . $billing->getCountry())->setDeliverySurname($this->ss($billing->getLastname(), 20))->setDeliveryFirstnames($this->ss($billing->getFirstname(), 20))->setDeliveryPostCode($this->sanitizePostcode($this->ss($billing->getPostcode(), 10)))->setDeliveryAddress1($this->ss($billing->getStreet(1), 100))->setDeliveryAddress2($this->ss($billing->getStreet(2), 100))->setDeliveryCity($this->ss($billing->getCity(), 40))->setDeliveryCountry($billing->getCountry())->setDeliveryPhone($this->ss(urlencode($this->_cphone($billing->getTelephone())), 20));
             if ($billing->getCountry() == 'US') {
                 $request->setDeliveryState($billing->getRegionCode());
             }
         }
     }
     if ($payment->getCcNumber()) {
         $request->setCardNumber($payment->getCcNumber())->setExpiryDate(sprintf('%02d%02d', $payment->getCcExpMonth(), substr($payment->getCcExpYear(), strlen($payment->getCcExpYear()) - 2)))->setCardType($payment->getCcType())->setCV2($payment->getCcCid())->setCardHolder($payment->getCcOwner());
         if ($payment->getCcIssue()) {
             $request->setIssueNumber($payment->getCcIssue());
         }
         if ($payment->getCcStartMonth() && $payment->getCcStartYear()) {
             $request->setStartDate(sprintf('%02d%02d', $payment->getCcStartMonth(), substr($payment->getCcStartYear(), strlen($payment->getCcStartYear()) - 2)));
         }
     }
     $basket = Mage::helper('sagepaysuite')->getSagePayBasket($quoteObj, false);
     if (!empty($basket)) {
         if ($basket[0] == "<") {
             $request->setBasketXML($basket);
         } else {
             $request->setBasket($basket);
         }
     }
     if (!$request->getDeliveryPostCode()) {
         $request->setDeliveryPostCode('000');
     }
     if (!$request->getBillingPostCode()) {
         $request->setBillingPostCode('000');
     }
     return $request;
 }
Example #2
0
 /**
  * Return commno data for *all* transactions.
  * @return array Data
  */
 public function _getGeneralTrnData(Varien_Object $payment)
 {
     $order = $payment->getOrder();
     $quoteObj = $this->_getQuote();
     $vendorTxCode = $this->_getTrnVendorTxCode();
     if ($payment->getCcNumber()) {
         $vendorTxCode .= $this->_cleanString(substr($payment->getCcOwner(), 0, 10));
     }
     $payment->setVendorTxCode($vendorTxCode);
     $request = new Varien_Object();
     $request->setVPSProtocol('2.23')->setReferrerID($this->getConfigData('referrer_id'))->setVendor($this->getConfigData('vendor'))->setVendorTxCode($vendorTxCode);
     $request->setClientIPAddress($this->getClientIp());
     if ($payment->getIntegra()) {
         $this->getSageSuiteSession()->setLastVendorTxCode($vendorTxCode);
         $request->setIntegration($payment->getIntegra());
         $request->setData('notification_URL', $this->getNotificationUrl() . '&vtxc=' . $vendorTxCode);
         $request->setData('success_URL', $this->getSuccessUrl());
         $request->setData('redirect_URL', $this->getRedirectUrl());
         $request->setData('failure_URL', $this->getFailureUrl());
     }
     if ($this->_getIsAdminOrder()) {
         $request->setAccountType('M');
     }
     if ($payment->getAmountOrdered()) {
         $from = $order->getOrderCurrencyCode();
         if ((string) $this->getConfigData('trncurrency') == 'store') {
             $request->setAmount($this->formatAmount($quoteObj->getGrandTotal(), $quoteObj->getQuoteCurrencyCode()));
             $request->setCurrency($quoteObj->getQuoteCurrencyCode());
         } else {
             $request->setAmount($this->formatAmount($quoteObj->getBaseGrandTotal(), $quoteObj->getBaseCurrencyCode()));
             $request->setCurrency($quoteObj->getBaseCurrencyCode());
         }
     }
     if (!empty($order)) {
         $billing = $order->getBillingAddress();
         if (!empty($billing)) {
             $request->setBillingAddress($billing->getStreet(1) . ' ' . $billing->getCity() . ' ' . $billing->getRegion() . ' ' . $billing->getCountry())->setBillingSurname($this->ss($billing->getLastname(), 20))->setBillingFirstnames($this->ss($billing->getFirstname(), 20))->setBillingPostCode($this->ss($billing->getPostcode(), 10))->setBillingAddress1($this->ss($billing->getStreet(1), 100))->setBillingAddress2($this->ss($billing->getStreet(2), 100))->setBillingCity($this->ss($billing->getCity(), 40))->setBillingCountry($billing->getCountry())->setContactNumber(substr($this->_cphone($billing->getTelephone()), 0, 20));
             if ($billing->getCountry() == 'US') {
                 $request->setBillingState($billing->getRegionCode());
             }
             $request->setCustomerEMail($billing->getEmail());
         }
         if (!$request->getDescription()) {
             $request->setDescription('.');
         }
         $shipping = $order->getShippingAddress();
         if (!empty($shipping)) {
             $request->setDeliveryAddress($shipping->getStreet(1) . ' ' . $shipping->getCity() . ' ' . $shipping->getRegion() . ' ' . $shipping->getCountry())->setDeliverySurname($this->ss($shipping->getLastname(), 20))->setDeliveryFirstnames($this->ss($shipping->getFirstname(), 20))->setDeliveryPostCode($this->ss($shipping->getPostcode(), 10))->setDeliveryAddress1($this->ss($shipping->getStreet(1), 100))->setDeliveryAddress2($this->ss($shipping->getStreet(2), 100))->setDeliveryCity($this->ss($shipping->getCity(), 40))->setDeliveryCountry($shipping->getCountry())->setDeliveryPhone($this->ss(urlencode($this->_cphone($shipping->getTelephone())), 20));
             if ($shipping->getCountry() == 'US') {
                 $request->setDeliveryState($shipping->getRegionCode());
             }
         } else {
             #If the cart only has virtual products, I need to put an shipping address to Sage Pay.
             #Then the billing address will be the shipping address to
             $request->setDeliveryAddress($billing->getStreet(1) . ' ' . $billing->getCity() . ' ' . $billing->getRegion() . ' ' . $billing->getCountry())->setDeliverySurname($this->ss($billing->getLastname(), 20))->setDeliveryFirstnames($this->ss($billing->getFirstname(), 20))->setDeliveryPostCode($this->ss($billing->getPostcode(), 10))->setDeliveryAddress1($this->ss($billing->getStreet(1), 100))->setDeliveryAddress2($this->ss($billing->getStreet(2), 100))->setDeliveryCity($this->ss($billing->getCity(), 40))->setDeliveryCountry($billing->getCountry())->setDeliveryPhone($this->ss(urlencode($this->_cphone($billing->getTelephone())), 20));
             if ($billing->getCountry() == 'US') {
                 $request->setDeliveryState($billing->getRegionCode());
             }
         }
     }
     if ($payment->getCcNumber()) {
         $request->setCardNumber($payment->getCcNumber())->setExpiryDate(sprintf('%02d%02d', $payment->getCcExpMonth(), substr($payment->getCcExpYear(), strlen($payment->getCcExpYear()) - 2)))->setCardType($payment->getCcType())->setCV2($payment->getCcCid())->setCardHolder($payment->getCcOwner());
         if ($payment->getCcIssue()) {
             $request->setIssueNumber($payment->getCcIssue());
         }
         if ($payment->getCcStartMonth() && $payment->getCcStartYear()) {
             $request->setStartDate(sprintf('%02d%02d', $payment->getCcStartMonth(), substr($payment->getCcStartYear(), strlen($payment->getCcStartYear()) - 2)));
         }
     }
     $totals = $shipping->getTotals();
     $shippingTotal = isset($totals['shipping']) ? $totals['shipping']->getValue() : 0;
     if ($this->getSendBasket()) {
         $request->setBasket($this->_getBasketContents($quoteObj));
     }
     if (!$request->getDeliveryPostCode()) {
         $request->setDeliveryPostCode('000');
     }
     if (!$request->getBillingPostCode()) {
         $request->setBillingPostCode('000');
     }
     return $request;
 }