diff --git a/ghost/core/core/server/services/stripe/stripe-api.js b/ghost/core/core/server/services/stripe/stripe-api.js index 092588a245f..9af5b7acd56 100644 --- a/ghost/core/core/server/services/stripe/stripe-api.js +++ b/ghost/core/core/server/services/stripe/stripe-api.js @@ -599,7 +599,7 @@ module.exports = class StripeAPI { } if (customerId && this._config.enableAutomaticTax) { - stripeSessionOptions.customer_update = {address: 'auto'}; + stripeSessionOptions.customer_update = {address: 'auto', name: 'auto'}; } // @ts-ignore @@ -670,7 +670,7 @@ module.exports = class StripeAPI { }; if (customer && this._config.enableAutomaticTax) { - stripeSessionOptions.customer_update = {address: 'auto'}; + stripeSessionOptions.customer_update = {address: 'auto', name: 'auto'}; } // @ts-ignore @@ -729,7 +729,7 @@ module.exports = class StripeAPI { }; if (customer && this._config.enableAutomaticTax) { - stripeSessionOptions.customer_update = {address: 'auto'}; + stripeSessionOptions.customer_update = {address: 'auto', name: 'auto'}; } // @ts-ignore diff --git a/ghost/core/test/unit/server/services/stripe/stripe-api.test.js b/ghost/core/test/unit/server/services/stripe/stripe-api.test.js index 02d01b727d7..97807af2964 100644 --- a/ghost/core/test/unit/server/services/stripe/stripe-api.test.js +++ b/ghost/core/test/unit/server/services/stripe/stripe-api.test.js @@ -458,7 +458,7 @@ describe('StripeAPI', function () { await api.createCheckoutSession('priceId', mockCustomer, { trialDays: null }); - assertExists(mockStripe.checkout.sessions.create.firstCall.firstArg.customer_update); + assert.deepEqual(mockStripe.checkout.sessions.create.firstCall.firstArg.customer_update, {address: 'auto', name: 'auto'}); }); it('createCheckoutSession does not add customer_update if automatic tax flag is enabled and customer is undefined', async function () { @@ -648,6 +648,27 @@ describe('StripeAPI', function () { assert(mockStripe.checkout.sessions.create.firstCall.firstArg.custom_fields.length <= 3); }); + + it('sets customer_update when customer and automatic tax are enabled', async function () { + api.configure({ + checkoutSessionSuccessUrl: '/success', + checkoutSessionCancelUrl: '/cancel', + checkoutSetupSessionSuccessUrl: '/setup-success', + checkoutSetupSessionCancelUrl: '/setup-cancel', + secretKey: '', + enableAutomaticTax: true + }); + + await api.createDonationCheckoutSession({ + priceId: 'priceId', + successUrl: '/success', + cancelUrl: '/cancel', + metadata: {}, + customer: {id: mockCustomerId} + }); + + assert.deepEqual(mockStripe.checkout.sessions.create.firstCall.firstArg.customer_update, {address: 'auto', name: 'auto'}); + }); }); describe('createGiftCheckoutSession', function () { @@ -886,7 +907,7 @@ describe('StripeAPI', function () { const args = mockStripe.checkout.sessions.create.firstCall.firstArg; - assert.deepEqual(args.customer_update, {address: 'auto'}); + assert.deepEqual(args.customer_update, {address: 'auto', name: 'auto'}); }); it('does not set customer_update without customer', async function () {