Skip to content

Commit

Permalink
Correctly set payment information when using paypal
Browse files Browse the repository at this point in the history
  • Loading branch information
therool committed Nov 22, 2017
1 parent 9fc1138 commit ba0472f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 37 deletions.
7 changes: 6 additions & 1 deletion app/code/Magento/Paypal/Model/Express.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,14 +669,19 @@ public function getApi()
public function assignData(\Magento\Framework\DataObject $data)
{
parent::assignData($data);

$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);

if (!is_array($additionalData)) {
return $this;
}

foreach ($additionalData as $key => $value) {
// Skip extension attributes
if ($key === \Magento\Framework\Api\ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY) {
continue;
}

$this->getInfoInstance()->setAdditionalInformation($key, $value);
}
return $this;
Expand Down
11 changes: 10 additions & 1 deletion app/code/Magento/Paypal/Test/Unit/Model/ExpressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,21 @@ public function testAssignData()
{
$transportValue = 'something';

$extensionAttributeMock = $this->getMockForAbstractClass(
\Magento\Quote\Api\Data\PaymentExtensionInterface::class,
[],
'',
false,
false
);

$data = new DataObject(
[
PaymentInterface::KEY_ADDITIONAL_DATA => [
Express\Checkout::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT => $transportValue,
Express\Checkout::PAYMENT_INFO_TRANSPORT_PAYER_ID => $transportValue,
Express\Checkout::PAYMENT_INFO_TRANSPORT_TOKEN => $transportValue
Express\Checkout::PAYMENT_INFO_TRANSPORT_TOKEN => $transportValue,
\Magento\Framework\Api\ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY => $extensionAttributeMock
]
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,12 @@ define([
'mage/storage',
'Magento_Checkout/js/model/error-processor',
'Magento_Customer/js/model/customer',
'Magento_Checkout/js/model/full-screen-loader'
], function ($, quote, urlBuilder, storage, errorProcessor, customer, fullScreenLoader) {
'Magento_Checkout/js/model/full-screen-loader',
'Magento_Checkout/js/action/set-payment-information'
], function ($, quote, urlBuilder, storage, errorProcessor, customer, fullScreenLoader, setPaymentInformation) {
'use strict';

return function (messageContainer) {
var serviceUrl,
payload,
paymentData = quote.paymentMethod();

/**
* Checkout for guest and registered customer.
*/
if (!customer.isLoggedIn()) {
serviceUrl = urlBuilder.createUrl('/guest-carts/:cartId/set-payment-information', {
cartId: quote.getQuoteId()
});
payload = {
cartId: quote.getQuoteId(),
email: quote.guestEmail,
paymentMethod: paymentData
};
} else {
serviceUrl = urlBuilder.createUrl('/carts/mine/set-payment-information', {});
payload = {
cartId: quote.getQuoteId(),
paymentMethod: paymentData
};
}
fullScreenLoader.startLoader();

return storage.post(
serviceUrl, JSON.stringify(payload)
).fail(function (response) {
errorProcessor.process(response, messageContainer);
}).always(function () {
fullScreenLoader.stopLoader();
});
return setPaymentInformation(messageContainer, quote.paymentMethod());
};
});
});

0 comments on commit ba0472f

Please sign in to comment.