From 65e15e0c1d09e6b84170618269d81d8cd1b7d78d Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Mon, 3 Aug 2020 15:34:18 +0200 Subject: [PATCH] Fix multiple purchases with Amazon Pay (#12422) * fix(amazon): logout when modal is closed, prevents issue with multiple order reference ids * amazon logout when the button is loaded the first time --- website/client/src/components/payments/amazonButton.vue | 1 + website/client/src/components/payments/amazonModal.vue | 9 ++++++--- website/client/src/mixins/payments.js | 8 ++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/website/client/src/components/payments/amazonButton.vue b/website/client/src/components/payments/amazonButton.vue index e7050ce99d..5a292ed8e3 100644 --- a/website/client/src/components/payments/amazonButton.vue +++ b/website/client/src/components/payments/amazonButton.vue @@ -74,6 +74,7 @@ export default { setupAmazon () { if (this.isAmazonSetup) return; this.isAmazonSetup = true; + this.amazonLogout(); this.showButton(); }, showButton () { diff --git a/website/client/src/components/payments/amazonModal.vue b/website/client/src/components/payments/amazonModal.vue index f9b7e934f4..b18dab6175 100644 --- a/website/client/src/components/payments/amazonModal.vue +++ b/website/client/src/components/payments/amazonModal.vue @@ -2,8 +2,9 @@

Continue with Amazon @@ -58,10 +59,12 @@ import pick from 'lodash/pick'; import * as Analytics from '@/libs/analytics'; import { mapState } from '@/libs/store'; import { CONSTANTS, setLocalSetting } from '@/libs/userlocalManager'; +import paymentsMixin from '@/mixins/payments'; const habiticaUrl = `${window.location.protocol}//${window.location.host}`; export default { + mixins: [paymentsMixin], data () { return { amazonPayments: { @@ -201,6 +204,7 @@ export default { } setLocalSetting(CONSTANTS.savedAppStateValues.SAVED_APP_STATE, JSON.stringify(appState)); + if (url) { window.location.assign(url); } else { @@ -245,8 +249,6 @@ export default { paymentType: 'Amazon', }); - this.$root.$emit('bv::hide::modal', 'amazon-payment'); - const newGroup = response.data.data; if (newGroup && newGroup._id) { // Handle new user signup @@ -275,6 +277,7 @@ export default { this.storePaymentStatusAndReload(); } catch (e) { this.$set(this, 'amazonButtonEnabled', true); + this.$root.$emit('bv::hide::modal', 'amazon-payment'); // @TODO: do we need this? this.amazonPaymentsreset(); } } diff --git a/website/client/src/mixins/payments.js b/website/client/src/mixins/payments.js index 8d812aa080..a4d7e8ff58 100644 --- a/website/client/src/mixins/payments.js +++ b/website/client/src/mixins/payments.js @@ -263,9 +263,17 @@ export default { window.alert(error.getErrorMessage()); this.reset(); }, + // Make sure the amazon session is reset between different sessions and after each purchase + amazonLogout () { + if (window.amazon && window.amazon.Login && typeof window.amazon.Login.logout === 'function') { + window.amazon.Login.logout(); + } + }, reset () { // @TODO: Ensure we are using all of these // some vars are set in the payments mixin. We should try to edit in one place + this.amazonLogout(); + this.amazonPayments.modal = null; this.amazonPayments.type = null; this.amazonPayments.loggedIn = false;