@@ -815,17 +815,18 @@ public function completeCheckoutSession($amazonSessionId, $cartId = null, $order
815815 */
816816 public function placeOrder ($ amazonSessionId , $ quoteId = null )
817817 {
818-
819818 // verify the shipping address has not been modified in Magento, it must match
820819 // the one selected in the Amazon checkout session (express checkout only)
821- if ($ amznShippingAddress = $ this ->getShippingAddress ($ amazonSessionId )) {
822- $ amazonAddress = $ amznShippingAddress [0 ];
823- $ magentoAddress = $ this ->session ->getQuoteFromIdOrSession ($ quoteId )->getShippingAddress ();
824- if (!$ this ->addressHelper ->validateShippingIsSame ($ amazonAddress , $ magentoAddress )) {
825- return $ this ->handleCompleteCheckoutSessionError (
826- self ::ADDRESS_CHANGED_CHECKOUT_ERROR_MESSAGE ,
827- $ this ->getAddressMismatchDetails ($ amazonAddress , $ magentoAddress )
828- );
820+ if ($ this ->isExpressCheckoutFlow ()) {
821+ if ($ amznShippingAddress = $ this ->getShippingAddress ($ amazonSessionId )) {
822+ $ amazonAddress = $ amznShippingAddress [0 ];
823+ $ magentoAddress = $ this ->session ->getQuoteFromIdOrSession ($ quoteId )->getShippingAddress ();
824+ if (!$ this ->addressHelper ->validateShippingIsSame ($ amazonAddress , $ magentoAddress )) {
825+ return $ this ->handleCompleteCheckoutSessionError (
826+ self ::ADDRESS_CHANGED_CHECKOUT_ERROR_MESSAGE ,
827+ $ this ->getAddressMismatchDetails ($ amazonAddress , $ magentoAddress )
828+ );
829+ }
829830 }
830831 }
831832
@@ -915,7 +916,7 @@ public function placeOrder($amazonSessionId, $quoteId = null)
915916 * @param mixed $amazonSession
916917 * @return \Magento\Framework\Phrase|mixed
917918 */
918- protected function getCanceledMessage ($ amazonSession )
919+ public function getCanceledMessage ($ amazonSession )
919920 {
920921 if ($ amazonSession ['statusDetails ' ]['reasonCode ' ] == 'BuyerCanceled ' ) {
921922 return $ this ->getTranslationString ('This transaction was cancelled. Please try again. ' );
@@ -953,6 +954,20 @@ protected function getAddressMismatchDetails($amazonAddress, $magentoAddress)
953954 ]);
954955 }
955956
957+ /**
958+ * Determine whether the checkout session was completed via Express Checkout
959+ *
960+ * @return bool
961+ */
962+ protected function isExpressCheckoutFlow ()
963+ {
964+ $ stack = debug_backtrace (DEBUG_BACKTRACE_PROVIDE_OBJECT );
965+ return !empty (array_filter ($ stack , function ($ entry ) {
966+ return isset ($ entry ['class ' ])
967+ && $ entry ['class ' ] === 'Amazon \\Pay \\Controller \\Checkout \\PlaceOrder \\Interceptor ' ;
968+ }));
969+ }
970+
956971 /**
957972 * Update vault token
958973 *
0 commit comments