fix(amazon): disabled state for button, fix bug where checkout button would not appear

This commit is contained in:
Matteo Pagliazzi
2019-03-13 19:19:30 +01:00
parent ef42fba049
commit c7309ae179
4 changed files with 24 additions and 6 deletions

View File

@@ -10,6 +10,10 @@
.btn, .btn:hover, .btn:active { .btn, .btn:hover, .btn:active {
box-shadow: none; box-shadow: none;
} }
.payment-item > *{
cursor: default !important;
}
} }
.payment-item { .payment-item {

View File

@@ -35,6 +35,10 @@ export default {
}, },
props: { props: {
amazonData: Object, amazonData: Object,
amazonDisabled: {
type: Boolean,
default: false,
},
}, },
computed: { computed: {
...mapState({user: 'user.data'}), ...mapState({user: 'user.data'}),
@@ -48,11 +52,16 @@ export default {
return false; return false;
}, },
}, },
watch: {
amazonData () {
this.amazonPaymentsInit(this.amazonData);
},
},
beforeMount () { beforeMount () {
this.buttonId = `AmazonPayButton-${uuid.v4()}`; this.buttonId = `AmazonPayButton-${uuid.v4()}`;
}, },
mounted () { mounted () {
this.amazonPaymentsInit(this.amazonData); // TOOD clone this.amazonPaymentsInit(this.amazonData);
if (this.isAmazonReady) return this.setupAmazon(); if (this.isAmazonReady) return this.setupAmazon();
this.$store.watch(state => state.isAmazonReady, (isAmazonReady) => { this.$store.watch(state => state.isAmazonReady, (isAmazonReady) => {
@@ -75,6 +84,8 @@ export default {
size: 'large', size: 'large',
agreementType: 'BillingAgreement', agreementType: 'BillingAgreement',
onSignIn: async (contract) => { // @TODO send to modal onSignIn: async (contract) => { // @TODO send to modal
if (this.amazonDisabled === true) return null;
// if (!this.checkGemAmount(this.amazonData)) return;
this.amazonPayments.billingAgreementId = contract.getAmazonBillingAgreementId(); this.amazonPayments.billingAgreementId = contract.getAmazonBillingAgreementId();
this.$set(this.amazonPayments, 'loggedIn', true); this.$set(this.amazonPayments, 'loggedIn', true);
@@ -82,6 +93,7 @@ export default {
this.$root.$emit('habitica::pay-with-amazon', this.amazonPayments); this.$root.$emit('habitica::pay-with-amazon', this.amazonPayments);
}, },
authorization: () => { authorization: () => {
if (this.amazonDisabled === true) return null;
window.amazon.Login.authorize({ window.amazon.Login.authorize({
scope: 'payments:widget', scope: 'payments:widget',
popup: true, popup: true,

View File

@@ -48,15 +48,18 @@ b-modal#send-gems(:title="title", :hide-footer="true", size='md', @hide='onHide(
@click="sendGift()", @click="sendGift()",
:disabled="sendingInProgress" :disabled="sendingInProgress"
) {{ $t("send") }} ) {{ $t("send") }}
.payments-column.mx-auto(v-else, :class="{'payments-disabled': !gift.subscription.key}") .payments-column.mx-auto(v-else, :class="{'payments-disabled': !gift.subscription.key && gift.gems.amount < 1}")
button.purchase.btn.btn-primary.payment-button.payment-item(@click='showStripe({gift, uuid: userReceivingGems._id, receiverName})', :disabled="!gift.subscription.key") button.purchase.btn.btn-primary.payment-button.payment-item(@click='showStripe({gift, uuid: userReceivingGems._id, receiverName})', :disabled="!gift.subscription.key && gift.gems.amount < 1")
.svg-icon.credit-card-icon(v-html="icons.creditCardIcon") .svg-icon.credit-card-icon(v-html="icons.creditCardIcon")
| {{ $t('card') }} | {{ $t('card') }}
button.btn.payment-item.paypal-checkout.payment-button(@click="openPaypalGift({gift: gift, giftedTo: userReceivingGems._id, receiverName})", :disabled="!gift.subscription.key") button.btn.payment-item.paypal-checkout.payment-button(@click="openPaypalGift({gift: gift, giftedTo: userReceivingGems._id, receiverName})", :disabled="!gift.subscription.key && gift.gems.amount < 1")
| &nbsp; | &nbsp;
img(src='~assets/images/paypal-checkout.png', :alt="$t('paypal')") img(src='~assets/images/paypal-checkout.png', :alt="$t('paypal')")
| &nbsp; | &nbsp;
amazon-button.payment-item.mb-0(:amazon-data="{type: 'single', gift, giftedTo: userReceivingGems._id, receiverName}") amazon-button.payment-item.mb-0(
:amazon-data="{type: 'single', gift, giftedTo: userReceivingGems._id, receiverName}",
:amazon-disabled="!gift.subscription.key && gift.gems.amount < 1",
)
</template> </template>
<style lang="scss"> <style lang="scss">

View File

@@ -223,7 +223,6 @@ export default {
return true; return true;
}, },
amazonPaymentsInit (data) { amazonPaymentsInit (data) {
if (!this.checkGemAmount(data)) return;
if (data.type !== 'single' && data.type !== 'subscription') return; if (data.type !== 'single' && data.type !== 'subscription') return;
if (data.gift) { if (data.gift) {