mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Fixed gem purchasing and error catching
This commit is contained in:
@@ -173,6 +173,7 @@ export default {
|
|||||||
}).bind('AmazonPayRecurring');
|
}).bind('AmazonPayRecurring');
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
this.$set(this, 'amazonButtonEnabled', true);
|
||||||
walletParams.amazonOrderReferenceId = this.amazonPayments.orderReferenceId;
|
walletParams.amazonOrderReferenceId = this.amazonPayments.orderReferenceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,21 +186,21 @@ export default {
|
|||||||
// @TODO: A gift should not read the same as buying gems for yourself.
|
// @TODO: A gift should not read the same as buying gems for yourself.
|
||||||
if (this.amazonPayments.type === 'single') {
|
if (this.amazonPayments.type === 'single') {
|
||||||
let url = '/amazon/checkout';
|
let url = '/amazon/checkout';
|
||||||
let response = await axios.post(url, {
|
|
||||||
orderReferenceId: this.amazonPayments.orderReferenceId,
|
|
||||||
gift: this.amazonPayments.gift,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.status < 400) {
|
try {
|
||||||
|
await axios.post(url, {
|
||||||
|
orderReferenceId: this.amazonPayments.orderReferenceId,
|
||||||
|
gift: this.amazonPayments.gift,
|
||||||
|
});
|
||||||
|
|
||||||
this.$set(this, 'amazonButtonEnabled', true);
|
this.$set(this, 'amazonButtonEnabled', true);
|
||||||
this.reset();
|
this.reset();
|
||||||
// @TODO: What are we syncing?
|
// @TODO: What are we syncing?
|
||||||
window.location.reload(true);
|
window.location.reload(true);
|
||||||
return;
|
} catch (e) {
|
||||||
|
this.$set(this, 'amazonButtonEnabled', true);
|
||||||
|
this.amazonPaymentsreset();
|
||||||
}
|
}
|
||||||
|
|
||||||
alert(response.message);
|
|
||||||
this.amazonPaymentsreset();
|
|
||||||
} else if (this.amazonPayments.type === 'subscription') {
|
} else if (this.amazonPayments.type === 'subscription') {
|
||||||
let url = '/amazon/subscribe';
|
let url = '/amazon/subscribe';
|
||||||
|
|
||||||
@@ -207,40 +208,37 @@ export default {
|
|||||||
url = '/api/v3/groups/create-plan';
|
url = '/api/v3/groups/create-plan';
|
||||||
}
|
}
|
||||||
|
|
||||||
let response = await axios.post(url, {
|
try {
|
||||||
billingAgreementId: this.amazonPayments.billingAgreementId,
|
const response = await axios.post(url, {
|
||||||
subscription: this.amazonPayments.subscription,
|
billingAgreementId: this.amazonPayments.billingAgreementId,
|
||||||
coupon: this.amazonPayments.coupon,
|
subscription: this.amazonPayments.subscription,
|
||||||
groupId: this.amazonPayments.groupId,
|
coupon: this.amazonPayments.coupon,
|
||||||
groupToCreate: this.amazonPayments.groupToCreate,
|
groupId: this.amazonPayments.groupId,
|
||||||
paymentType: 'Amazon',
|
groupToCreate: this.amazonPayments.groupToCreate,
|
||||||
});
|
paymentType: 'Amazon',
|
||||||
|
});
|
||||||
|
|
||||||
let responseStatus = response.status;
|
this.$root.$emit('bv::hide::modal', 'amazon-payment');
|
||||||
if (responseStatus >= 400) {
|
|
||||||
|
let newGroup = response.data.data;
|
||||||
|
if (newGroup && newGroup._id) {
|
||||||
|
// @TODO: Just append? or $emit?
|
||||||
|
this.$router.push(`/group-plans/${newGroup._id}/task-information`);
|
||||||
|
this.user.guilds.push(newGroup._id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.amazonPayments.groupId) {
|
||||||
|
this.$router.push(`/group-plans/${this.amazonPayments.groupId}/task-information`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.location.reload(true);
|
||||||
|
this.reset();
|
||||||
|
} catch (e) {
|
||||||
this.$set(this, 'amazonButtonEnabled', true);
|
this.$set(this, 'amazonButtonEnabled', true);
|
||||||
alert(`Error: ${response.message}`);
|
|
||||||
// @TODO: do we need this? this.amazonPaymentsreset();
|
// @TODO: do we need this? this.amazonPaymentsreset();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$root.$emit('bv::hide::modal', 'amazon-payment');
|
|
||||||
|
|
||||||
let newGroup = response.data.data;
|
|
||||||
if (newGroup && newGroup._id) {
|
|
||||||
// @TODO: Just append? or $emit?
|
|
||||||
this.$router.push(`/group-plans/${newGroup._id}/task-information`);
|
|
||||||
this.user.guilds.push(newGroup._id);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.amazonPayments.groupId) {
|
|
||||||
this.$router.push(`/group-plans/${this.amazonPayments.groupId}/task-information`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.location.reload(true);
|
|
||||||
this.reset();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
amazonOnPaymentSelect () {
|
amazonOnPaymentSelect () {
|
||||||
|
|||||||
Reference in New Issue
Block a user