Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ghost/core/core/server/services/stripe/stripe-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 23 additions & 2 deletions ghost/core/test/unit/server/services/stripe/stripe-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down
Loading