diff --git a/packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts b/packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts index f4e8fc7511..bb930983eb 100644 --- a/packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts +++ b/packages/payments-plugin/e2e/mollie-payment.e2e-spec.ts @@ -539,6 +539,11 @@ describe('Mollie payments', () => { expect(orderPlacedEvent?.ctx.languageCode).toBe('nl'); }); + it('Resulting events should have a ctx.req ', () => { + // We've set the languageCode to 'nl' in the mock response's metadata + expect(orderPlacedEvent?.ctx?.req).toBeDefined(); + }); + it('Should have Mollie metadata on payment', async () => { const { order: { payments }, diff --git a/packages/payments-plugin/src/mollie/mollie.controller.ts b/packages/payments-plugin/src/mollie/mollie.controller.ts index be41ca78c5..2c023b53e2 100644 --- a/packages/payments-plugin/src/mollie/mollie.controller.ts +++ b/packages/payments-plugin/src/mollie/mollie.controller.ts @@ -1,12 +1,16 @@ -import { Body, Controller, Param, Post } from '@nestjs/common'; +import { Body, Controller, Param, Post, Req } from '@nestjs/common'; import { Ctx, Logger, RequestContext, Transaction, ChannelService, LanguageCode } from '@vendure/core'; +import { Request } from 'express'; import { loggerCtx } from './constants'; import { MollieService } from './mollie.service'; @Controller('payments') export class MollieController { - constructor(private mollieService: MollieService, private channelService: ChannelService) {} + constructor( + private mollieService: MollieService, + private channelService: ChannelService, + ) {} @Post('mollie/:channelToken/:paymentMethodId') @Transaction() @@ -14,6 +18,7 @@ export class MollieController { @Param('channelToken') channelToken: string, @Param('paymentMethodId') paymentMethodId: string, @Body() body: any, + @Req() req: Request, ): Promise { if (!body.id) { return Logger.warn(' Ignoring incoming webhook, because it has no body.id.', loggerCtx); @@ -21,7 +26,7 @@ export class MollieController { try { // We need to construct a RequestContext based on the channelToken, // because this is an incoming webhook, not a graphql request with a valid Ctx - const ctx = await this.createContext(channelToken); + const ctx = await this.createContext(channelToken, req); await this.mollieService.handleMollieStatusUpdate(ctx, { paymentMethodId, orderId: body.id, @@ -36,13 +41,14 @@ export class MollieController { } } - private async createContext(channelToken: string): Promise { + private async createContext(channelToken: string, req: Request): Promise { const channel = await this.channelService.getChannelFromToken(channelToken); return new RequestContext({ apiType: 'admin', isAuthorized: true, authorizedAsOwnerOnly: false, channel, + req, languageCode: LanguageCode.en, }); } diff --git a/packages/payments-plugin/src/mollie/mollie.service.ts b/packages/payments-plugin/src/mollie/mollie.service.ts index 8e323578ca..e880554b4a 100644 --- a/packages/payments-plugin/src/mollie/mollie.service.ts +++ b/packages/payments-plugin/src/mollie/mollie.service.ts @@ -282,6 +282,7 @@ export class MollieService { apiType: 'admin', isAuthorized: true, authorizedAsOwnerOnly: false, + req: ctx.req, channel: ctx.channel, languageCode: mollieOrder.metadata.languageCode as LanguageCode, });