|
|
@@ -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<void> {
|
|
|
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<RequestContext> {
|
|
|
+ private async createContext(channelToken: string, req: Request): Promise<RequestContext> {
|
|
|
const channel = await this.channelService.getChannelFromToken(channelToken);
|
|
|
return new RequestContext({
|
|
|
apiType: 'admin',
|
|
|
isAuthorized: true,
|
|
|
authorizedAsOwnerOnly: false,
|
|
|
channel,
|
|
|
+ req,
|
|
|
languageCode: LanguageCode.en,
|
|
|
});
|
|
|
}
|