示例#1
0
 /**
  * Update quote when returned from PayPal
  * rewrite billing address by paypal
  * save old billing address for new customer
  * export shipping address in case address absence
  *
  * @param string $token
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function returnFromPaypal($token)
 {
     $this->_getApi();
     $this->_api->setToken($token)->callGetExpressCheckoutDetails();
     $quote = $this->_quote;
     $this->ignoreAddressValidation();
     // import shipping address
     $exportedShippingAddress = $this->_api->getExportedShippingAddress();
     if (!$quote->getIsVirtual()) {
         $shippingAddress = $quote->getShippingAddress();
         if ($shippingAddress) {
             if ($exportedShippingAddress && $quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1) {
                 $this->_setExportedAddressData($shippingAddress, $exportedShippingAddress);
                 // PayPal doesn't provide detailed shipping info: prefix, middlename, lastname, suffix
                 $shippingAddress->setPrefix(null);
                 $shippingAddress->setMiddlename(null);
                 $shippingAddress->setLastname(null);
                 $shippingAddress->setSuffix(null);
                 $shippingAddress->setCollectShippingRates(true);
                 $shippingAddress->setSameAsBilling(0);
             }
             // import shipping method
             $code = '';
             if ($this->_api->getShippingRateCode()) {
                 $code = $this->_matchShippingMethodCode($shippingAddress, $this->_api->getShippingRateCode());
                 if ($code) {
                     // possible bug of double collecting rates :-/
                     $shippingAddress->setShippingMethod($code)->setCollectShippingRates(true);
                 }
             }
             $quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD, $code);
         }
     }
     // import billing address
     $portBillingFromShipping = $quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1 && $this->_config->getValue('requireBillingAddress') != \Magento\Paypal\Model\Config::REQUIRE_BILLING_ADDRESS_ALL && !$quote->isVirtual();
     if ($portBillingFromShipping) {
         $billingAddress = clone $shippingAddress;
         $billingAddress->unsAddressId()->unsAddressType()->setCustomerAddressId(null);
         $data = $billingAddress->getData();
         $data['save_in_address_book'] = 0;
         $quote->getBillingAddress()->addData($data);
         $quote->getShippingAddress()->setSameAsBilling(1);
     } else {
         $billingAddress = $quote->getBillingAddress();
     }
     $exportedBillingAddress = $this->_api->getExportedBillingAddress();
     $this->_setExportedAddressData($billingAddress, $exportedBillingAddress);
     $billingAddress->setCustomerNote($exportedBillingAddress->getData('note'));
     $quote->setBillingAddress($billingAddress);
     // import payment info
     $payment = $quote->getPayment();
     $payment->setMethod($this->_methodType);
     $this->_paypalInfo->importToPayment($this->_api, $payment);
     $payment->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID, $this->_api->getPayerId())->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_TOKEN, $token);
     $quote->collectTotals();
     $this->quoteRepository->save($quote);
 }
示例#2
0
 public function testCallGetExpressCheckoutDetails()
 {
     $this->curl->expects($this->once())->method('read')->will($this->returnValue("\r\n" . 'ACK=Success&SHIPTONAME=Ship%20To%20Name'));
     $this->model->callGetExpressCheckoutDetails();
     $this->assertEquals('Ship To Name', $this->model->getExportedShippingAddress()->getData('firstname'));
 }