Skip to content

Commit

Permalink
Merge pull request #1140 from BearGroup/release/5.14.1
Browse files Browse the repository at this point in the history
Release/5.14.1
  • Loading branch information
Christian Zichichi authored Aug 24, 2022
2 parents d2070bf + 3392cbb commit 0e9aa6e
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 285 deletions.
9 changes: 1 addition & 8 deletions Api/CheckoutSessionManagementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,9 @@ interface CheckoutSessionManagementInterface
{
/**
* @param string|null $cartId
* @param boolean $omitPayloads
* @return mixed
*/
public function getConfig($cartId = null, $omitPayloads = false);

/**
* @param string $payloadType
* @return mixed
*/
public function getButtonPayload($payloadType = 'checkout');
public function getConfig($cartId = null);

/**
* @param mixed $amazonSessionId
Expand Down
4 changes: 3 additions & 1 deletion Block/Adminhtml/System/Config/AutoKeyExchangeAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public function getRegion()
public function getCurrency()
{
$currency = $this->autokeyexchange->getCurrency();
if($currency) $currency = strtoupper($currency);
if ($currency) {
$currency = strtoupper($currency);
}
return $currency;
}
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 5.14.1
* Changed how buttons are rendered for compatibility with estimated order amount feature
* Removed estimated order amount from PDP button

## 5.14.0
* Added configurable options for checkout and signin cancel return urls
* Added estimated order amount to the button payload
Expand Down
3 changes: 1 addition & 2 deletions Controller/Checkout/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public function __construct(
*/
public function execute()
{
$omitPayloads = filter_var($this->getRequest()->getParams()['omit_payloads'], FILTER_VALIDATE_BOOLEAN);
$data = $this->amazonCheckoutSession->getConfig($omitPayloads);
$data = $this->amazonCheckoutSession->getConfig();
return $this->resultJsonFactory->create()->setData($data);
}
}
4 changes: 2 additions & 2 deletions CustomerData/CheckoutSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public function __construct(
/**
* @return array
*/
public function getConfig($omitPayloads)
public function getConfig()
{
$data = $this->checkoutSessionManagement->getConfig(null, $omitPayloads);
$data = $this->checkoutSessionManagement->getConfig();
if (count($data) > 0) {
$data = $data[0];
}
Expand Down
87 changes: 14 additions & 73 deletions Model/CheckoutSessionManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,33 +413,39 @@ protected function convertToMagentoAddress(array $address, $isShippingAddress =
/**
* {@inheritdoc}
*/
public function getConfig($cartId = null, $omitPayloads = true)
public function getConfig($cartId = null)
{
$result = [];
$quote = $this->session->getQuoteFromIdOrSession($cartId);

if ($this->canCheckoutWithAmazon($quote)) {
$loginButtonPayload = $this->amazonAdapter->generateLoginButtonPayload();
$checkoutButtonPayload = $this->amazonAdapter->generateCheckoutButtonPayload();
$config = [
'merchant_id' => $this->amazonConfig->getMerchantId(),
'currency' => $this->amazonConfig->getCurrencyCode(),
'button_color' => $this->amazonConfig->getButtonColor(),
'language' => $this->amazonConfig->getLanguage(),
'sandbox' => $this->amazonConfig->isSandboxEnabled(),
'login_payload' => $loginButtonPayload,
'login_signature' => $this->amazonAdapter->signButton($loginButtonPayload),
'checkout_payload' => $checkoutButtonPayload,
'checkout_signature' => $this->amazonAdapter->signButton($checkoutButtonPayload),
'public_key_id' => $this->amazonConfig->getPublicKeyId(),
];

if (!$omitPayloads) {
$config = array_merge($config, $this->getLoginButtonPayload(), $this->getCheckoutButtonPayload());
}

if ($quote) {
// Ensure the totals are up to date, in case the checkout does something to update qty or shipping
// without collecting totals
$quote->collectTotals();
$config['pay_only'] = $this->amazonHelper->isPayOnly($quote);

if (!$omitPayloads) {
$config = array_merge($config, $this->getPayNowButtonPayload($quote));
}
$payNowButtonPayload = $this->amazonAdapter->generatePayNowButtonPayload(
$quote,
$this->amazonConfig->getPaymentAction()
);
$config['paynow_payload'] = $payNowButtonPayload;
$config['paynow_signature'] = $this->amazonAdapter->signButton($payNowButtonPayload);
}

$result[] = $config;
Expand All @@ -448,71 +454,6 @@ public function getConfig($cartId = null, $omitPayloads = true)
return $result;
}

public function getButtonPayload($payloadType = 'checkout')
{
switch ($payloadType) {
case 'paynow':
$quote = $this->session->getQuoteFromIdOrSession();
return $this->getPayNowButtonPayload($quote);
case 'login':
return $this->getLoginButtonPayload();
default:
return $this->getCheckoutButtonPayload();
}
}

/**
* Generate login button payload/signature pair.
*
* @return mixed
*/
private function getLoginButtonPayload()
{
$loginButtonPayload = $this->amazonAdapter->generateLoginButtonPayload();
$result = [
'login_payload' => $loginButtonPayload,
'login_signature' => $this->amazonAdapter->signButton($loginButtonPayload)
];

return $result;
}

/**
* Generate checkout button payload/signature pair.
*
* @return mixed
*/
private function getCheckoutButtonPayload()
{
$checkoutButtonPayload = $this->amazonAdapter->generateCheckoutButtonPayload();
$result = [
'checkout_payload' => $checkoutButtonPayload,
'checkout_signature' => $this->amazonAdapter->signButton($checkoutButtonPayload)
];

return $result;
}

/**
* Generate paynow payload/signature pair.
*
* @param CartInterface $quote
* @return mixed
*/
private function getPayNowButtonPayload($quote)
{
$payNowButtonPayload = $this->amazonAdapter->generatePayNowButtonPayload(
$quote,
$this->amazonConfig->getPaymentAction()
);
$result = [
'paynow_payload' => $payNowButtonPayload,
'paynow_signature' => $this->amazonAdapter->signButton($payNowButtonPayload)
];

return $result;
}

/**
* {@inheritdoc}
*/
Expand Down
40 changes: 0 additions & 40 deletions Plugin/CustomerData/Cart.php

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The following table provides an overview on which Git branch is compatible to wh
Magento Version | Github Branch | Latest release
---|---|---
2.2.6 - 2.2.11 (EOL) | [V2checkout-1.2.x](https://github.com/amzn/amazon-payments-magento-2-plugin/tree/V2checkout-1.2.x) | 1.20.0 (EOL)
2.3.0 - 2.4.x | [master](https://github.com/amzn/amazon-payments-magento-2-plugin/tree/master) | 5.14.0
2.3.0 - 2.4.x | [master](https://github.com/amzn/amazon-payments-magento-2-plugin/tree/master) | 5.14.1

## Release Notes
See [CHANGELOG.md](/CHANGELOG.md)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "amzn/amazon-pay-magento-2-module",
"description": "Official Magento2 Plugin to integrate with Amazon Pay",
"type": "magento2-module",
"version": "5.14.0",
"version": "5.14.1",
"license": [
"Apache-2.0"
],
Expand Down
3 changes: 0 additions & 3 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,4 @@
<type name="Magento\Sales\Model\Order">
<plugin name="amazon_payv2_legacy_order" type="Amazon\Pay\Plugin\LegacyPaymentHandler" />
</type>
<type name="Magento\Checkout\CustomerData\Cart">
<plugin name="amazon_pay_customerdata_cart" type="Amazon\Pay\Plugin\CustomerData\Cart" />
</type>
</config>
12 changes: 0 additions & 12 deletions etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,12 @@
<resources>
<resource ref="anonymous" />
</resources>
<data>
<parameter name="omitPayloads">%omit_payloads%</parameter>
</data>
</route>
<route url="/V1/amazon-checkout-session/config/:cartId" method="GET">
<service class="Amazon\Pay\Api\CheckoutSessionManagementInterface" method="getConfig"/>
<resources>
<resource ref="anonymous" />
</resources>
<data>
<parameter name="omitPayloads">%omit_payloads%</parameter>
</data>
</route>
<route method="GET" url="/V1/amazon-checkout-session/button-payload/:payloadType">
<service class="Amazon\Pay\Api\CheckoutSessionManagementInterface" method="getButtonPayload"/>
<resources>
<resource ref="anonymous" />
</resources>
</route>
<route url="/V1/amazon-checkout-session/:amazonSessionId/payment-descriptor" method="GET">
<service class="Amazon\Pay\Api\CheckoutSessionManagementInterface" method="getPaymentDescriptor"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $currency = $block->getCurrency();
</a>
</span>
</div>
<?php elseif($currency == 'JPY'): // JPY (JA) AKE not supported ?>
<?php elseif ($currency == 'JPY'): // JPY (JA) AKE not supported ?>
<div></div>
<?php else: ?>
<div id="autokeyexchange-hint">
Expand Down

This file was deleted.

40 changes: 21 additions & 19 deletions view/frontend/web/js/action/checkout-session-config-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

define([
define([
'jquery',
'underscore',
'mage/storage',
Expand All @@ -22,31 +22,33 @@ define([
], function ($, _, remoteStorage, url, customerData) {
'use strict';

const storageKey = 'amzn-checkout-session-config';
$('.switcher-option').on('click', function () {
$.localStorage.remove(storageKey);
});

var callbacks = [];
var localStorage = null;
var getLocalStorage = function () {
if (localStorage === null) {
localStorage = $.initNamespaceStorage(storageKey).localStorage;
localStorage = $.initNamespaceStorage('amzn-checkout-session-config').localStorage;
}
return localStorage;
};
return function (callback, omitPayloads = true) {
};
return function (callback, forceReload = false) {
var cartId = customerData.get('cart')()['data_id'] || window.checkout.storeId;
var config = getLocalStorage().get('config') || false;
if (!config) {
remoteStorage.get(url.build(`amazon_pay/checkout/config?omit_payloads=${omitPayloads}`)).done(function (config) {
getLocalStorage().set('cart_id', cartId);
getLocalStorage().set('config', config);

callback(getLocalStorage().get('config'));
});
}
else {
if (forceReload
|| cartId !== getLocalStorage().get('cart_id')
|| typeof config.checkout_payload === 'undefined'
|| !config.checkout_payload.includes(document.URL.slice(0, -1))) {
callbacks.push(callback);
if (callbacks.length == 1) {
remoteStorage.get(url.build('amazon_pay/checkout/config')).done(function (config) {
getLocalStorage().set('cart_id', cartId);
getLocalStorage().set('config', config);
do {
callbacks.shift()(config);
} while (callbacks.length);
});
}
} else {
callback(getLocalStorage().get('config'));
}
};
};
});
Loading

0 comments on commit 0e9aa6e

Please sign in to comment.