stripe - test - check behaviour on payment failure
MODIFY
test/api/BillingStripeIntegrationTest.ts
test/api/BillingStripeIntegrationTest.ts
@@ -37,12 +37,16 @@ describe('Billing Stripe Service', function() {
// Anyway, there is no way to cleanup the utbilling stripe account!
});
+ it('should create a DRAFT invoice and fail to pay', async () => {
+ await testData.checkBusinessProcessBillToPay(true);
+ });
+
it('Should add a payment method to BILLING-TEST user', async () => {
await testData.assignPaymentMethod('tok_visa');
});
- it('should create and pay a first invoice for BILLING-TEST user', async () => {
- await testData.checkBusinessProcessBillToPay();
+ it('should create a DRAFT invoice and pay it for BILLING-TEST user', async () => {
+ await testData.checkBusinessProcessBillToPay(false, true);
});
it('Should download invoice as PDF', async () => {

MODIFY
test/api/BillingStripeTestData.ts
test/api/BillingStripeTestData.ts
@@ -156,7 +156,7 @@ export default class StripeIntegrationTestData {
return taxRate;
}
- public async checkBusinessProcessBillToPay(withTax?:boolean) : Promise<number> {
+ public async checkBusinessProcessBillToPay(paymentShouldFail: boolean, withTax?:boolean) : Promise<number> {
let taxId: string = null;
if (withTax) {
@@ -176,7 +176,7 @@ export default class StripeIntegrationTestData {
assert(draftInvoices, 'User should have at least a draft invoice');
expect(draftInvoices.length).to.be.eql(1);
// Let's pay that particular DRAFT invoice
- await this.payDraftInvoice(draftInvoices[0]);
+ await this.payDraftInvoice(draftInvoices[0], paymentShouldFail);
// Next step should not be necessary
// await testData.billingImpl.synchronizeInvoices(testData.dynamicUser);
// Let's check that the user do not have any DRAFT invoice anymore
@@ -236,13 +236,20 @@ export default class StripeIntegrationTestData {
return billingInvoice;
}
- public async payDraftInvoice(draftInvoice: { id: string }): Promise<void> {
+ public async payDraftInvoice(draftInvoice: { id: string }, paymentShouldFail: boolean): Promise<void> {
const draftInvoiceId = draftInvoice.id;
let billingInvoice: BillingInvoice = await BillingStorage.getInvoice(this.getTenantID(), draftInvoiceId);
// Let's attempt a payment using the default payment method
billingInvoice = await this.billingImpl.chargeInvoice(billingInvoice);
+ if (paymentShouldFail) {
+ assert(billingInvoice.status === BillingInvoiceStatus.OPEN, 'Invoice should have been be finalized but not yet paid');
+ // TODO - retrieve and check the last payment error and the corresponding error code
+ // billingInvoice = await BillingStorage.getInvoice(draftInvoiceId);
+ // assert(billingInvoice.lastPaymentFailure.error.error_code === "missing"!!!!
+ } else {
assert(billingInvoice.status === BillingInvoiceStatus.PAID, 'Invoice should have been paid');
}
+ }
public getTenantID(): string {
const tenantId = this.tenantContext?.getTenant()?.id;

stripe - test - check behaviour on payment failure