|
|
@@ -1,17 +1,16 @@
|
|
|
import { Body, Controller, Param, Post } from '@nestjs/common';
|
|
|
-import { Ctx, Logger, RequestContext, Transaction } from '@vendure/core';
|
|
|
+import { Ctx, Logger, RequestContext, Transaction, ChannelService, LanguageCode } from '@vendure/core';
|
|
|
|
|
|
import { loggerCtx } from './constants';
|
|
|
import { MollieService } from './mollie.service';
|
|
|
|
|
|
@Controller('payments')
|
|
|
export class MollieController {
|
|
|
- constructor(private mollieService: MollieService) {}
|
|
|
+ constructor(private mollieService: MollieService, private channelService: ChannelService) {}
|
|
|
|
|
|
@Post('mollie/:channelToken/:paymentMethodId')
|
|
|
@Transaction()
|
|
|
async webhook(
|
|
|
- @Ctx() ctx: RequestContext,
|
|
|
@Param('channelToken') channelToken: string,
|
|
|
@Param('paymentMethodId') paymentMethodId: string,
|
|
|
@Body() body: any,
|
|
|
@@ -20,8 +19,10 @@ export class MollieController {
|
|
|
return Logger.warn(' Ignoring incoming webhook, because it has no body.id.', loggerCtx);
|
|
|
}
|
|
|
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);
|
|
|
await this.mollieService.handleMollieStatusUpdate(ctx, {
|
|
|
- channelToken,
|
|
|
paymentMethodId,
|
|
|
orderId: body.id,
|
|
|
});
|
|
|
@@ -34,4 +35,15 @@ export class MollieController {
|
|
|
throw error;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private async createContext(channelToken: string): Promise<RequestContext> {
|
|
|
+ const channel = await this.channelService.getChannelFromToken(channelToken);
|
|
|
+ return new RequestContext({
|
|
|
+ apiType: 'admin',
|
|
|
+ isAuthorized: true,
|
|
|
+ authorizedAsOwnerOnly: false,
|
|
|
+ channel,
|
|
|
+ languageCode: LanguageCode.en,
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|