Jelajahi Sumber

chore: Tidy up after merge

Michael Bromley 3 tahun lalu
induk
melakukan
a017936b05

+ 1 - 1
packages/core/src/service/services/collection.service.ts

@@ -130,7 +130,7 @@ export class CollectionService implements OnModuleInit {
                                 collection,
                                 job.data.applyToChangedVariantsOnly,
                             );
-                        } catch (e) {
+                        } catch (e: any) {
                             const translatedCollection = await this.translator.translate(collection, ctx);
                             Logger.error(
                                 `An error occurred when processing the filters for the collection "${translatedCollection.name}" (id: ${collection.id})`,

+ 34 - 0
packages/payments-plugin/src/mollie/graphql/generated-shop-types.ts

@@ -1550,6 +1550,12 @@ export type MissingPasswordError = ErrorResult & {
   message: Scalars['String'];
 };
 
+export type MollieAmount = {
+  __typename?: 'MollieAmount';
+  currency?: Maybe<Scalars['String']>;
+  value?: Maybe<Scalars['String']>;
+};
+
 export type MolliePaymentIntent = {
   __typename?: 'MolliePaymentIntent';
   url: Scalars['String'];
@@ -1562,11 +1568,33 @@ export type MolliePaymentIntentError = ErrorResult & {
 };
 
 export type MolliePaymentIntentInput = {
+  molliePaymentMethodCode?: InputMaybe<Scalars['String']>;
   paymentMethodCode: Scalars['String'];
 };
 
 export type MolliePaymentIntentResult = MolliePaymentIntent | MolliePaymentIntentError;
 
+export type MolliePaymentMethod = {
+  __typename?: 'MolliePaymentMethod';
+  code: Scalars['String'];
+  description?: Maybe<Scalars['String']>;
+  id: Scalars['ID'];
+  image?: Maybe<MolliePaymentMethodImages>;
+  maximumAmount?: Maybe<MollieAmount>;
+  minimumAmount?: Maybe<MollieAmount>;
+};
+
+export type MolliePaymentMethodImages = {
+  __typename?: 'MolliePaymentMethodImages';
+  size1x?: Maybe<Scalars['String']>;
+  size2x?: Maybe<Scalars['String']>;
+  svg?: Maybe<Scalars['String']>;
+};
+
+export type MolliePaymentMethodsInput = {
+  paymentMethodCode: Scalars['String'];
+};
+
 export type Mutation = {
   __typename?: 'Mutation';
   /** Adds an item to the order. If custom fields are defined on the OrderLine entity, a third argument 'customFields' will be available. */
@@ -2710,6 +2738,7 @@ export type Query = {
   facets: FacetList;
   /** Returns information about the current authenticated User */
   me?: Maybe<CurrentUser>;
+  molliePaymentMethods: Array<MolliePaymentMethod>;
   /** Returns the possible next states that the activeOrder can transition to */
   nextOrderStates: Array<Scalars['String']>;
   /**
@@ -2754,6 +2783,11 @@ export type QueryFacetsArgs = {
 };
 
 
+export type QueryMolliePaymentMethodsArgs = {
+  input: MolliePaymentMethodsInput;
+};
+
+
 export type QueryOrderArgs = {
   id: Scalars['ID'];
 };

+ 6 - 3
packages/payments-plugin/src/mollie/mollie.resolver.ts

@@ -3,8 +3,11 @@ import { Allow, Ctx, Permission, RequestContext } from '@vendure/core';
 
 import {
     MolliePaymentIntent,
-    MolliePaymentIntentError, MolliePaymentIntentInput,
-    MolliePaymentIntentResult, MolliePaymentMethod, MolliePaymentMethodsInput,
+    MolliePaymentIntentError,
+    MolliePaymentIntentInput,
+    MolliePaymentIntentResult,
+    MolliePaymentMethod,
+    MolliePaymentMethodsInput,
 } from './graphql/generated-shop-types';
 import { MollieService } from './mollie.service';
 
@@ -35,7 +38,7 @@ export class MollieResolver {
     @Allow(Permission.Public)
     async molliePaymentMethods(
         @Ctx() ctx: RequestContext,
-        @Args('input') { paymentMethodCode }: MolliePaymentMethodsInput
+        @Args('input') { paymentMethodCode }: MolliePaymentMethodsInput,
     ): Promise<MolliePaymentMethod[]> {
         return this.mollieService.getEnabledPaymentMethods(ctx, paymentMethodCode);
     }

+ 20 - 12
packages/payments-plugin/src/mollie/mollie.service.ts

@@ -1,4 +1,6 @@
 import createMollieClient, { PaymentStatus } from '@mollie/api-client';
+import { PaymentMethod as MollieClientMethod } from '@mollie/api-client';
+import { CreateParameters } from '@mollie/api-client/dist/types/src/binders/payments/parameters';
 import { Inject, Injectable } from '@nestjs/common';
 import {
     ActiveOrderService,
@@ -8,11 +10,11 @@ import {
     Logger,
     Order,
     OrderService,
+    OrderStateTransitionError,
     PaymentMethod,
     PaymentMethodService,
     RequestContext,
 } from '@vendure/core';
-import { OrderStateTransitionError } from '@vendure/core/dist/common/error/generated-graphql-shop-errors';
 
 import { loggerCtx, PLUGIN_INIT_OPTIONS } from './constants';
 import {
@@ -23,8 +25,6 @@ import {
     MolliePaymentMethod,
 } from './graphql/generated-shop-types';
 import { MolliePluginOptions } from './mollie.plugin';
-import { CreateParameters } from '@mollie/api-client/dist/types/src/binders/payments/parameters';
-import { PaymentMethod as MollieClientMethod } from '@mollie/api-client';
 
 interface SettlePaymentInput {
     channelToken: string;
@@ -35,20 +35,17 @@ interface SettlePaymentInput {
 class PaymentIntentError implements MolliePaymentIntentError {
     errorCode = ErrorCode.ORDER_PAYMENT_STATE_ERROR;
 
-    constructor(public message: string) {
-    }
+    constructor(public message: string) {}
 }
 
 class InvalidInput implements MolliePaymentIntentError {
     errorCode = ErrorCode.INELIGIBLE_PAYMENT_METHOD_ERROR;
 
-    constructor(public message: string) {
-    }
+    constructor(public message: string) {}
 }
 
 @Injectable()
 export class MollieService {
-
     constructor(
         private paymentMethodService: PaymentMethodService,
         @Inject(PLUGIN_INIT_OPTIONS) private options: MolliePluginOptions,
@@ -92,8 +89,13 @@ export class MollieService {
         const apiKey = paymentMethod.handler.args.find(arg => arg.name === 'apiKey')?.value;
         let redirectUrl = paymentMethod.handler.args.find(arg => arg.name === 'redirectUrl')?.value;
         if (!apiKey || !redirectUrl) {
-            Logger.warn(`CreatePaymentIntent failed, because no apiKey or redirect is configured for ${paymentMethod.code}`, loggerCtx);
-            return new PaymentIntentError(`Paymentmethod ${paymentMethod.code} has no apiKey or redirectUrl configured`);
+            Logger.warn(
+                `CreatePaymentIntent failed, because no apiKey or redirect is configured for ${paymentMethod.code}`,
+                loggerCtx,
+            );
+            return new PaymentIntentError(
+                `Paymentmethod ${paymentMethod.code} has no apiKey or redirectUrl configured`,
+            );
         }
         const mollieClient = createMollieClient({ apiKey });
         redirectUrl = redirectUrl.endsWith('/') ? redirectUrl.slice(0, -1) : redirectUrl; // remove appending slash
@@ -193,7 +195,10 @@ export class MollieService {
         Logger.info(`Payment for order ${molliePayment.metadata.orderCode} settled`, loggerCtx);
     }
 
-    async getEnabledPaymentMethods(ctx: RequestContext, paymentMethodCode: string): Promise<MolliePaymentMethod[]> {
+    async getEnabledPaymentMethods(
+        ctx: RequestContext,
+        paymentMethodCode: string,
+    ): Promise<MolliePaymentMethod[]> {
         const paymentMethod = await this.getPaymentMethod(ctx, paymentMethodCode);
         const apiKey = paymentMethod?.handler.args.find(arg => arg.name === 'apiKey')?.value;
         if (!apiKey) {
@@ -207,7 +212,10 @@ export class MollieService {
         }));
     }
 
-    private async getPaymentMethod(ctx: RequestContext, paymentMethodCode: string): Promise<PaymentMethod | undefined> {
+    private async getPaymentMethod(
+        ctx: RequestContext,
+        paymentMethodCode: string,
+    ): Promise<PaymentMethod | undefined> {
         const paymentMethods = await this.paymentMethodService.findAll(ctx);
         return paymentMethods.items.find(pm => pm.code === paymentMethodCode);
     }