From 8db459a84338331d829a4750ebc14351574bf5fe Mon Sep 17 00:00:00 2001 From: Martijn Date: Thu, 12 Oct 2023 14:37:16 +0200 Subject: [PATCH] fix(payments-plugin): Fix Mollie klarna AutoCapture (#2446) --- packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts | 7 ++++--- packages/payments-plugin/src/mollie/mollie.service.ts | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts b/packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts index 0cab90543a..87c6bced31 100644 --- a/packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts +++ b/packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts @@ -381,8 +381,7 @@ describe('Mollie payments (with useDynamicRedirectUrl set to true)', () => { body: JSON.stringify({ id: mockData.mollieOrderResponse.id }), headers: { 'Content-Type': 'application/json' }, }); - // tslint:disable-next-line:no-non-null-assertion - const { order: adminOrder } = await adminClient.query(GET_ORDER_PAYMENTS, { id: order!.id }); + const { order: adminOrder } = await adminClient.query(GET_ORDER_PAYMENTS, { id: order?.id }); expect(adminOrder.state).toBe('ArrangingPayment'); }); @@ -457,7 +456,7 @@ describe('Mollie payments (with useDynamicRedirectUrl set to true)', () => { adminClient, order.lines[0].id, 10, - // tslint:disable-next-line:no-non-null-assertion + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion order.payments!.find(p => p.amount === 108990)!.id, SURCHARGE_AMOUNT, ); @@ -468,6 +467,8 @@ describe('Mollie payments (with useDynamicRedirectUrl set to true)', () => { }); describe('Handle pay-later methods', () => { + // TODO: Add testcases that mock incoming webhook to: 1. Authorize payment and 2. AutoCapture payments + it('Should prepare a new order', async () => { await shopClient.asUserWithCredentials(customers[0].emailAddress, 'test'); const { addItemToOrder } = await shopClient.query< diff --git a/packages/payments-plugin/src/mollie/mollie.service.ts b/packages/payments-plugin/src/mollie/mollie.service.ts index e48b7e2051..27e1f90498 100644 --- a/packages/payments-plugin/src/mollie/mollie.service.ts +++ b/packages/payments-plugin/src/mollie/mollie.service.ts @@ -308,6 +308,7 @@ export class MollieService { * Settle an existing payment based on the given mollieOrder */ async settleExistingPayment(ctx: RequestContext, order: Order, mollieOrderId: string): Promise { + order = await this.entityHydrator.hydrate(ctx, order, { relations: ['payments'] }); const payment = order.payments.find(p => p.transactionId === mollieOrderId); if (!payment) { throw Error( @@ -335,7 +336,7 @@ export class MollieService { } const client = createMollieClient({ apiKey }); // We use the orders API, so list available methods for that API usage - const methods = await client.methods.list({resource: 'orders'}); + const methods = await client.methods.list({ resource: 'orders' }); return methods.map(m => ({ ...m, code: m.id,