mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 21:33:24 +03:00
🐛 Fixed errors with Stripe Checkout (#15749)
refs https://github.com/TryGhost/Ghost/commit/1f300fb781f0 The full customer object was not being passed to the StripeAPI service when it already exists, this was resulting in inconsistent behaviour when sending the customerEmail param to the API, causing `invalid_email` errors to be thrown from Stripe and breaking the checkout.
This commit is contained in:
parent
7fda360799
commit
1ff1b75a69
@ -165,7 +165,7 @@ describe('Create Stripe Checkout Session', function () {
|
||||
if (uri === '/v1/checkout/sessions') {
|
||||
const bodyJSON = querystring.parse(body);
|
||||
// TODO: Actually work out what Stripe checks and when/how it errors
|
||||
if (bodyJSON.customerEmail) {
|
||||
if (Reflect.has(bodyJSON, 'customerEmail')) {
|
||||
return [400, {error: 'Invalid Email'}];
|
||||
}
|
||||
return [200, {id: 'cs_123', url: 'https://site.com'}];
|
||||
|
@ -88,14 +88,19 @@ class PaymentsService {
|
||||
|
||||
const email = options.email || null;
|
||||
|
||||
const session = await this.stripeAPIService.createCheckoutSession(price.id, customer, {
|
||||
const data = {
|
||||
metadata,
|
||||
successUrl: options.successUrl,
|
||||
cancelUrl: options.cancelUrl,
|
||||
customerEmail: customer ? email : null,
|
||||
trialDays: trialDays ?? tier.trialDays,
|
||||
coupon: coupon?.id
|
||||
});
|
||||
};
|
||||
|
||||
if (!customer && email) {
|
||||
data.customerEmail = email;
|
||||
}
|
||||
|
||||
const session = await this.stripeAPIService.createCheckoutSession(price.id, customer, data);
|
||||
|
||||
return session.url;
|
||||
}
|
||||
@ -108,9 +113,7 @@ class PaymentsService {
|
||||
for (const row of rows) {
|
||||
const customer = await this.stripeAPIService.getCustomer(row.customer_id);
|
||||
if (!customer.deleted) {
|
||||
return {
|
||||
id: customer.id
|
||||
};
|
||||
return customer;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user