diff --git a/Block/Config.php b/Block/Config.php index 534393e68..f031ae50d 100755 --- a/Block/Config.php +++ b/Block/Config.php @@ -69,6 +69,14 @@ public function getConfig() return $config; } + /** + * @return string + */ + public function getJsonConfig() + { + return json_encode($this->getConfig()); + } + /** * @return bool */ diff --git a/CHANGELOG.md b/CHANGELOG.md index e69905d24..a649567b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Helper/Customer.php b/Helper/Customer.php index f567dc928..a42ebe31d 100644 --- a/Helper/Customer.php +++ b/Helper/Customer.php @@ -18,7 +18,7 @@ namespace Amazon\Pay\Helper; use Amazon\Pay\Api\Data\AmazonCustomerInterface; -use Zend_Validate; +use Magento\Framework\Validator\ValidatorChain; class Customer { @@ -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')); } diff --git a/Model/CheckoutSessionManagement.php b/Model/CheckoutSessionManagement.php index 4ca891e0d..a059ed1af 100755 --- a/Model/CheckoutSessionManagement.php +++ b/Model/CheckoutSessionManagement.php @@ -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 { @@ -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 @@ -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, @@ -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; @@ -303,6 +311,7 @@ public function __construct( $this->logger = $logger; $this->session = $session; $this->translationRenderer = $translationRenderer; + $this->updateCouponUsages = $updateCouponUsages; } /** @@ -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(); diff --git a/README.md b/README.md index 672a2590f..5988f75f6 100755 --- a/README.md +++ b/README.md @@ -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) diff --git a/Test/Mftf-23/ActionGroup/AmazonBeginLoginOnlyActionGroup.xml b/Test/Mftf-23/ActionGroup/AmazonBeginLoginOnlyActionGroup.xml index 5e6129b5a..df51bf8e7 100644 --- a/Test/Mftf-23/ActionGroup/AmazonBeginLoginOnlyActionGroup.xml +++ b/Test/Mftf-23/ActionGroup/AmazonBeginLoginOnlyActionGroup.xml @@ -5,9 +5,43 @@ - - - - + + + + diff --git a/Test/Mftf-23/ActionGroup/AmazonLoginActionGroup.xml b/Test/Mftf-23/ActionGroup/AmazonLoginActionGroup.xml index 8bb17e0be..530da756d 100644 --- a/Test/Mftf-23/ActionGroup/AmazonLoginActionGroup.xml +++ b/Test/Mftf-23/ActionGroup/AmazonLoginActionGroup.xml @@ -5,29 +5,69 @@ - - - + + + }" stepKey="navigateToAddressAndPaymentOptions" /> diff --git a/Test/Mftf-23/ActionGroup/AmazonLoginAndCheckoutActionGroup.xml b/Test/Mftf-23/ActionGroup/AmazonLoginAndCheckoutActionGroup.xml index 95349f785..48c0919f8 100644 --- a/Test/Mftf-23/ActionGroup/AmazonLoginAndCheckoutActionGroup.xml +++ b/Test/Mftf-23/ActionGroup/AmazonLoginAndCheckoutActionGroup.xml @@ -22,33 +22,73 @@ - - - - + + + }" stepKey="navigateToAddressAndPaymentOptions" /> + diff --git a/Test/Mftf-23/ActionGroup/AmazonLoginOnlyActionGroup.xml b/Test/Mftf-23/ActionGroup/AmazonLoginOnlyActionGroup.xml index 006dca33b..b9aa176cf 100644 --- a/Test/Mftf-23/ActionGroup/AmazonLoginOnlyActionGroup.xml +++ b/Test/Mftf-23/ActionGroup/AmazonLoginOnlyActionGroup.xml @@ -14,13 +14,44 @@ + - - - - - + + + + diff --git a/Test/Mftf-23/ActionGroup/AmazonLoginOnlyRedirectActionGroup.xml b/Test/Mftf-23/ActionGroup/AmazonLoginOnlyRedirectActionGroup.xml index 172c6829a..cef9aeef8 100644 --- a/Test/Mftf-23/ActionGroup/AmazonLoginOnlyRedirectActionGroup.xml +++ b/Test/Mftf-23/ActionGroup/AmazonLoginOnlyRedirectActionGroup.xml @@ -5,9 +5,41 @@ - - - - + + + + + diff --git a/Test/Mftf-23/Section/AmazonPageSection.xml b/Test/Mftf-23/Section/AmazonPageSection.xml index bef5a519a..6a6f4e111 100644 --- a/Test/Mftf-23/Section/AmazonPageSection.xml +++ b/Test/Mftf-23/Section/AmazonPageSection.xml @@ -5,9 +5,9 @@ - + - + diff --git a/Test/Mftf-23/Test/AmazonCancelReturnUrl.xml b/Test/Mftf-23/Test/AmazonCancelReturnUrl.xml index 0a2b8a1ac..f3bc78234 100644 --- a/Test/Mftf-23/Test/AmazonCancelReturnUrl.xml +++ b/Test/Mftf-23/Test/AmazonCancelReturnUrl.xml @@ -38,12 +38,6 @@ - - - - - - @@ -56,31 +50,104 @@ - - + + + + + }" stepKey="handlePopupSecondScreen2" /> diff --git a/Test/Mftf-23/Test/AmazonSignInToExistingTest.xml b/Test/Mftf-23/Test/AmazonSignInToExistingTest.xml index 2fac5737c..e76e1a89e 100644 --- a/Test/Mftf-23/Test/AmazonSignInToExistingTest.xml +++ b/Test/Mftf-23/Test/AmazonSignInToExistingTest.xml @@ -43,9 +43,6 @@ - - - diff --git a/Test/Mftf-24/ActionGroup/AmazonBeginLoginOnlyActionGroup.xml b/Test/Mftf-24/ActionGroup/AmazonBeginLoginOnlyActionGroup.xml index 5e6129b5a..36a5dcfb1 100644 --- a/Test/Mftf-24/ActionGroup/AmazonBeginLoginOnlyActionGroup.xml +++ b/Test/Mftf-24/ActionGroup/AmazonBeginLoginOnlyActionGroup.xml @@ -1,13 +1,20 @@ + - - - - + + + {{AmazonPageSection.signInButton}} + {$openerName} + + + + {{AmazonPageSection.loginCancelButton}} + {$openerName} + diff --git a/Test/Mftf-24/ActionGroup/AmazonCheckoutActionGroup.xml b/Test/Mftf-24/ActionGroup/AmazonCheckoutActionGroup.xml index c2dbc3498..67438a1b6 100644 --- a/Test/Mftf-24/ActionGroup/AmazonCheckoutActionGroup.xml +++ b/Test/Mftf-24/ActionGroup/AmazonCheckoutActionGroup.xml @@ -6,11 +6,14 @@ + {{AmazonPageSection.changeAddressButton}} {{AmazonPageSection.addressBackButton}} {{AmazonPageSection.addressId}} + {{openerName}} + {{AmazonCheckoutSection.editShippingButton}} diff --git a/Test/Mftf-24/ActionGroup/AmazonGoToPaymentMethodActionGroup.xml b/Test/Mftf-24/ActionGroup/AmazonGoToPaymentMethodActionGroup.xml new file mode 100644 index 000000000..c3e4f7580 --- /dev/null +++ b/Test/Mftf-24/ActionGroup/AmazonGoToPaymentMethodActionGroup.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/Test/Mftf-24/ActionGroup/AmazonLoginActionGroup.xml b/Test/Mftf-24/ActionGroup/AmazonLoginActionGroup.xml index 60961a623..0b5dc59b8 100644 --- a/Test/Mftf-24/ActionGroup/AmazonLoginActionGroup.xml +++ b/Test/Mftf-24/ActionGroup/AmazonLoginActionGroup.xml @@ -2,21 +2,26 @@ + + + + - - - - + + + {{AmazonPageSection.signInButton}} + - + {$openerName} - {{AmazonCheckoutSection.editShippingButton}} - {{AmazonPageSection.addressId}} - {{AmazonPageSection.changePaymentButton}} - {{AmazonPageSection.changeAddressButton}} + {{AmazonPageSection.continueButton}} + {{AmazonCheckoutSection.editShippingButton}} + {{AmazonPageSection.addressId}} + {{AmazonPageSection.checkoutButton}} + {{buttonSelector}} diff --git a/Test/Mftf-24/ActionGroup/AmazonLoginAndCheckoutActionGroup.xml b/Test/Mftf-24/ActionGroup/AmazonLoginAndCheckoutActionGroup.xml index 9759d48ba..4fadfcf13 100644 --- a/Test/Mftf-24/ActionGroup/AmazonLoginAndCheckoutActionGroup.xml +++ b/Test/Mftf-24/ActionGroup/AmazonLoginAndCheckoutActionGroup.xml @@ -9,33 +9,37 @@ + - + + {{buttonSelector}} + - - - - + + + {{AmazonPageSection.signInButton}} + - + {$openerName} - {{AmazonCheckoutSection.editShippingButton}} - {{AmazonPageSection.addressId}} - {{AmazonPageSection.changePaymentButton}} - {{AmazonPageSection.changeAddressButton}} + {{AmazonPageSection.continueButton}} + {{AmazonCheckoutSection.editShippingButton}} + {{AmazonPageSection.addressId}} + {{AmazonPageSection.checkoutButton}} + {{buttonSelector}} - + {{AmazonPageSection.changeAddressButton}} @@ -43,6 +47,11 @@ {{AmazonPageSection.addressId}} + + diff --git a/Test/Mftf-24/ActionGroup/AmazonLoginOnlyActionGroup.xml b/Test/Mftf-24/ActionGroup/AmazonLoginOnlyActionGroup.xml index 006dca33b..d5f54136f 100644 --- a/Test/Mftf-24/ActionGroup/AmazonLoginOnlyActionGroup.xml +++ b/Test/Mftf-24/ActionGroup/AmazonLoginOnlyActionGroup.xml @@ -16,12 +16,15 @@ - - - - - + + + {{AmazonPageSection.signInButton}} + + + {{AmazonLoginSection.consentButton}} + + diff --git a/Test/Mftf-24/ActionGroup/AmazonLoginOnlyRedirectActionGroup.xml b/Test/Mftf-24/ActionGroup/AmazonLoginOnlyRedirectActionGroup.xml index 172c6829a..ef4fd7d83 100644 --- a/Test/Mftf-24/ActionGroup/AmazonLoginOnlyRedirectActionGroup.xml +++ b/Test/Mftf-24/ActionGroup/AmazonLoginOnlyRedirectActionGroup.xml @@ -1,13 +1,13 @@ - + + + + + - - - - - - + + diff --git a/Test/Mftf-24/Helper/EnsurePopupOpened.php b/Test/Mftf-24/Helper/EnsurePopupOpened.php new file mode 100644 index 000000000..08d0170ad --- /dev/null +++ b/Test/Mftf-24/Helper/EnsurePopupOpened.php @@ -0,0 +1,45 @@ +getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver'); + $log = []; + + try { + $magentoWebDriver->executeInSelenium(function (RemoteWebDriver $remoteWebDriver) use ( + $magentoWebDriver, + $buttonSelector, + $log + ) { + try { + $remoteWebDriver->wait(15, 100)->until( + WebDriverExpectedCondition::numberOfWindowsToBe(2) + ); + } catch (TimeoutException $e) { + $log[] = 'Timed out waiting for second window:\n' . $e->getMessage(); + $log[] = 'Attempting to click button again'; + $magentoWebDriver->click($buttonSelector); + $magentoWebDriver->wait(1); + } catch (\Exception $e) { + $log[] = 'General exception thrown while waiting for second window:\n' . $e->getMessage(); + } + }); + } catch (\Exception $e) { + $log[] = 'General exception thrown while executing remote web driver code:\n' . $e->getMessage(); + // Avoid out of memory error sometimes caused by print_r + // print_r($e); + } finally { + var_dump($log); + } + } +} diff --git a/Test/Mftf-24/Helper/HandlePopupSecondScreen.php b/Test/Mftf-24/Helper/HandlePopupSecondScreen.php new file mode 100644 index 000000000..707a7fff9 --- /dev/null +++ b/Test/Mftf-24/Helper/HandlePopupSecondScreen.php @@ -0,0 +1,200 @@ +getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver'); + + $magentoWebDriver->executeInSelenium(function (RemoteWebDriver $remoteWebDriver) use ( + $magentoWebDriver, + $signInButton + ) { + try { + $remoteWebDriver->findElement( + WebDriverBy::cssSelector($signInButton) + )->click(); + $magentoWebDriver->switchToNextTab(); + $magentoWebDriver->wait(5); + } catch (\Exception $ex) { + + } catch (\Error $err) { + + } + }); + } + + public function navigateToAddressAndPaymentOptions( + $openerName, + $continueButton, + $editShippingButton, + $addressId, + $checkoutButton, + $apButton + ) { + /** @var MagentoWebDriver $magentoWebDriver */ + $magentoWebDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver'); + $stepLog = []; + + $magentoWebDriver->executeInSelenium(function (RemoteWebDriver $remoteWebDriver) use ( + $magentoWebDriver, + $stepLog, + $openerName, + $continueButton, + $editShippingButton, + $addressId, + $checkoutButton, + $apButton + ) { + try { + if (count($remoteWebDriver->getWindowHandles()) > 1) { + if ($magentoWebDriver->executeJS('return window.name;') === $openerName) { + $stepLog[] = 'Popup remained open, switching back to it'; + $magentoWebDriver->switchToNextTab(); + } + + $continueAs = $remoteWebDriver->findElements(WebDriverBy::cssSelector($continueButton)); + $checkout = $remoteWebDriver->findElements(WebDriverBy::cssSelector($checkoutButton)); + + if (empty($continueAs) && empty($checkout)) { + $stepLog[] = 'Popup didn\'t finish loading, closing popup and re-initiating Amazon Pay'; + + $stepLog[] = 'Closing tab'; + $magentoWebDriver->closeTab(); + $stepLog[] = 'Switching back to opener'; + $magentoWebDriver->switchToWindow($openerName); + $stepLog[] = 'Clicking Amazon button on checkout'; + $magentoWebDriver->click($apButton); + $stepLog[] = 'Waiting for popup to load and switching back to it'; + $magentoWebDriver->wait(3); + $magentoWebDriver->switchToNextTab(); + + $continueAs = $remoteWebDriver->findElements(WebDriverBy::cssSelector($continueButton)); + } + + if (!empty($continueAs)) { + $stepLog[] = 'Click Continue as... button and return to checkout'; + $continueAs[0]->click(); + $remoteWebDriver->switchTo()->window($openerName); + $magentoWebDriver->waitForPageLoad(30); + + $stepLog[] = 'Wait for Edit button in address details'; + $editAddressSelector = WebDriverBy::cssSelector($editShippingButton); + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::elementToBeClickable($editAddressSelector)); + $stepLog[] = 'Click Edit button to return to normal flow'; + $remoteWebDriver->findElement($editAddressSelector)->click(); + + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::numberOfWindowsToBe(2)); + $magentoWebDriver->switchToNextTab(); + $addressIdSelector = WebDriverBy::cssSelector($addressId); + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::presenceOfElementLocated($addressIdSelector)); + } else { + $stepLog[] = 'No continue button, standard maxo/pay now'; + $addressIdSelector = WebDriverBy::cssSelector($addressId); + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::presenceOfElementLocated($addressIdSelector)); + } + } else { + $stepLog[] = 'Popup closed, allowing checkout page to load'; + $magentoWebDriver->waitForLoadingMaskToDisappear(30); + $stepLog[] = 'Wait for Edit button in address details'; + $editAddressSelector = WebDriverBy::cssSelector($editShippingButton); + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::elementToBeClickable($editAddressSelector)); + $stepLog[] = 'Click Edit button to return to normal flow'; + $remoteWebDriver->findElement($editAddressSelector)->click(); + + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::numberOfWindowsToBe(2)); + $magentoWebDriver->switchToNextTab(); + $addressIdSelector = WebDriverBy::cssSelector($addressId); + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::presenceOfElementLocated($addressIdSelector)); + } + } catch (\Exception $ex) { + $stepLog[] = $ex->getMessage(); + } finally { + var_dump($stepLog); + } + }); + } + + public function handleSignInConsent($consentButton) + { + /** @var MagentoWebDriver $magentoWebDriver */ + $magentoWebDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver'); + $stepLog = []; + + $magentoWebDriver->executeInSelenium(function (RemoteWebDriver $remoteWebDriver) use ( + $magentoWebDriver, + $stepLog, + $consentButton + ) { + try { + if (count($remoteWebDriver->getWindowHandles()) > 1) { + $stepLog[] = 'Popup remained open, switching back to it'; + $magentoWebDriver->switchToNextTab(); + + $loginConsent = $remoteWebDriver->findElements(WebDriverBy::cssSelector($consentButton)); + + if (!empty($loginConsent)) { + $stepLog[] = 'Click Continue button'; + $loginConsent[0]->click(); + $magentoWebDriver->switchToNextTab(); + } + } else { + $stepLog[] = 'Popup closed, following redirect to account screen'; + } + } catch (\Exception $ex) { + $stepLog[] = $ex->getMessage(); + } finally { + var_dump($stepLog); + } + }); + } + + public function handleCancelSignIn( + $loginCancelButton, + $openerName + ) { + /** @var MagentoWebDriver $magentoWebDriver */ + $magentoWebDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver'); + $stepLog = []; + + $magentoWebDriver->executeInSelenium(function (RemoteWebDriver $remoteWebDriver) use ( + $magentoWebDriver, + $stepLog, + $loginCancelButton, + $openerName + ) { + try { + if (count($remoteWebDriver->getWindowHandles()) > 1) { + $stepLog[] = 'Popup remained open, switching back to it'; + $magentoWebDriver->switchToNextTab(); + + $loginCancel = $remoteWebDriver->findElements(WebDriverBy::cssSelector($loginCancelButton)); + + if (!empty($loginCancel)) { + $stepLog[] = 'Cancel login with Amazon and land back on sign-in Magento page'; + $loginCancel[0]->click(); + $remoteWebDriver->switchTo()->window($openerName); + } + } else { + $stepLog[] = 'Popup closed, signing out manually and returning to login page'; + $magentoWebDriver->amOnPage('customer/account/logout/'); + $magentoWebDriver->wait(5); + $magentoWebDriver->amOnPage('/customer/account/login/'); + } + } catch (\Exception $ex) { + $stepLog[] = $ex->getMessage(); + } finally { + var_dump($stepLog); + } + }); + } +} diff --git a/Test/Mftf-24/Helper/LoadAddresses.php b/Test/Mftf-24/Helper/LoadAddresses.php index 3e0a85622..1881277da 100644 --- a/Test/Mftf-24/Helper/LoadAddresses.php +++ b/Test/Mftf-24/Helper/LoadAddresses.php @@ -2,7 +2,11 @@ namespace Amazon\Pay\Test\Mftf\Helper; +use Facebook\WebDriver\Exception\TimeoutException; use Magento\FunctionalTestingFramework\Helper\Helper; +use Facebook\WebDriver\Remote\RemoteWebDriver; +use Facebook\WebDriver\WebDriverBy; +use Facebook\WebDriver\WebDriverExpectedCondition; class LoadAddresses extends Helper { @@ -11,17 +15,41 @@ public function loadAddresses( $addressBackButtonSelector, $defaultAddressSelector ) { - /** @var \Magento\FunctionalTestingFramework\Module\MagentoWebDriver $webDriver */ - $webDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver'); - $waitTime = 15000; + /** @var \Magento\FunctionalTestingFramework\Module\MagentoWebDriver $magentoWebDriver */ + $magentoWebDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver'); + $waitTime = 15; + $stepLog = []; try { - $webDriver->waitForElementClickable($changeAddressSelector, $waitTime); - $webDriver->click($changeAddressSelector); - $webDriver->waitForElementClickable($addressBackButtonSelector, $waitTime); - $webDriver->click($addressBackButtonSelector); + $stepLog[] = 'Waiting for Change Address button'; + $magentoWebDriver->waitForElementClickable($changeAddressSelector, $waitTime); + $magentoWebDriver->click($changeAddressSelector); + $stepLog[] = 'Clicked Change Address, waiting for Back button'; + $magentoWebDriver->waitForElementClickable($addressBackButtonSelector, $waitTime); + $magentoWebDriver->click($addressBackButtonSelector); - $webDriver->waitForElement($defaultAddressSelector, $waitTime); + $stepLog[] = 'Looking for default address'; + $magentoWebDriver->waitForElement($defaultAddressSelector, $waitTime); + $stepLog[] = 'Found default address'; + // } catch (\Exception $e) { + // $magentoWebDriver->switchToNextTab(); + + // try { + // $magentoWebDriver->executeInSelenium(function (RemoteWebDriver $remoteWebDriver) use ( + // $magentoWebDriver, + // $editShippingButton + // ) { + // $editAddressSelector = WebDriverBy::cssSelector($editShippingButton); + // $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::elementToBeClickable($editAddressSelector)); + // $magentoWebDriver->debug('Click Edit button to return to normal flow'); + // $remoteWebDriver->findElement($editAddressSelector)->click(); + + // $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::numberOfWindowsToBe(2)); + // $magentoWebDriver->switchToNextTab(); + // }); + // } catch (\Exception $e) { + + // } } catch (\Exception $e) { // Avoid out of memory error sometimes caused by print_r // print_r($e); diff --git a/Test/Mftf-24/Helper/SignInOrContinue.php b/Test/Mftf-24/Helper/SignInOrContinue.php new file mode 100644 index 000000000..a4cec5ab8 --- /dev/null +++ b/Test/Mftf-24/Helper/SignInOrContinue.php @@ -0,0 +1,145 @@ +getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver'); + + $magentoWebDriver->executeInSelenium(function (RemoteWebDriver $remoteWebDriver) use ( + $magentoWebDriver, + $emailField, + $passwordField, + $signInButton, + $openerName, + $continueButton, + $editShippingButton, + $addressId + ) { + $email = $remoteWebDriver->findElements( + WebDriverBy::cssSelector($emailField) + ); + + if (!empty($email)) { + $magentoWebDriver->fillField($emailField, new PasswordArgument('pay-demo-eu@amazon.com')); + $magentoWebDriver->fillField($passwordField, new PasswordArgument('demo123')); + + try { + $remoteWebDriver->findElement( + WebDriverBy::cssSelector($signInButton) + )->click(); + $magentoWebDriver->switchToNextTab(); + $magentoWebDriver->wait(3); + } catch (\Exception $ex) { + $magentoWebDriver->debug('exception caught'); + } catch (\Error $err) { + $magentoWebDriver->debug('error caught'); + } + } else { + $magentoWebDriver->debug('Popup appeared as normal'); + $continueAs = $remoteWebDriver->findElements(WebDriverBy::cssSelector($continueButton)); + + if (!empty($continueAs)) { + $magentoWebDriver->debug('Click Continue as... button and return to checkout'); + $continueAs[0]->click(); + $remoteWebDriver->switchTo()->window($openerName); + $magentoWebDriver->waitForPageLoad(30); + + $magentoWebDriver->debug('Wait for Edit button in address details'); + $editAddressSelector = WebDriverBy::cssSelector($editShippingButton); + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::elementToBeClickable($editAddressSelector)); + $magentoWebDriver->debug('Click Edit button to return to normal flow'); + $remoteWebDriver->findElement($editAddressSelector)->click(); + + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::numberOfWindowsToBe(2)); + $magentoWebDriver->switchToNextTab(); + $addressIdSelector = WebDriverBy::cssSelector($addressId); + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::presenceOfElementLocated($addressIdSelector)); + } else { + $addressIdSelector = WebDriverBy::cssSelector($addressId); + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::presenceOfElementLocated($addressIdSelector)); + } + } + }); + } + + public function handleSecondScreen( + $openerName, + $continueButton, + $editShippingButton, + $addressId + ) { + /** @var \Magento\FunctionalTestingFramework\Module\MagentoWebDriver $magentoWebDriver */ + $magentoWebDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver'); + + $magentoWebDriver->executeInSelenium(function (RemoteWebDriver $remoteWebDriver) use ( + $magentoWebDriver, + $openerName, + $continueButton, + $editShippingButton, + $addressId + ) { + try { + if (count($remoteWebDriver->getWindowHandles()) > 1) { + if ($magentoWebDriver->executeJS('return window.name;') === $openerName) { + $magentoWebDriver->debug('Popup remained open, switching back to it'); + $magentoWebDriver->switchToNextTab(); + } + + $continueAs = $remoteWebDriver->findElements(WebDriverBy::cssSelector($continueButton)); + + if (!empty($continueAs)) { + $magentoWebDriver->debug('Click Continue as... button and return to checkout'); + $continueAs[0]->click(); + $remoteWebDriver->switchTo()->window($openerName); + $magentoWebDriver->waitForPageLoad(30); + + $magentoWebDriver->debug('Wait for Edit button in address details'); + $editAddressSelector = WebDriverBy::cssSelector($editShippingButton); + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::elementToBeClickable($editAddressSelector)); + $magentoWebDriver->debug('Click Edit button to return to normal flow'); + $remoteWebDriver->findElement($editAddressSelector)->click(); + + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::numberOfWindowsToBe(2)); + $magentoWebDriver->switchToNextTab(); + $addressIdSelector = WebDriverBy::cssSelector($addressId); + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::presenceOfElementLocated($addressIdSelector)); + } else { + $addressIdSelector = WebDriverBy::cssSelector($addressId); + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::presenceOfElementLocated($addressIdSelector)); + } + } else { + $magentoWebDriver->debug('Popup closed, allowing checkout page to load'); + $magentoWebDriver->debug('Wait for Edit button in address details'); + $editAddressSelector = WebDriverBy::cssSelector($editShippingButton); + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::elementToBeClickable($editAddressSelector)); + $magentoWebDriver->debug('Click Edit button to return to normal flow'); + $remoteWebDriver->findElement($editAddressSelector)->click(); + + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::numberOfWindowsToBe(2)); + $magentoWebDriver->switchToNextTab(); + $addressIdSelector = WebDriverBy::cssSelector($addressId); + $remoteWebDriver->wait(30, 100)->until(WebDriverExpectedCondition::presenceOfElementLocated($addressIdSelector)); + } + } catch (\Exception $ex) { + + } + }); + } +} diff --git a/Test/Mftf-24/Section/AmazonLoginSection.xml b/Test/Mftf-24/Section/AmazonLoginSection.xml index 5ad1e5aac..be780bc5e 100644 --- a/Test/Mftf-24/Section/AmazonLoginSection.xml +++ b/Test/Mftf-24/Section/AmazonLoginSection.xml @@ -3,6 +3,7 @@
+
diff --git a/Test/Mftf-24/Section/AmazonPageSection.xml b/Test/Mftf-24/Section/AmazonPageSection.xml index 2bdefc481..a166087f8 100644 --- a/Test/Mftf-24/Section/AmazonPageSection.xml +++ b/Test/Mftf-24/Section/AmazonPageSection.xml @@ -5,7 +5,7 @@ - + @@ -17,5 +17,8 @@ + + + diff --git a/Test/Mftf-24/Test/AmazonBillingAddressVisibilityTest.xml b/Test/Mftf-24/Test/AmazonBillingAddressVisibilityTest.xml index 12a8a1603..e5fd7e17c 100644 --- a/Test/Mftf-24/Test/AmazonBillingAddressVisibilityTest.xml +++ b/Test/Mftf-24/Test/AmazonBillingAddressVisibilityTest.xml @@ -37,7 +37,7 @@
- + diff --git a/Test/Mftf-24/Test/AmazonBillingFormVisibilityTest.xml b/Test/Mftf-24/Test/AmazonBillingFormVisibilityTest.xml index 12a8a1603..e5fd7e17c 100644 --- a/Test/Mftf-24/Test/AmazonBillingFormVisibilityTest.xml +++ b/Test/Mftf-24/Test/AmazonBillingFormVisibilityTest.xml @@ -37,7 +37,7 @@ - + diff --git a/Test/Mftf-24/Test/AmazonCancelReturnUrl.xml b/Test/Mftf-24/Test/AmazonCancelReturnUrl.xml index 8ed756859..4b5096862 100644 --- a/Test/Mftf-24/Test/AmazonCancelReturnUrl.xml +++ b/Test/Mftf-24/Test/AmazonCancelReturnUrl.xml @@ -41,12 +41,6 @@ - - - - - - @@ -59,15 +53,25 @@ - - + + + + {{AmazonPageSection.emailField}} + {{AmazonPageSection.passwordField}} + {{AmazonPageSection.signInButton}} + {$openerName} + {{AmazonPageSection.continueButton}} + {{AmazonCheckoutSection.editShippingButton}} + {{AmazonPageSection.addressId}} + + + {$openerName} - {{AmazonCheckoutSection.editShippingButton}} - {{AmazonPageSection.addressId}} - {{AmazonPageSection.changePaymentButton}} - {{AmazonPageSection.changeAddressButton}} + {{AmazonPageSection.continueButton}} + {{AmazonCheckoutSection.editShippingButton}} + {{AmazonPageSection.addressId}} diff --git a/Test/Mftf-24/Test/AmazonCheckoutAsyncDeclinedTest.xml b/Test/Mftf-24/Test/AmazonCheckoutAsyncDeclinedTest.xml index 5481fd6de..11cab5dbf 100644 --- a/Test/Mftf-24/Test/AmazonCheckoutAsyncDeclinedTest.xml +++ b/Test/Mftf-24/Test/AmazonCheckoutAsyncDeclinedTest.xml @@ -23,9 +23,7 @@ - - - + diff --git a/Test/Mftf-24/Test/AmazonCheckoutAsyncSuccessTest.xml b/Test/Mftf-24/Test/AmazonCheckoutAsyncSuccessTest.xml index 65913debc..8088e6933 100644 --- a/Test/Mftf-24/Test/AmazonCheckoutAsyncSuccessTest.xml +++ b/Test/Mftf-24/Test/AmazonCheckoutAsyncSuccessTest.xml @@ -23,9 +23,7 @@ - - - + diff --git a/Test/Mftf-24/Test/AmazonCheckoutBuyerCanceledTest.xml b/Test/Mftf-24/Test/AmazonCheckoutBuyerCanceledTest.xml index 8eea58e93..e23edbdbd 100644 --- a/Test/Mftf-24/Test/AmazonCheckoutBuyerCanceledTest.xml +++ b/Test/Mftf-24/Test/AmazonCheckoutBuyerCanceledTest.xml @@ -14,9 +14,7 @@ - - - + diff --git a/Test/Mftf-24/Test/AmazonCheckoutDeclinedTest.xml b/Test/Mftf-24/Test/AmazonCheckoutDeclinedTest.xml index 8b1efaedc..64f059f44 100644 --- a/Test/Mftf-24/Test/AmazonCheckoutDeclinedTest.xml +++ b/Test/Mftf-24/Test/AmazonCheckoutDeclinedTest.xml @@ -14,9 +14,7 @@ - - - + diff --git a/Test/Mftf-24/Test/AmazonCheckoutLoggedInNoGuestButtonTest.xml b/Test/Mftf-24/Test/AmazonCheckoutLoggedInNoGuestButtonTest.xml index 5bbe81ec4..ab4cda661 100644 --- a/Test/Mftf-24/Test/AmazonCheckoutLoggedInNoGuestButtonTest.xml +++ b/Test/Mftf-24/Test/AmazonCheckoutLoggedInNoGuestButtonTest.xml @@ -46,9 +46,7 @@ - - - + diff --git a/Test/Mftf-24/Test/AmazonCheckoutLoginTest.xml b/Test/Mftf-24/Test/AmazonCheckoutLoginTest.xml index b06741461..20eaf9e64 100644 --- a/Test/Mftf-24/Test/AmazonCheckoutLoginTest.xml +++ b/Test/Mftf-24/Test/AmazonCheckoutLoginTest.xml @@ -16,6 +16,8 @@ - + + + diff --git a/Test/Mftf-24/Test/AmazonCheckoutMulticurrencySuccessTest.xml b/Test/Mftf-24/Test/AmazonCheckoutMulticurrencySuccessTest.xml index cbbee576f..d8b296db0 100644 --- a/Test/Mftf-24/Test/AmazonCheckoutMulticurrencySuccessTest.xml +++ b/Test/Mftf-24/Test/AmazonCheckoutMulticurrencySuccessTest.xml @@ -28,9 +28,7 @@ - - - + diff --git a/Test/Mftf-24/Test/AmazonCheckoutOrderTwoItems.xml b/Test/Mftf-24/Test/AmazonCheckoutOrderTwoItems.xml index 3708e8a4a..06712ca8c 100644 --- a/Test/Mftf-24/Test/AmazonCheckoutOrderTwoItems.xml +++ b/Test/Mftf-24/Test/AmazonCheckoutOrderTwoItems.xml @@ -41,9 +41,7 @@ - - - + diff --git a/Test/Mftf-24/Test/AmazonCheckoutPayNowDeclinedTest.xml b/Test/Mftf-24/Test/AmazonCheckoutPayNowDeclinedTest.xml index f0d0e2d52..d26e1af77 100644 --- a/Test/Mftf-24/Test/AmazonCheckoutPayNowDeclinedTest.xml +++ b/Test/Mftf-24/Test/AmazonCheckoutPayNowDeclinedTest.xml @@ -28,7 +28,7 @@ - + diff --git a/Test/Mftf-24/Test/AmazonCheckoutPayNowMulticurrencySuccessTest.xml b/Test/Mftf-24/Test/AmazonCheckoutPayNowMulticurrencySuccessTest.xml index 601956581..447dc540e 100644 --- a/Test/Mftf-24/Test/AmazonCheckoutPayNowMulticurrencySuccessTest.xml +++ b/Test/Mftf-24/Test/AmazonCheckoutPayNowMulticurrencySuccessTest.xml @@ -41,7 +41,7 @@ - + diff --git a/Test/Mftf-24/Test/AmazonCheckoutPayNowSuccessTest.xml b/Test/Mftf-24/Test/AmazonCheckoutPayNowSuccessTest.xml index 5a3c337e0..43a42badc 100644 --- a/Test/Mftf-24/Test/AmazonCheckoutPayNowSuccessTest.xml +++ b/Test/Mftf-24/Test/AmazonCheckoutPayNowSuccessTest.xml @@ -28,7 +28,7 @@ - + diff --git a/Test/Mftf-24/Test/AmazonCheckoutSuccessTest.xml b/Test/Mftf-24/Test/AmazonCheckoutSuccessTest.xml index 6a745d87f..c86b3b241 100644 --- a/Test/Mftf-24/Test/AmazonCheckoutSuccessTest.xml +++ b/Test/Mftf-24/Test/AmazonCheckoutSuccessTest.xml @@ -12,9 +12,7 @@ - - - + diff --git a/Test/Mftf-24/Test/AmazonInvoiceMultipleCapture.xml b/Test/Mftf-24/Test/AmazonInvoiceMultipleCapture.xml index 6b8582400..2de7e6735 100644 --- a/Test/Mftf-24/Test/AmazonInvoiceMultipleCapture.xml +++ b/Test/Mftf-24/Test/AmazonInvoiceMultipleCapture.xml @@ -27,9 +27,7 @@ - - - + diff --git a/Test/Mftf-24/Test/AmazonInvoicePendingCapturedTest.xml b/Test/Mftf-24/Test/AmazonInvoicePendingCapturedTest.xml index 4b9dae11c..35b7070dd 100644 --- a/Test/Mftf-24/Test/AmazonInvoicePendingCapturedTest.xml +++ b/Test/Mftf-24/Test/AmazonInvoicePendingCapturedTest.xml @@ -12,9 +12,7 @@ - - - + diff --git a/Test/Mftf-24/Test/AmazonInvoicePendingDeclinedTest.xml b/Test/Mftf-24/Test/AmazonInvoicePendingDeclinedTest.xml index 4c3594b6e..29dd08d1f 100644 --- a/Test/Mftf-24/Test/AmazonInvoicePendingDeclinedTest.xml +++ b/Test/Mftf-24/Test/AmazonInvoicePendingDeclinedTest.xml @@ -12,9 +12,7 @@ - - - + diff --git a/Test/Mftf-24/Test/AmazonInvoiceTest.xml b/Test/Mftf-24/Test/AmazonInvoiceTest.xml index 09398f369..bad82fcd7 100644 --- a/Test/Mftf-24/Test/AmazonInvoiceTest.xml +++ b/Test/Mftf-24/Test/AmazonInvoiceTest.xml @@ -12,9 +12,7 @@ - - - + diff --git a/Test/Mftf-24/Test/AmazonMiniCartLoginTest.xml b/Test/Mftf-24/Test/AmazonMiniCartLoginTest.xml index 74f970301..56814ecca 100644 --- a/Test/Mftf-24/Test/AmazonMiniCartLoginTest.xml +++ b/Test/Mftf-24/Test/AmazonMiniCartLoginTest.xml @@ -16,6 +16,8 @@ - + + + diff --git a/Test/Mftf-24/Test/AmazonPaymentLoginTest.xml b/Test/Mftf-24/Test/AmazonPaymentLoginTest.xml index 87ce7a46a..18b9efc1b 100644 --- a/Test/Mftf-24/Test/AmazonPaymentLoginTest.xml +++ b/Test/Mftf-24/Test/AmazonPaymentLoginTest.xml @@ -17,6 +17,6 @@ - + diff --git a/Test/Mftf-24/Test/AmazonProductLoginTest.xml b/Test/Mftf-24/Test/AmazonProductLoginTest.xml index cd4f98acc..5cf24d75b 100644 --- a/Test/Mftf-24/Test/AmazonProductLoginTest.xml +++ b/Test/Mftf-24/Test/AmazonProductLoginTest.xml @@ -16,6 +16,8 @@ - + + + diff --git a/Test/Mftf-24/Test/AmazonRefund.xml b/Test/Mftf-24/Test/AmazonRefund.xml index 18a6cbf55..db581b56a 100644 --- a/Test/Mftf-24/Test/AmazonRefund.xml +++ b/Test/Mftf-24/Test/AmazonRefund.xml @@ -12,9 +12,7 @@ - - - + diff --git a/Test/Mftf-24/Test/AmazonSignInToExistingTest.xml b/Test/Mftf-24/Test/AmazonSignInToExistingTest.xml index 8f24b4bf6..3f799a3a1 100644 --- a/Test/Mftf-24/Test/AmazonSignInToExistingTest.xml +++ b/Test/Mftf-24/Test/AmazonSignInToExistingTest.xml @@ -35,17 +35,8 @@ - - - - - - - - - - - + + diff --git a/Test/Mftf-24/Test/AmazonSigninCheckoutSuccessTest.xml b/Test/Mftf-24/Test/AmazonSigninCheckoutSuccessTest.xml index f69a5fa5e..d14a1672c 100644 --- a/Test/Mftf-24/Test/AmazonSigninCheckoutSuccessTest.xml +++ b/Test/Mftf-24/Test/AmazonSigninCheckoutSuccessTest.xml @@ -24,9 +24,7 @@ - - - + diff --git a/composer.json b/composer.json index 547bfc7e7..1a8226231 100755 --- a/composer.json +++ b/composer.json @@ -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.1", + "version": "5.14.2", "license": [ "Apache-2.0" ], @@ -18,7 +18,7 @@ "guzzlehttp/guzzle": "^6.2.0" }, "require": { - "php": "~7.0.13||~7.1.0||~7.2.0||~7.3.0||~7.4.0||~8.0.0||~8.1.0", + "php": "~7.0.13||~7.1.0||~7.2.0||~7.3.0||~7.4.0||~8.0.0||~8.1.0||~8.2.0", "magento/framework": "^102.0||^103.0", "magento/module-sales": "^100.0||^101.0||^102.0||^103.0", "magento/module-checkout": "^100.0", diff --git a/view/frontend/templates/config.phtml b/view/frontend/templates/config.phtml index 60dcaba3e..28fb09239 100755 --- a/view/frontend/templates/config.phtml +++ b/view/frontend/templates/config.phtml @@ -23,7 +23,7 @@