mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
Payments: Success Messages (#10903)
* fix v-once * gems purchase success dialog * amazon and stripe support for gems message, translations * subscriptions success message * subscriptions success message * group plans success message and many fixes * finish success messages for payments * add success modal when gifting from balance
This commit is contained in:
@@ -34,6 +34,7 @@ import * as Analytics from 'client/libs/analytics';
|
||||
import axios from 'axios';
|
||||
import { mapState } from 'client/libs/store';
|
||||
import { CONSTANTS, setLocalSetting } from 'client/libs/userlocalManager';
|
||||
import pick from 'lodash/pick';
|
||||
|
||||
const AMAZON_PAYMENTS = process.env.AMAZON_PAYMENTS; // eslint-disable-line
|
||||
const habiticaUrl = `${location.protocol}//${location.host}`;
|
||||
@@ -56,6 +57,8 @@ export default {
|
||||
OffAmazonPayments: {},
|
||||
isAmazonSetup: false,
|
||||
amazonButtonEnabled: false,
|
||||
groupToCreate: null, // creating new group
|
||||
group: null, // upgrading existing group
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -189,10 +192,37 @@ export default {
|
||||
new this.OffAmazonPayments.Widgets.Wallet(walletParams).bind('AmazonPayWallet');
|
||||
},
|
||||
storePaymentStatusAndReload (url) {
|
||||
let paymentType;
|
||||
|
||||
if (this.amazonPayments.type === 'single' && !this.amazonPayments.gift) paymentType = 'gems';
|
||||
if (this.amazonPayments.type === 'subscription') paymentType = 'subscription';
|
||||
if (this.amazonPayments.groupId || this.amazonPayments.groupToCreate) paymentType = 'groupPlan';
|
||||
if (this.amazonPayments.type === 'single' && this.amazonPayments.gift && this.amazonPayments.giftReceiver) {
|
||||
paymentType = this.amazonPayments.gift.type === 'gems' ? 'gift-gems' : 'gift-subscription';
|
||||
}
|
||||
|
||||
const appState = {
|
||||
paymentMethod: 'amazon',
|
||||
paymentCompleted: true,
|
||||
paymentType,
|
||||
};
|
||||
if (paymentType === 'subscription') {
|
||||
appState.subscriptionKey = this.amazonPayments.subscription;
|
||||
} else if (paymentType === 'groupPlan') {
|
||||
appState.subscriptionKey = this.amazonPayments.subscription;
|
||||
|
||||
if (this.amazonPayments.groupToCreate) {
|
||||
appState.newGroup = true;
|
||||
appState.group = pick(this.amazonPayments.groupToCreate, ['_id', 'memberCount', 'name']);
|
||||
} else {
|
||||
appState.newGroup = false;
|
||||
appState.group = pick(this.amazonPayments.group, ['_id', 'memberCount', 'name']);
|
||||
}
|
||||
} else if (paymentType.indexOf('gift-') === 0) {
|
||||
appState.gift = this.amazonPayments.gift;
|
||||
appState.giftReceiver = this.amazonPayments.giftReceiver;
|
||||
}
|
||||
|
||||
setLocalSetting(CONSTANTS.savedAppStateValues.SAVED_APP_STATE, JSON.stringify(appState));
|
||||
if (url) {
|
||||
window.location.assign(url);
|
||||
@@ -215,11 +245,11 @@ export default {
|
||||
});
|
||||
|
||||
this.$set(this, 'amazonButtonEnabled', true);
|
||||
this.reset();
|
||||
this.storePaymentStatusAndReload();
|
||||
} catch (e) {
|
||||
console.error(e); // eslint-disable-line no-console
|
||||
this.$set(this, 'amazonButtonEnabled', true);
|
||||
this.amazonPaymentsreset();
|
||||
this.reset();
|
||||
}
|
||||
} else if (this.amazonPayments.type === 'subscription') {
|
||||
let url = '/amazon/subscribe';
|
||||
@@ -265,7 +295,6 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
this.reset();
|
||||
this.storePaymentStatusAndReload();
|
||||
} catch (e) {
|
||||
this.$set(this, 'amazonButtonEnabled', true);
|
||||
@@ -286,13 +315,19 @@ export default {
|
||||
this.amazonPayments.modal = null;
|
||||
this.amazonPayments.type = null;
|
||||
this.amazonPayments.loggedIn = false;
|
||||
|
||||
// Gift
|
||||
this.amazonPayments.gift = null;
|
||||
this.amazonPayments.giftReceiver = null;
|
||||
|
||||
this.amazonPayments.billingAgreementId = null;
|
||||
this.amazonPayments.orderReferenceId = null;
|
||||
this.amazonPayments.paymentSelected = false;
|
||||
this.amazonPayments.recurringConsent = false;
|
||||
this.amazonPayments.subscription = null;
|
||||
this.amazonPayments.coupon = null;
|
||||
this.amazonPayments.groupToCreate = null;
|
||||
this.amazonPayments.group = null;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user