stripe - billing settings - taxID now taken into account
MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -34,11 +34,19 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
}
public async getStripeInstance(): Promise<Stripe> {
- // TODO - To be clarified - only used by automated tests!!! - remove it ASAP
+ // TODO - To be removed - only used by automated tests!
await this.checkConnection();
return this.stripe;
}
+ public alterStripeSettings(someSettings: Partial<StripeBillingSetting>): void {
+ // TODO - To be removed - only used by automated tests!
+ this.settings = {
+ ...this.settings,
+ ...someSettings // overrides defult settings to test different scenarios - e.g.: VAT 20%
+ };
+ }
+
public async checkConnection(): Promise<void> {
// Initialize Stripe
if (!this.stripe) {
@@ -405,6 +413,9 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
private getTaxRateIds(): Array<string> {
// TODO - just a hack for now - tax rate should be part of the billing settings
// return [ 'txr_1IP3FJKHtGlSi68frTdAro48' ];
+ if (this.settings.taxID) {
+ return [this.settings.taxID] ;
+ }
return []; // No tax rates so far!
}

MODIFY
test/api/BillingStripeIntegrationTest.ts
test/api/BillingStripeIntegrationTest.ts
@@ -59,6 +59,10 @@ describe('Billing Stripe Service', function() {
await testData.assignPaymentMethod('tok_fr');
});
+ it('Should set VAT tax rate to 20% (non inclusive)', async () => {
+ await testData.assignTaxRate(20);
+ });
+
it('should create and pay a second invoice for BILLING-TEST user', async () => {
await testData.checkForDraftInvoices(testData.dynamicUser.id, 0);
// Let's create an Invoice with a first Item

MODIFY
test/api/BillingStripeTestData.ts
test/api/BillingStripeTestData.ts
@@ -140,6 +140,25 @@ export default class StripeIntegrationTestData {
return source;
}
+ public async assignTaxRate(rate: number) : Promise<Stripe.TaxRate> {
+ // Let's create a tax rate
+ const concreteImplementation : StripeBillingIntegration = this.billingImpl ;
+ const stripeInstance = await concreteImplementation.getStripeInstance();
+ const taxRate = await stripeInstance.taxRates.create({
+ display_name: 'TVA',
+ description: `TVA France - ${rate}%`,
+ jurisdiction: 'FR',
+ percentage: rate,
+ inclusive: false
+ });
+ expect(taxRate).to.not.be.null;
+ // Make it the default tax to apply when charging invoices
+ concreteImplementation.alterStripeSettings({
+ taxID: taxRate?.id
+ });
+ return taxRate;
+ }
+
public async createDraftInvoice() : Promise<BillingInvoice> {
assert(this.billingUser, 'Billing user cannot be null');
const item = { description: 'Stripe Integration - Item 777', amount: 777 };

stripe - billing settings - taxID now taken into account