Beispiel #1
0
 /**
  * Get shipping cost for set express checkout
  *
  * @param \XLite\Model\Order $order Order
  *
  * @return float
  */
 protected function getShippingCost($order)
 {
     $result = null;
     $shippingModifier = $order->getModifier(\XLite\Model\Base\Surcharge::TYPE_SHIPPING, 'SHIPPING');
     if ($shippingModifier && $shippingModifier->canApply()) {
         /** @var \XLite\Model\Currency $currency */
         $currency = $order->getCurrency();
         $result = $currency->roundValue($order->getSurchargeSumByType(\XLite\Model\Base\Surcharge::TYPE_SHIPPING));
     }
     return $result;
 }
Beispiel #2
0
 /**
  * Check - payment processor is applicable for specified order or not
  *
  * @param \XLite\Model\Order          $order  Order
  * @param \XLite\Model\Payment\Method $method Payment method
  *
  * @return boolean
  */
 public function isApplicable(\XLite\Model\Order $order, \XLite\Model\Payment\Method $method)
 {
     $currencies = $this->getAllowedCurrencies($method);
     return !$currencies || in_array($order->getCurrency()->getCode(), $currencies);
 }
Beispiel #3
0
 /**
  * Convert order to array for CreateSecureToken
  *
  * @param \XLite\Model\Order $order Order
  *
  * @return array
  * @see    https://www.paypalobjects.com/webstatic/en_US/developer/docs/pdf/pfp_expresscheckout_pp.pdf
  */
 public function convertCreateSecureTokenParams($order)
 {
     /** @var \XLite\Model\Currency $currency */
     $currency = $order->getCurrency();
     $orderTotal = $currency->roundValue($order->getTotal());
     $shippingCost = $this->getShippingCost($order);
     /** @var \XLite\Module\CDev\Paypal\Model\Payment\Processor\ExpressCheckoutMerchantAPI $processor */
     $processor = $this->getProcessor();
     /** @var \XLite\Model\Profile $profile */
     $profile = $order->getProfile();
     /** @var \XLite\Model\Address $billingAddress */
     $billingAddress = $profile->getBillingAddress();
     $postData = array('CREATESECURETOKEN' => 'Y', 'SECURETOKENID' => $this->getSecureTokenId(), 'TRXTYPE' => $this->getPaymentAction(), 'AMT' => $orderTotal, 'BILLTOFIRSTNAME' => $billingAddress->getFirstname(), 'BILLTOLASTNAME' => $billingAddress->getLastname(), 'BILLTOSTREET' => $billingAddress->getStreet(), 'BILLTOCITY' => $billingAddress->getCity(), 'BILLTOSTATE' => $billingAddress->getState()->getCode() ?: $billingAddress->getState()->getState(), 'BILLTOZIP' => $billingAddress->getZipcode(), 'BILLTOCOUNTRY' => strtoupper($billingAddress->getCountry()->getCode()), 'ERRORURL' => $processor->getPaymentReturnUrl(), 'RETURNURL' => $processor->getPaymentReturnUrl(), 'CANCELURL' => $processor->getPaymentCancelUrl(), 'NOTIFYURL' => $processor->getPaymentCallbackUrl(), 'RETURNURLMETHOD' => 'POST', 'URLMETHOD' => 'POST', 'TEMPLATE' => 'MINLAYOUT', 'BILLTOPHONENUM' => $billingAddress->getPhone(), 'BILLTOEMAIL' => $profile->getLogin(), 'ADDROVERRIDE' => '1', 'NOSHIPPING' => null === $shippingCost ? '1' : '0', 'FREIGHTAMT' => (double) $shippingCost, 'HANDLINGAMT' => 0, 'INSURANCEAMT' => 0, 'SILENTPOST' => 'TRUE', 'SILENTPOSTURL' => $processor->getPaymentCallbackUrl(), 'FORCESILENTPOST' => 'FALSE', 'DISABLERECEIPT' => 'TRUE', 'CURRENCY' => $currency->getCode());
     if (null !== $shippingCost) {
         /** @var \XLite\Model\Address $shippingAddress */
         $shippingAddress = $profile->getShippingAddress();
         $postData += array('SHIPTOPHONENUM' => $shippingAddress->getPhone(), 'SHIPTOFIRSTNAME' => $shippingAddress->getFirstname(), 'SHIPTOLASTNAME' => $shippingAddress->getLastname(), 'SHIPTOSTREET' => $shippingAddress->getStreet(), 'SHIPTOCITY' => $shippingAddress->getCity(), 'SHIPTOSTATE' => $shippingAddress->getState()->getCode() ?: $shippingAddress->getState()->getState(), 'SHIPTOZIP' => $shippingAddress->getZipcode(), 'SHIPTOCOUNTRY' => $shippingAddress->getCountry()->getCode(), 'SHIPTOEMAIL' => $profile->getLogin());
     }
     $items = $this->getItems($order);
     // To avoid total mismatch clear tax and shipping cost
     $taxAmt = isset($items['TAXAMT']) ? $items['TAXAMT'] : 0;
     if (abs($orderTotal - $items['ITEMAMT'] - $taxAmt - $shippingCost) > 1.0E-10) {
         $items['ITEMAMT'] = $orderTotal;
         $items['TAXAMT'] = 0;
         $postData['FREIGHTAMT'] = 0;
     }
     if (static::REQUEST_LENGTH_LIMIT > strlen($this->convertParams($postData) . $this->convertParams($items))) {
         $postData += $items;
     }
     return $postData;
 }
Beispiel #4
0
 /**
  * Convert order to array for SetExpressCheckout
  *
  * @param \XLite\Model\Order $order Order
  *
  * @return array
  * @see    https://developer.paypal.com/docs/classic/api/merchant/SetExpressCheckout_API_Operation_NVP/
  */
 public function convertSetExpressCheckoutParams($order)
 {
     /** @var \XLite\Model\Currency $currency */
     $currency = $order->getCurrency();
     $orderTotal = $currency->roundValue($order->getTotal());
     $shippingCost = $this->getShippingCost($order);
     /** @var \XLite\Module\CDev\Paypal\Model\Payment\Processor\ExpressCheckoutMerchantAPI $processor */
     $processor = $this->getProcessor();
     $params = array('RETURNURL' => $processor->getPaymentReturnUrl(), 'CANCELURL' => $processor->getPaymentCancelUrl(), 'NOSHIPPING' => null === $shippingCost ? '1' : '0', 'ALLOWNOTE' => 1, 'PAYMENTREQUEST_0_AMT' => $orderTotal, 'PAYMENTREQUEST_0_PAYMENTACTION' => $this->getPaymentAction(), 'PAYMENTREQUEST_0_CURRENCYCODE' => $currency->getCode(), 'PAYMENTREQUEST_0_HANDLINGAMT' => 0, 'PAYMENTREQUEST_0_INSURANCEAMT' => 0, 'PAYMENTREQUEST_0_SHIPPINGAMT' => (double) $shippingCost);
     if (\XLite\Core\Config::getInstance()->Security->customer_security) {
         $postData['HDRIMG'] = urlencode(\XLite\Module\CDev\Paypal\Main::getLogo());
     }
     $items = $this->getItems($order);
     // To avoid total mismatch clear tax and shipping cost
     $taxAmt = isset($items['PAYMENTREQUEST_0_TAXAMT']) ? $items['PAYMENTREQUEST_0_TAXAMT'] : 0;
     if (abs($orderTotal - $items['PAYMENTREQUEST_0_ITEMAMT'] - $taxAmt - $shippingCost) <= 1.0E-10) {
         $params += $items;
     } else {
         $itemsAmt = $orderTotal - (double) $shippingCost;
         $params['PAYMENTREQUEST_0_ITEMAMT'] = $itemsAmt;
     }
     $type = \XLite\Core\Session::getInstance()->ec_type;
     /** @var \XLite\Model\Profile $profile */
     $profile = $order->getProfile();
     if (\XLite\Module\CDev\Paypal\Model\Payment\Processor\ExpressCheckout::EC_TYPE_SHORTCUT == $type) {
         $params['REQCONFIRMSHIPPING'] = 0;
     }
     if ($profile && $profile->getLogin()) {
         $params += array('EMAIL' => $profile->getLogin());
     }
     if ($profile && $profile->getBillingAddress()) {
         $params += array('PHONENUM' => $profile->getBillingAddress()->getPhone());
     }
     if (null !== $shippingCost && $profile && $profile->getShippingAddress()) {
         /** @var \XLite\Model\Address $address */
         $address = $profile->getShippingAddress();
         $params += array('ADDROVERRIDE' => 1, 'PAYMENTREQUEST_0_SHIPTONAME' => trim($address->getFirstname() . ' ' . $address->getLastname()), 'PAYMENTREQUEST_0_SHIPTOSTREET' => $address->getStreet(), 'PAYMENTREQUEST_0_SHIPTOSTREET2' => '', 'PAYMENTREQUEST_0_SHIPTOCITY' => $address->getCity(), 'PAYMENTREQUEST_0_SHIPTOSTATE' => $address->getState()->getCode() ?: $address->getState()->getState(), 'PAYMENTREQUEST_0_SHIPTOZIP' => $address->getZipcode(), 'PAYMENTREQUEST_0_SHIPTOCOUNTRY' => $address->getCountry()->getCode());
     }
     if (\XLite\Core\Auth::getInstance()->isLogged()) {
         $profile = \XLite\Core\Auth::getInstance()->getProfile();
         if ($profile->isSocialProfile() && 'PayPal' == $profile->getSocialLoginProvider() && \XLite\Core\Session::getInstance()->paypalAccessToken) {
             $accessToken = \XLite\Core\Session::getInstance()->paypalAccessToken;
             if (LC_START_TIME < $accessToken['expirationTime']) {
                 $params['IDENTITYACCESSTOKEN'] = $accessToken['access_token'];
             }
         }
     }
     return $params;
 }
 /**
  * {@inheritDoc}
  */
 public function getCurrency()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCurrency', array());
     return parent::getCurrency();
 }