Beispiel #1
0
 /**
  * Prepare shopping cart data
  *
  * @param \XLite\Model\Order            $cart           X-Cart shopping cart
  * @param \XLite\Model\Payment\Method   $paymentMethod  Payment method
  * @param integer                       $refId          Transaction ID OPTIONAL
  * @param boolean                       $forceAuth      Force enable AUTH mode OPTIONAL
  *
  * @return array
  */
 public function prepareCart(\XLite\Model\Order $cart, \XLite\Model\Payment\Method $paymentMethod, $refId = null, $forceAuth = false)
 {
     $config = \XLite\Core\Config::getInstance()->CDev->XPaymentsConnector;
     $profile = $cart->getProfile();
     if ($cart->getOrderNumber()) {
         $description = 'Order #' . $cart->getOrderNumber();
     } elseif ($cart->getFirstOpenPaymentTransaction() && $cart->getFirstOpenPaymentTransaction()->getPublicId()) {
         $description = 'Payment transaction: ' . $cart->getFirstOpenPaymentTransaction()->getPublicId();
     } else {
         $description = '';
     }
     $result = array('login' => $profile->getLogin() . ' (User ID #' . $profile->getProfileId() . ')', 'items' => array(), 'currency' => $this->getCurrencyCode($paymentMethod), 'shippingCost' => 0.0, 'taxCost' => 0.0, 'discount' => 0.0, 'totalCost' => 0.0, 'description' => $description, 'merchantEmail' => \XLite\Core\Config::getInstance()->Company->orders_department, 'forceTransactionType' => $forceAuth ? 'A' : '');
     // Send customer unique Id for Kount UNIQ field (API v1.6 and higher)
     if (version_compare($config->xpc_api_version, '1.6') >= 0) {
         $result['kountCustomerUniq'] = $this->getKountCustomerUniq($cart);
     }
     $result['billingAddress'] = $this->prepareAddress($profile);
     if ($profile->getShippingAddress()) {
         $result['shippingAddress'] = $this->prepareAddress($profile, 'shipping');
     } else {
         $result['shippingAddress'] = $result['billingAddress'];
     }
     // Set items
     if ($cart->getItems()) {
         foreach ($cart->getItems() as $item) {
             $itemElement = array('sku' => strval($item->getSku() ? $item->getSku() : $item->getName()), 'name' => strval($item->getName() ? $item->getName() : $item->getSku()), 'price' => $this->roundCurrency($item->getPrice()), 'quantity' => $item->getAmount());
             if (!$itemElement['sku']) {
                 $itemElement['sku'] = 'N/A';
             }
             if (!$itemElement['name']) {
                 $itemElement['name'] = 'N/A';
             }
             $result['items'][] = $itemElement;
         }
     }
     // Set costs
     $result['shippingCost'] = $this->roundCurrency($cart->getSurchargesSubtotal(\XLite\Model\Base\Surcharge::TYPE_SHIPPING, false));
     $result['taxCost'] = $this->roundCurrency($cart->getSurchargesSubtotal(\XLite\Model\Base\Surcharge::TYPE_TAX, false));
     $result['totalCost'] = $this->roundCurrency($cart->getTotal());
     $result['discount'] = $this->roundCurrency(abs($cart->getSurchargesSubtotal(\XLite\Model\Base\Surcharge::TYPE_DISCOUNT, false)));
     return $result;
 }
 /**
  * {@inheritDoc}
  */
 public function getFirstOpenPaymentTransaction()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getFirstOpenPaymentTransaction', array());
     return parent::getFirstOpenPaymentTransaction();
 }