mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
continuation of PR #8161 Display error notification when attempting to purchase invalid amount of gems - fixes #8145 (#8688)
* Translation string for error notification * Use function instead of a link for paypal * Inject notification service, function to check the amount of gems to purchase, function to handle payments with paypal * Throw error if amount of gems is zero or negative * Add condition to raise error if amount is negative * Added gem errors for gifts 0 or less * Fixed linting and broken test * Fixed test syntax * Added back needed strings * Fixed group locales
This commit is contained in:
committed by
Sabe Jones
parent
48bbc22fb4
commit
e901850a6f
@@ -98,6 +98,9 @@ api.checkout = async function checkout (options = {}) {
|
||||
|
||||
if (gift) {
|
||||
if (gift.type === this.constants.GIFT_TYPE_GEMS) {
|
||||
if (gift.gems.amount <= 0) {
|
||||
throw new BadRequest(i18n.t('badAmountOfGemsToPurchase'));
|
||||
}
|
||||
amount = gift.gems.amount / 4;
|
||||
} else if (gift.type === this.constants.GIFT_TYPE_SUBSCRIPTION) {
|
||||
amount = common.content.subscriptionBlocks[gift.subscription.key].price;
|
||||
|
||||
@@ -74,6 +74,9 @@ api.checkout = async function checkout (options = {}) {
|
||||
let description = 'Habitica Gems';
|
||||
if (gift) {
|
||||
if (gift.type === 'gems') {
|
||||
if (gift.gems.amount <= 0) {
|
||||
throw new BadRequest(i18n.t('badAmountOfGemsToPurchase'));
|
||||
}
|
||||
amount = Number(gift.gems.amount / 4).toFixed(2);
|
||||
description = `${description} (Gift)`;
|
||||
} else {
|
||||
|
||||
@@ -107,6 +107,9 @@ api.checkout = async function checkout (options, stripeInc) {
|
||||
if (gift.type === 'subscription') {
|
||||
amount = `${shared.content.subscriptionBlocks[gift.subscription.key].price * 100}`;
|
||||
} else {
|
||||
if (gift.gems.amount <= 0) {
|
||||
throw new BadRequest(shared.i18n.t('badAmountOfGemsToPurchase'));
|
||||
}
|
||||
amount = `${gift.gems.amount / 4 * 100}`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user