mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
New Payments Buttons (#11045)
* start implementing separate amazon button component * wio * switch amazon to new flow * adjust amazon pay button size * design buttons and add them to the settings page * abstract css * fixes and buy gems modal * group plans css * new buttons for gifts, fix padding in settings * gift modal styles * final style fixes
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<template lang="pug">
|
||||
b-modal#amazon-payment(title="Amazon", :hide-footer="true", size='md')
|
||||
h2.text-center Continue with Amazon
|
||||
#AmazonPayButton
|
||||
#AmazonPayWallet(v-if="amazonPayments.loggedIn", style="width: 400px; height: 228px;")
|
||||
template(v-if="amazonPayments.loggedIn && amazonPayments.type === 'subscription'")
|
||||
br
|
||||
@@ -19,7 +18,7 @@
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
#AmazonPayButton, #AmazonPayWallet, #AmazonPayRecurring {
|
||||
#AmazonPayWallet, #AmazonPayRecurring {
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
@@ -54,7 +53,6 @@ export default {
|
||||
subscription: null,
|
||||
coupon: null,
|
||||
},
|
||||
OffAmazonPayments: {},
|
||||
isAmazonSetup: false,
|
||||
amazonButtonEnabled: false,
|
||||
groupToCreate: null, // creating new group
|
||||
@@ -74,12 +72,6 @@ export default {
|
||||
},
|
||||
},
|
||||
mounted () {
|
||||
if (this.isAmazonReady) return this.setupAmazon();
|
||||
|
||||
this.$store.watch(state => state.isAmazonReady, (isAmazonReady) => {
|
||||
if (isAmazonReady) return this.setupAmazon();
|
||||
});
|
||||
|
||||
this.$root.$on('habitica::pay-with-amazon', (amazonPaymentsData) => {
|
||||
if (!amazonPaymentsData) return;
|
||||
|
||||
@@ -90,67 +82,30 @@ export default {
|
||||
this.amazonPayments = Object.assign({}, amazonPayments, amazonPaymentsData);
|
||||
|
||||
this.$root.$emit('bv::show::modal', 'amazon-payment');
|
||||
|
||||
this.$nextTick(async () => {
|
||||
if (this.amazonPayments.type === 'subscription') {
|
||||
this.amazonInitWidgets();
|
||||
} else {
|
||||
let url = '/amazon/createOrderReferenceId';
|
||||
let response = await axios.post(url, {
|
||||
billingAgreementId: this.amazonPayments.billingAgreementId,
|
||||
});
|
||||
|
||||
if (response.status <= 400) {
|
||||
this.amazonPayments.orderReferenceId = response.data.data.orderReferenceId;
|
||||
this.amazonInitWidgets();
|
||||
} else {
|
||||
alert(response.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
destroyed () {
|
||||
this.$root.$off('habitica::pay-with-amazon');
|
||||
},
|
||||
methods: {
|
||||
setupAmazon () {
|
||||
if (this.isAmazonSetup) return false;
|
||||
this.isAmazonSetup = true;
|
||||
this.OffAmazonPayments = window.OffAmazonPayments;
|
||||
this.showButton();
|
||||
},
|
||||
showButton () {
|
||||
// @TODO: prevent modal close form clicking outside
|
||||
let amazonButton = this.OffAmazonPayments.Button( // eslint-disable-line
|
||||
'AmazonPayButton',
|
||||
AMAZON_PAYMENTS.SELLER_ID,
|
||||
{
|
||||
type: 'PwA',
|
||||
color: 'Gold',
|
||||
size: 'small',
|
||||
agreementType: 'BillingAgreement',
|
||||
onSignIn: async (contract) => {
|
||||
this.amazonPayments.billingAgreementId = contract.getAmazonBillingAgreementId();
|
||||
|
||||
this.$set(this.amazonPayments, 'loggedIn', true);
|
||||
|
||||
if (this.amazonPayments.type === 'subscription') {
|
||||
this.amazonInitWidgets();
|
||||
} else {
|
||||
let url = '/amazon/createOrderReferenceId';
|
||||
let response = await axios.post(url, {
|
||||
billingAgreementId: this.amazonPayments.billingAgreementId,
|
||||
});
|
||||
|
||||
if (response.status <= 400) {
|
||||
this.amazonPayments.orderReferenceId = response.data.data.orderReferenceId;
|
||||
this.amazonInitWidgets();
|
||||
return;
|
||||
}
|
||||
|
||||
alert(response.message);
|
||||
}
|
||||
},
|
||||
authorization: () => {
|
||||
window.amazon.Login.authorize({
|
||||
scope: 'payments:widget',
|
||||
popup: true,
|
||||
}, function amazonSuccess (response) {
|
||||
if (response.error) return alert(response.error);
|
||||
|
||||
let url = '/amazon/verifyAccessToken';
|
||||
axios.post(url, response)
|
||||
.catch((e) => {
|
||||
alert(e.message);
|
||||
});
|
||||
});
|
||||
},
|
||||
onError: this.amazonOnError,
|
||||
});
|
||||
},
|
||||
amazonInitWidgets () {
|
||||
let walletParams = {
|
||||
sellerId: AMAZON_PAYMENTS.SELLER_ID, // @TODO: Import
|
||||
@@ -167,15 +122,14 @@ export default {
|
||||
walletParams.onReady = (billingAgreement) => {
|
||||
this.amazonPayments.billingAgreementId = billingAgreement.getAmazonBillingAgreementId();
|
||||
|
||||
new this.OffAmazonPayments.Widgets.Consent({
|
||||
new window.OffAmazonPayments.Widgets.Consent({
|
||||
sellerId: AMAZON_PAYMENTS.SELLER_ID,
|
||||
amazonBillingAgreementId: this.amazonPayments.billingAgreementId,
|
||||
design: {
|
||||
designMode: 'responsive',
|
||||
},
|
||||
onReady: (consent) => {
|
||||
let getConsent = consent.getConsentStatus;
|
||||
this.$set(this.amazonPayments, 'recurringConsent', getConsent ? Boolean(getConsent()) : false);
|
||||
this.$set(this.amazonPayments, 'recurringConsent', consent.getConsentStatus ? Boolean(consent.getConsentStatus()) : false);
|
||||
this.$set(this, 'amazonButtonEnabled', true);
|
||||
},
|
||||
onConsent: (consent) => {
|
||||
@@ -189,7 +143,7 @@ export default {
|
||||
walletParams.amazonOrderReferenceId = this.amazonPayments.orderReferenceId;
|
||||
}
|
||||
|
||||
new this.OffAmazonPayments.Widgets.Wallet(walletParams).bind('AmazonPayWallet');
|
||||
new window.OffAmazonPayments.Widgets.Wallet(walletParams).bind('AmazonPayWallet');
|
||||
},
|
||||
storePaymentStatusAndReload (url) {
|
||||
let paymentType;
|
||||
@@ -305,30 +259,6 @@ export default {
|
||||
amazonOnPaymentSelect () {
|
||||
this.$set(this.amazonPayments, 'paymentSelected', true);
|
||||
},
|
||||
amazonOnError (error) {
|
||||
alert(error.getErrorMessage());
|
||||
this.reset();
|
||||
},
|
||||
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.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;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user