Skip to content

Commit 08ab5fe

Browse files
committed
task(subscription): exclude fpn subs from tax enablement
Because: * Do not update FPN subscriptions to Stripe automatic tax. This commit: * Adds isEligibleSubscriptionProduct method to check if the product of a subscription is eligible to update automatic tax. Closes FXA-6811
1 parent ca8e56b commit 08ab5fe

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

packages/fxa-auth-server/scripts/convert-customers-to-stripe-automatic-tax/convert-customers-to-stripe-automatic-tax.ts

+15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class StripeAutomaticTaxConverter {
2323
private ipAddressMap: IpAddressMap;
2424
private helpers: StripeAutomaticTaxConverterHelpers;
2525
private stripeQueue: PQueue;
26+
private ineligibleProducts: string[];
2627

2728
/**
2829
* A converter to update all eligible customers to Stripe automatic tax
@@ -60,6 +61,8 @@ export class StripeAutomaticTaxConverter {
6061
fs.readFileSync(ipAddressMapFile, 'utf-8')
6162
);
6263
this.ipAddressMap = this.helpers.processIPAddressList(ipAddressList);
64+
65+
this.ineligibleProducts = ['prod_HEJ13uxjG4Rj6L', 'prod_HeWOjYtYcEjAzV'];
6366
}
6467

6568
/**
@@ -132,6 +135,9 @@ export class StripeAutomaticTaxConverter {
132135
try {
133136
const product = await this.fetchProduct(plan.product as string);
134137

138+
const isExcludedProduct = this.isExcludedSubscriptionProduct(product.id);
139+
if (isExcludedProduct) return; // Return early if subscription is for excluded product
140+
135141
const customer = await this.fetchCustomer(customerId);
136142
if (!customer) return; // Do not enable tax for an invalid customer
137143

@@ -216,6 +222,15 @@ export class StripeAutomaticTaxConverter {
216222
return isTaxEligible;
217223
}
218224

225+
/**
226+
* Check if the subscriptions product is eligible to enable Tax
227+
* @param productId
228+
* @returns
229+
*/
230+
isExcludedSubscriptionProduct(productId: string) {
231+
return this.ineligibleProducts.includes(productId);
232+
}
233+
219234
/**
220235
* Updates a Stripe subscription with automatic tax enabled
221236
* @param subscriptionId Subscription to enable automatic tax for

packages/fxa-auth-server/test/scripts/convert-customers-to-stripe-automatic-tax.ts

+38
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ describe('StripeAutomaticTaxConverter', () => {
227227
.resolves(mockCustomer);
228228
enableTaxForCustomer = sinon.stub().resolves(true);
229229
stripeAutomaticTaxConverter.enableTaxForCustomer = enableTaxForCustomer;
230+
stripeAutomaticTaxConverter.isExcludedSubscriptionProduct = sinon
231+
.stub()
232+
.returns(false);
230233
enableTaxForSubscription = sinon.stub().resolves();
231234
stripeAutomaticTaxConverter.enableTaxForSubscription =
232235
enableTaxForSubscription;
@@ -291,6 +294,19 @@ describe('StripeAutomaticTaxConverter', () => {
291294
expect(enableTaxForSubscription.notCalled).true;
292295
expect(logStub.notCalled).true;
293296
});
297+
298+
it('does not update subscription for ineligible product', async () => {
299+
stripeAutomaticTaxConverter.isExcludedSubscriptionProduct = sinon
300+
.stub()
301+
.returns(true);
302+
await stripeAutomaticTaxConverter.generateReportForSubscription(
303+
mockFirestoreSub
304+
);
305+
306+
expect(enableTaxForCustomer.notCalled).true;
307+
expect(enableTaxForSubscription.notCalled).true;
308+
expect(logStub.notCalled).true;
309+
});
294310
});
295311
});
296312

@@ -436,6 +452,28 @@ describe('StripeAutomaticTaxConverter', () => {
436452
});
437453
});
438454

455+
describe('isEligibleSubscriptionProduct', () => {
456+
let result: boolean;
457+
const VALID_PRODUCT = 'valid';
458+
const EXCLUDED_PRODUCT = 'prod_HEJ13uxjG4Rj6L';
459+
460+
it('returns false if the product is not excluded', () => {
461+
result =
462+
stripeAutomaticTaxConverter.isExcludedSubscriptionProduct(
463+
VALID_PRODUCT
464+
);
465+
expect(result).false;
466+
});
467+
468+
it('returns true if the product is meant to be excluded', () => {
469+
result =
470+
stripeAutomaticTaxConverter.isExcludedSubscriptionProduct(
471+
EXCLUDED_PRODUCT
472+
);
473+
expect(result).true;
474+
});
475+
});
476+
439477
describe('enableTaxForSubscription', () => {
440478
let updateStub: sinon.SinonStub;
441479
let retrieveStub: sinon.SinonStub;

0 commit comments

Comments
 (0)