mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-18 02:21:47 -05:00
Fixed preset amount in Stripe Checkout (#17615)
refs https://github.com/TryGhost/Product/issues/3666 - Stripe has a set of minimum charges per currency. This adds a basic safeguard on the backend side, while the main validation should happen in Portal - Stripe docs: https://stripe.com/docs/currencies#minimum-and-maximum-charge-amounts
This commit is contained in:
parent
5462bc0a96
commit
c201e4eb4f
1 changed files with 6 additions and 3 deletions
|
@ -283,8 +283,9 @@ class PaymentsService {
|
|||
const currency = this.settingsCache.get('donations_currency');
|
||||
const suggestedAmount = this.settingsCache.get('donations_suggested_amount');
|
||||
|
||||
// Stripe requires a minimum of 50 cents
|
||||
const amount = suggestedAmount && suggestedAmount > 50 ? suggestedAmount : 0;
|
||||
// Stripe requires a minimum charge amount
|
||||
// @see https://stripe.com/docs/currencies#minimum-and-maximum-charge-amounts
|
||||
const amount = suggestedAmount && suggestedAmount >= 100 ? suggestedAmount : 0;
|
||||
|
||||
const price = await this.StripePriceModel
|
||||
.where({
|
||||
|
@ -338,13 +339,15 @@ class PaymentsService {
|
|||
async createPriceForDonations({currency, amount, nickname}) {
|
||||
const product = await this.getProductForDonations({name: nickname});
|
||||
|
||||
const preset = amount ? amount : null;
|
||||
|
||||
// Create the price in Stripe
|
||||
const price = await this.stripeAPIService.createPrice({
|
||||
currency,
|
||||
product: product.id,
|
||||
custom_unit_amount: {
|
||||
enabled: true,
|
||||
preset: amount
|
||||
preset
|
||||
},
|
||||
nickname,
|
||||
type: 'one-time',
|
||||
|
|
Loading…
Add table
Reference in a new issue