Browse Source

fix(core): Make addPaymentToOrder channel aware

Fixes #773
Martijn 4 years ago
parent
commit
63382124f4
1 changed files with 7 additions and 6 deletions
  1. 7 6
      packages/core/src/service/services/payment-method.service.ts

+ 7 - 6
packages/core/src/service/services/payment-method.service.ts

@@ -134,12 +134,13 @@ export class PaymentMethodService {
         handler: PaymentMethodHandler;
         checker: PaymentMethodEligibilityChecker | null;
     }> {
-        const paymentMethod = await this.connection.getRepository(ctx, PaymentMethod).findOne({
-            where: {
-                code: method,
-                enabled: true,
-            },
-        });
+        const paymentMethod = await this.connection
+            .getRepository(ctx, PaymentMethod)
+            .createQueryBuilder('method')
+            .leftJoin('method.channels', 'channel')
+            .where('method.code = :code', { code: method })
+            .andWhere('channel.id = :channelId', { channelId: ctx.channelId })
+            .getOne();
         if (!paymentMethod) {
             throw new UserInputError(`error.payment-method-not-found`, { method });
         }