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
This commit is contained in:
Matteo Pagliazzi 2020-08-03 15:34:18 +02:00 committed by GitHub
parent d21b9a5af4
commit 65e15e0c1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View file

@ -74,6 +74,7 @@ export default {
setupAmazon () {
if (this.isAmazonSetup) return;
this.isAmazonSetup = true;
this.amazonLogout();
this.showButton();
},
showButton () {

View file

@ -2,8 +2,9 @@
<b-modal
id="amazon-payment"
title="Amazon"
:hide-footer="true"
size="md"
:hide-footer="true"
@hide="reset()"
>
<h2 class="text-center">
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();
}
}

View file

@ -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;