فهرست منبع

refactor(server): PaymentHandler implement ConfigurableOperationDef

Michael Bromley 6 سال پیش
والد
کامیت
db1ad71d5a

+ 2 - 2
server/e2e/shop-order.e2e-spec.ts

@@ -698,7 +698,7 @@ describe('Shop orders', () => {
 
 const testPaymentMethod = new PaymentMethodHandler({
     code: 'test-payment-method',
-    name: 'Test Payment Method',
+    description: 'Test Payment Method',
     args: {},
     createPayment: (order, args, metadata) => {
         return {
@@ -712,7 +712,7 @@ const testPaymentMethod = new PaymentMethodHandler({
 
 const testFailingPaymentMethod = new PaymentMethodHandler({
     code: 'test-failing-payment-method',
-    name: 'Test Failing Payment Method',
+    description: 'Test Failing Payment Method',
     args: {},
     createPayment: (order, args, metadata) => {
         return {

+ 1 - 1
server/src/config/payment-method/example-payment-method-config.ts

@@ -23,7 +23,7 @@ const gripeSDK = {
  */
 export const examplePaymentHandler = new PaymentMethodHandler({
     code: 'example-payment-provider',
-    name: 'Example Payment Provider',
+    description: 'Example Payment Provider',
     args: {
         apiKey: ConfigArgType.STRING,
     },

+ 13 - 8
server/src/config/payment-method/payment-method-handler.ts

@@ -1,6 +1,11 @@
 import { ConfigArg, ConfigArgType } from '../../../../shared/generated-types';
 
-import { argsArrayToHash, ConfigArgs, ConfigArgValues } from '../../common/configurable-operation';
+import {
+    argsArrayToHash,
+    ConfigArgs,
+    ConfigArgValues,
+    ConfigurableOperationDef,
+} from '../../common/configurable-operation';
 import { StateMachineConfig } from '../../common/finite-state-machine';
 import { Order } from '../../entity/order/order.entity';
 import { PaymentMetadata } from '../../entity/payment/payment.entity';
@@ -59,9 +64,9 @@ export interface PaymentMethodConfigOptions<T extends PaymentMethodArgs = Paymen
     code: string;
     /**
      * @description
-     * A human-readable name for the payment method.
+     * A human-readable description for the payment method.
      */
-    name: string;
+    description: string;
     /**
      * @description
      * This function provides the actual logic for creating a payment. For example,
@@ -105,7 +110,7 @@ export interface PaymentMethodConfigOptions<T extends PaymentMethodArgs = Paymen
  *
  * export const examplePaymentHandler = new PaymentMethodHandler({
  *     code: 'example-payment-provider',
- *     name: 'Example Payment Provider',
+ *     description: 'Example Payment Provider',
  *     args: {
  *         apiKey: 'string',
  *     },
@@ -134,20 +139,20 @@ export interface PaymentMethodConfigOptions<T extends PaymentMethodArgs = Paymen
  *     },
  * });
  * ```
- * // TODO: Refactor to implement ConfigurableOperationDef interface
  *
  * @docsCategory payment
  */
-export class PaymentMethodHandler<T extends PaymentMethodArgs = PaymentMethodArgs> {
+export class PaymentMethodHandler<T extends PaymentMethodArgs = PaymentMethodArgs>
+    implements ConfigurableOperationDef {
     readonly code: string;
-    readonly name: string;
+    readonly description: string;
     readonly args: T;
     private readonly createPaymentFn: CreatePaymentFn<T>;
     private readonly onTransitionStartFn?: OnTransitionStartFn<T>;
 
     constructor(config: PaymentMethodConfigOptions<T>) {
         this.code = config.code;
-        this.name = config.name;
+        this.description = config.description;
         this.args = config.args;
         this.createPaymentFn = config.createPayment;
         this.onTransitionStartFn = config.onStateTransitionStart;

+ 1 - 5
server/src/service/services/payment-method.service.ts

@@ -55,11 +55,7 @@ export class PaymentMethodService {
                 h => h.code === paymentMethod.code,
             );
             if (handler) {
-                updatedPaymentMethod.configArgs = input.configArgs.map(a => ({
-                    name: a.name,
-                    type: handler.args[a.name],
-                    value: a.value,
-                }));
+                updatedPaymentMethod.configArgs = input.configArgs;
             }
         }
         return this.connection.getRepository(PaymentMethod).save(updatedPaymentMethod);

+ 1 - 7
server/src/service/services/promotion.service.ts

@@ -135,13 +135,7 @@ export class PromotionService {
         const output: ConfigurableOperation = {
             code: input.code,
             description: match.description,
-            args: input.arguments.map((inputArg, i) => {
-                return {
-                    name: inputArg.name,
-                    type: match.args[inputArg.name],
-                    value: inputArg.value,
-                };
-            }),
+            args: input.arguments,
         };
         return output;
     }

+ 1 - 7
server/src/service/services/shipping-method.service.ts

@@ -119,13 +119,7 @@ export class ShippingMethodService {
         const output: ConfigurableOperation = {
             code: input.code,
             description: adjustmentSource.description,
-            args: input.arguments.map((inputArg, i) => {
-                return {
-                    name: inputArg.name,
-                    type: adjustmentSource.args[inputArg.name],
-                    value: inputArg.value,
-                };
-            }),
+            args: input.arguments,
         };
         return output;
     }