🐛 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:
Fabien 'egg' O'Carroll 2022-11-02 02:18:30 +07:00 committed by GitHub
parent 7fda360799
commit 1ff1b75a69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 7 deletions

View File

@ -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'}];

View File

@ -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;
}
}