/** * 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 */ 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) { $this->_setExportedAddressData($shippingAddress, $exportedShippingAddress); if ($quote->getPayment()->getAdditionalInformation(self::PAYMENT_INFO_BUTTON) == 1) { // 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()) { if ($code = $this->_matchShippingMethodCode($shippingAddress, $this->_api->getShippingRateCode())) { // 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->requireBillingAddress != Mage_Paypal_Model_Config::REQUIRE_BILLING_ADDRESS_ALL && !$quote->isVirtual(); if ($portBillingFromShipping) { $billingAddress = clone $shippingAddress; $billingAddress->unsAddressId()->unsAddressType(); $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->setCustomerNotes($exportedBillingAddress->getData('note')); $quote->setBillingAddress($billingAddress); // import payment info $payment = $quote->getPayment(); $payment->setMethod($this->_methodType); Mage::getSingleton('paypal/info')->importToPayment($this->_api, $payment); $payment->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID, $this->_api->getPayerId())->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_TOKEN, $token); $quote->collectTotals()->save(); }
/** * 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 */ public function returnFromPaypal($token) { $this->_getApi(); $this->_api->setToken($token)->callGetExpressCheckoutDetails(); $quote = $this->_quote; // import billing address $billingAddress = $quote->getBillingAddress(); $exportedBillingAddress = $this->_api->getExportedBillingAddress(); $quote->setCustomerEmail($billingAddress->getEmail()); $quote->setCustomerPrefix($billingAddress->getPrefix()); $quote->setCustomerFirstname($billingAddress->getFirstname()); $quote->setCustomerMiddlename($billingAddress->getMiddlename()); $quote->setCustomerLastname($billingAddress->getLastname()); $quote->setCustomerSuffix($billingAddress->getSuffix()); $quote->setCustomerNote($exportedBillingAddress->getData('note')); foreach ($exportedBillingAddress->getExportedKeys() as $key) { if (!$billingAddress->getDataUsingMethod($key)) { $billingAddress->setDataUsingMethod($key, $exportedBillingAddress->getData($key)); } } // import shipping address $exportedShippingAddress = $this->_api->getExportedShippingAddress(); if (!$quote->getIsVirtual()) { $shippingAddress = $quote->getShippingAddress(); if ($shippingAddress) { if ($exportedShippingAddress) { foreach ($exportedShippingAddress->getExportedKeys() as $key) { $shippingAddress->setDataUsingMethod($key, $exportedShippingAddress->getData($key)); } $shippingAddress->setCollectShippingRates(true); $shippingAddress->setSameAsBilling(0); } // import shipping method $code = ''; if ($this->_api->getShippingRateCode()) { if ($code = $this->_matchShippingMethodCode($shippingAddress, $this->_api->getShippingRateCode())) { // possible bug of double collecting rates :-/ $shippingAddress->setShippingMethod($code)->setCollectShippingRates(true); } } $quote->getPayment()->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_SHIPPING_METHOD, $code); } } $this->_ignoreAddressValidation(); // import payment info $payment = $quote->getPayment(); $payment->setMethod($this->_methodType); Mage::getSingleton('paypal/info')->importToPayment($this->_api, $payment); $payment->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID, $this->_api->getPayerId())->setAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_TOKEN, $token); $quote->collectTotals()->save(); }