Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/5.14.2 #1177

Merged
merged 16 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Block/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public function getConfig()
return $config;
}

/**
* @return string
*/
public function getJsonConfig()
{
return json_encode($this->getConfig());
}

/**
* @return bool
*/
Expand Down
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.2
* Removed usage of Zend libraries and updated requirements for PHP 8.2/Magento 2.4.6 compatibility
* Fixed issue where coupon usage is not properly decremented when placing order fails

## 5.14.1
* Changed how buttons are rendered for compatibility with estimated order amount feature
* Removed estimated order amount from PDP button
Expand Down
4 changes: 2 additions & 2 deletions Helper/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace Amazon\Pay\Helper;

use Amazon\Pay\Api\Data\AmazonCustomerInterface;
use Zend_Validate;
use Magento\Framework\Validator\ValidatorChain;

class Customer
{
Expand Down Expand Up @@ -79,7 +79,7 @@ public function getAmazonCustomer($buyerInfo)

public function createCustomer(AmazonCustomerInterface $amazonCustomer)
{
if (! Zend_Validate::is($amazonCustomer->getEmail(), 'EmailAddress')) {
if (! ValidatorChain::is($amazonCustomer->getEmail(), '\Magento\Framework\Validator\EmailAddress')) {
throw new ValidatorException(__('the email address for your Amazon account is invalid'));
}

Expand Down
14 changes: 13 additions & 1 deletion Model/CheckoutSessionManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use Magento\Integration\Model\Oauth\TokenFactory as TokenModelFactory;
use Magento\Authorization\Model\UserContextInterface as UserContext;
use Magento\Framework\Phrase\Renderer\Translate as Translate;
use Magento\SalesRule\Model\Coupon\UpdateCouponUsages;

class CheckoutSessionManagement implements \Amazon\Pay\Api\CheckoutSessionManagementInterface
{
Expand Down Expand Up @@ -208,6 +209,11 @@ class CheckoutSessionManagement implements \Amazon\Pay\Api\CheckoutSessionManage
*/
private $translationRenderer;

/**
* @var UpdateCouponUsages
*/
private $updateCouponUsages;

/**
* CheckoutSessionManagement constructor.
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
Expand Down Expand Up @@ -240,6 +246,7 @@ class CheckoutSessionManagement implements \Amazon\Pay\Api\CheckoutSessionManage
* @param \Amazon\Pay\Logger\Logger $logger
* @param Session $session
* @param Translate $translationRenderer
* @param UpdateCouponUsages $updateCouponUsages
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
Expand Down Expand Up @@ -271,7 +278,8 @@ public function __construct(
UserContext $userContext,
\Amazon\Pay\Logger\Logger $logger,
Session $session,
Translate $translationRenderer
Translate $translationRenderer,
UpdateCouponUsages $updateCouponUsages,
) {
$this->storeManager = $storeManager;
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
Expand Down Expand Up @@ -303,6 +311,7 @@ public function __construct(
$this->logger = $logger;
$this->session = $session;
$this->translationRenderer = $translationRenderer;
$this->updateCouponUsages = $updateCouponUsages;
}

/**
Expand Down Expand Up @@ -634,6 +643,9 @@ private function cancelOrder($order)
$invoice->setState(Invoice::STATE_CANCELED);
}

// decrement coupon usages if applicable
$this->updateCouponUsages->execute($order, false);

// delete order comments and add new one
foreach ($order->getStatusHistories() as $history) {
$history->delete();
Expand Down
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.1
2.3.0 - 2.4.x | [master](https://github.com/amzn/amazon-payments-magento-2-plugin/tree/master) | 5.14.2

## Release Notes
See [CHANGELOG.md](/CHANGELOG.md)
42 changes: 38 additions & 4 deletions Test/Mftf-23/ActionGroup/AmazonBeginLoginOnlyActionGroup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,43 @@
<wait time="1" stepKey="allowButtonToActivate1"/>
<fillField selector="{{AmazonPageSection.emailField}}" userInput="{{AmazonAccount.email}}" stepKey="fillAmazonPageEmailField"/>
<fillField selector="{{AmazonPageSection.passwordField}}" userInput="{{AmazonAccount.password}}" stepKey="fillAmazonPagePasswordField"/>
<click selector="{{AmazonPageSection.signInButton}}" stepKey="clickAmazonPageSignInButton"/>
<!--Verify successful login by the presence of the continue button-->
<wait time="1" stepKey="allowButtonToActivate2"/>
<waitForElement selector="{{AmazonLoginSection.consentButton}}" stepKey="seeAmazonConsentButton"/>

<executeInSelenium function="function (\Facebook\WebDriver\Remote\RemoteWebDriver $remoteWebDriver) use ($I, $openerName) {
try {
$remoteWebDriver->findElement(
\Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonPageSection.signInButton}}')
)->click();
$remoteWebDriver->switchTo()->window($openerName);
$I->wait(5);
} catch (\Exception $ex) {
$I->comment('exception caught');
} catch (\Error $err) {
$I->comment('error caught');
}
}" stepKey="handlePopupSecondScreen"/>

<executeInSelenium function="function (\Facebook\WebDriver\Remote\RemoteWebDriver $remoteWebDriver) use ($I, $openerName) {
try {
if (count($remoteWebDriver->getWindowHandles()) > 1) {
$I->comment('Popup remained open, switching back to it');
$I->switchToNextTab();

$loginCancel = $remoteWebDriver->findElements(\Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonPageSection.loginCancelButton}}'));

if (!empty($loginCancel)) {
$I->comment('Cancel login with Amazon and land back on sign-in Magento page');
$loginCancel[0]->click();
$remoteWebDriver->switchTo()->window($openerName);
}
} else {
$I->comment('Popup closed, signing out manually and returning to login page');
$I->amOnPage('customer/account/logout/');
$I->wait(5);
$I->amOnPage('/customer/account/login/');
}
} catch (\Exception $ex) {

}
}" stepKey="handleCancelSignIn"/>
</actionGroup>
</actionGroups>
76 changes: 58 additions & 18 deletions Test/Mftf-23/ActionGroup/AmazonLoginActionGroup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,69 @@
<wait time="1" stepKey="allowButtonToActivate1"/>
<fillField selector="{{AmazonPageSection.emailField}}" userInput="{{AmazonAccount.email}}" stepKey="fillAmazonPageEmailField"/>
<fillField selector="{{AmazonPageSection.passwordField}}" userInput="{{AmazonAccount.password}}" stepKey="fillAmazonPagePasswordField"/>
<click selector="{{AmazonPageSection.signInButton}}" stepKey="clickAmazonPageSignInButton"/>
<!--Verify successful login by the presence of the checkout button-->
<wait time="1" stepKey="allowButtonToActivate"/>

<executeInSelenium function="function (\Facebook\WebDriver\Remote\RemoteWebDriver $remoteWebDriver) use ($I, $openerName) {
try {
$remoteWebDriver->findElement(
\Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonPageSection.signInButton}}')
)->click();
$remoteWebDriver->switchTo()->window($openerName);
$I->wait(5);
} catch (\Exception $ex) {
$I->comment('exception caught');
} catch (\Error $err) {
$I->comment('error caught');
}
}" stepKey="handlePopupSecondScreen"/>

<executeInSelenium function="function (\Facebook\WebDriver\Remote\RemoteWebDriver $remoteWebDriver) use ($I, $openerName) {
$continueAs = $remoteWebDriver->findElements(\Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonPageSection.continueButton}}'));
try {
if (count($remoteWebDriver->getWindowHandles()) > 1) {
if ($I->executeJS('return window.name;') === $openerName) {
$I->comment('Popup remained open, switching back to it');
$I->switchToNextTab();
}

$continueAs = $remoteWebDriver->findElements(\Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonPageSection.continueButton}}'));

if (!empty($continueAs)) {
$I->comment('Click Continue as... button and return to checkout');
$continueAs[0]->click();
$remoteWebDriver->switchTo()->window($openerName);
$I->waitForPageLoad(30);
if (!empty($continueAs)) {
$I->comment('Click Continue as... button and return to checkout');
$continueAs[0]->click();
$remoteWebDriver->switchTo()->window($openerName);
$I->waitForPageLoad(30);

$I->comment('Wait for Edit button in address details');
$editAddressSelector = \Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonCheckoutSection.editShippingButton}}');
$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::elementToBeClickable($editAddressSelector));
$I->comment('Click Edit button to return to normal flow');
$remoteWebDriver->findElement($editAddressSelector)->click();

$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::numberOfWindowsToBe(2));
$I->switchToNextTab();
$addressIdSelector = \Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonPageSection.addressId}}');
$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::presenceOfElementLocated($addressIdSelector));
} else {
$I->comment('No continue button, standard maxo/pay now');
$addressIdSelector = \Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonPageSection.addressId}}');
$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::presenceOfElementLocated($addressIdSelector));
}
} else {
$I->comment('Popup closed, allowing checkout page to load');
$I->comment('Wait for Edit button in address details');
$editAddressSelector = \Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonCheckoutSection.editShippingButton}}');
$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::elementToBeClickable($editAddressSelector));
$I->comment('Click Edit button to return to normal flow');
$remoteWebDriver->findElement($editAddressSelector)->click();

$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::numberOfWindowsToBe(2));
$I->switchToNextTab();
$addressIdSelector = \Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonPageSection.addressId}}');
$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::presenceOfElementLocated($addressIdSelector));
}
} catch (\Exception $ex) {

$I->comment('Wait for Edit button in address details');
$editAddressSelector = \Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonCheckoutSection.editShippingButton}}');
$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::elementToBeClickable($editAddressSelector));
$I->comment('Click Edit button to return to normal flow');
$remoteWebDriver->findElement($editAddressSelector)->click();

$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::numberOfWindowsToBe(2));
$I->switchToNextTab();
}
}" stepKey="secureSignInWorkaround" />
}" stepKey="navigateToAddressAndPaymentOptions" />

<waitForElement selector="{{AmazonPageSection.checkoutButton}}" stepKey="seeAmazonCheckoutButton"/>
</actionGroup>
Expand Down
78 changes: 59 additions & 19 deletions Test/Mftf-23/ActionGroup/AmazonLoginAndCheckoutActionGroup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,73 @@
<waitForElement selector="{{AmazonPageSection.emailField}}" time="30" stepKey="apWaitForLogin"/>
<fillField selector="{{AmazonPageSection.emailField}}" userInput="{{AmazonAccount.email}}" stepKey="apEnterEmail"/>
<fillField selector="{{AmazonPageSection.passwordField}}" userInput="{{AmazonAccount.password}}" stepKey="apEnterPassword"/>
<click selector="{{AmazonPageSection.signInButton}}" stepKey="clickSigninButton"/>

<!--Verify successful login by the presence of the checkout button-->
<wait time="1" stepKey="allowButtonToActivate2"/>

<executeInSelenium function="function (\Facebook\WebDriver\Remote\RemoteWebDriver $remoteWebDriver) use ($I, $openerName) {
$continueAs = $remoteWebDriver->findElements(\Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonPageSection.continueButton}}'));

if (!empty($continueAs)) {
$I->comment('Click Continue as... button and return to checkout');
$continueAs[0]->click();
try {
$remoteWebDriver->findElement(
\Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonPageSection.signInButton}}')
)->click();
$remoteWebDriver->switchTo()->window($openerName);
$I->waitForPageLoad(30);
$I->wait(5);
} catch (\Exception $ex) {
$I->comment('exception caught');
} catch (\Error $err) {
$I->comment('error caught');
}
}" stepKey="handlePopupSecondScreen"/>

<executeInSelenium function="function (\Facebook\WebDriver\Remote\RemoteWebDriver $remoteWebDriver) use ($I, $openerName) {
try {
if (count($remoteWebDriver->getWindowHandles()) > 1) {
if ($I->executeJS('return window.name;') === $openerName) {
$I->comment('Popup remained open, switching back to it');
$I->switchToNextTab();
}

$continueAs = $remoteWebDriver->findElements(\Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonPageSection.continueButton}}'));

if (!empty($continueAs)) {
$I->comment('Click Continue as... button and return to checkout');
$continueAs[0]->click();
$remoteWebDriver->switchTo()->window($openerName);
$I->waitForPageLoad(30);

$I->comment('Wait for Edit button in address details');
$editAddressSelector = \Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonCheckoutSection.editShippingButton}}');
$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::elementToBeClickable($editAddressSelector));
$I->comment('Click Edit button to return to normal flow');
$remoteWebDriver->findElement($editAddressSelector)->click();

$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::numberOfWindowsToBe(2));
$I->switchToNextTab();
$addressIdSelector = \Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonPageSection.addressId}}');
$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::presenceOfElementLocated($addressIdSelector));
} else {
$I->comment('No continue button, standard maxo/pay now');
$addressIdSelector = \Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonPageSection.addressId}}');
$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::presenceOfElementLocated($addressIdSelector));
}
} else {
$I->comment('Popup closed, allowing checkout page to load');
$I->comment('Wait for Edit button in address details');
$editAddressSelector = \Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonCheckoutSection.editShippingButton}}');
$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::elementToBeClickable($editAddressSelector));
$I->comment('Click Edit button to return to normal flow');
$remoteWebDriver->findElement($editAddressSelector)->click();

$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::numberOfWindowsToBe(2));
$I->switchToNextTab();
$addressIdSelector = \Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonPageSection.addressId}}');
$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::presenceOfElementLocated($addressIdSelector));
}
} catch (\Exception $ex) {

$I->comment('Wait for Edit button in address details');
$editAddressSelector = \Facebook\WebDriver\WebDriverBy::cssSelector('{{AmazonCheckoutSection.editShippingButton}}');
$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::elementToBeClickable($editAddressSelector));
$I->comment('Click Edit button to return to normal flow');
$remoteWebDriver->findElement($editAddressSelector)->click();

$remoteWebDriver->wait(30, 100)->until(\Facebook\WebDriver\WebDriverExpectedCondition::numberOfWindowsToBe(2));
$I->switchToNextTab();
}
}" stepKey="secureSignInWorkaround" />
}" stepKey="navigateToAddressAndPaymentOptions" />

<!-- Load address list in DOM -->
<waitForElementVisible selector="{{AmazonPageSection.changeAddressButton}}" stepKey="waitForChangeAddressButton"/>
<wait time="2" stepKey="waitForChangeAddressClickable"/>
<click selector="{{AmazonPageSection.changeAddressButton}}" stepKey="clickChangeAddress"/>
<waitForElementVisible selector="{{AmazonPageSection.addressBackButton}}" stepKey="waitForAddressBackButton"/>
<click selector="{{AmazonPageSection.addressBackButton}}" stepKey="clickAddressBackButton"/>
Expand Down
Loading