stripe - test invoice billing item with taxes
MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -39,13 +39,13 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
return this.stripe;
}
- public alterStripeSettings(someSettings: Partial<StripeBillingSetting>): void {
- // TODO - To be removed - only used by automated tests!
- this.settings = {
- ...this.settings,
- ...someSettings // overrides default settings to test different scenarios - e.g.: VAT 20%
- };
- }
+ // public alterStripeSettings(someSettings: Partial<StripeBillingSetting>): void {
+ // // TODO - To be removed - only used by automated tests!
+ // this.settings = {
+ // ...this.settings,
+ // ...someSettings // overrides default settings to test different scenarios - e.g.: VAT 20%
+ // };
+ // }
public async checkConnection(): Promise<void> {
// Initialize Stripe

MODIFY
test/api/BillingStripeIntegrationTest.ts
test/api/BillingStripeIntegrationTest.ts
@@ -37,20 +37,20 @@ describe('Billing Stripe Service', function() {
});
it('should create and pay a first invoice for BILLING-TEST user', async () => {
- void testData.checkBusinessProcessBillToPay();
+ await testData.checkBusinessProcessBillToPay();
});
it('Should add a different payment method to BILLING-TEST user', async () => {
await testData.assignPaymentMethod('tok_fr');
});
- it('Should set VAT tax rate to 20% (non inclusive)', async () => {
- await testData.assignTaxRate(20);
- });
+ // 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);
- void testData.checkBusinessProcessBillToPay();
+ await testData.checkBusinessProcessBillToPay(true);
});
});

MODIFY
test/api/BillingStripeTestData.ts
test/api/BillingStripeTestData.ts
@@ -156,20 +156,26 @@ export default class StripeIntegrationTestData {
inclusive: false
});
expect(taxRate).to.not.be.null;
- concreteImplementation.alterStripeSettings({
- taxID: taxRate?.id, // Default tax to apply when charging invoices
- // immediateBillingAllowed: true // Activate immediate billing
- });
+ // concreteImplementation.alterStripeSettings({
+ // taxID: taxRate?.id, // Default tax to apply when charging invoices
+ // // immediateBillingAllowed: true // Activate immediate billing
+ // });
return taxRate;
}
- public async checkBusinessProcessBillToPay() : Promise<number> {
+ public async checkBusinessProcessBillToPay(withTax?:boolean) : Promise<number> {
+
+ let taxId: string = null;
+ if (withTax) {
+ const taxRate: Stripe.TaxRate = await this.assignTaxRate(20); // VAT 20%
+ taxId = taxRate.id;
+ }
await this.checkForDraftInvoices(this.dynamicUser.id, 0);
// Let's create an Invoice with a first Item
- const dynamicInvoice = await this.billInvoiceItem(777);
+ const dynamicInvoice = await this.billInvoiceItem(777, taxId);
assert(dynamicInvoice, 'Invoice should not be null');
// Let's add an second item to the same invoice
- const updatedInvoice = await this.billInvoiceItem(555);
+ const updatedInvoice = await this.billInvoiceItem(555, taxId);
assert(updatedInvoice, 'Invoice should not be null');
// User should have a DRAFT invoice
const draftInvoices = await this.getDraftInvoices(this.dynamicUser.id);
@@ -184,10 +190,10 @@ export default class StripeIntegrationTestData {
return nbDraftInvoice;
}
- public async billInvoiceItem(price: number) : Promise<BillingInvoice> {
-
+ public async billInvoiceItem(price: number, taxId?: string) : Promise<BillingInvoice> {
assert(this.billingUser, 'Billing user cannot be null');
- const invoiceItem = {
+ // array of tax ids to apply to the line item
+ const invoiceItem:BillingInvoiceItem = {
description: `Stripe Integration - Item ${price}`,
pricingData: {
amount: price,
@@ -195,7 +201,10 @@ export default class StripeIntegrationTestData {
price: price
}
};
-
+ if (taxId) {
+ invoiceItem.taxes = [ taxId ];
+ }
+ // Let's attempt to bill the line item
const billingInvoice: BillingInvoice = await this.billingImpl.billInvoiceItems(this.dynamicUser, [ invoiceItem ]);
assert(billingInvoice, 'Billing invoice should not be null');
return billingInvoice;

stripe - test invoice billing item with taxes