Browse Source

feat(payments-plugin): Unstaged files

Martijn 1 year ago
parent
commit
1ef282a7ad

+ 85 - 0
packages/payments-plugin/src/mollie/api-extensions.ts

@@ -0,0 +1,85 @@
+import { gql } from 'graphql-tag';
+
+const commonSchemaExtensions = gql`
+
+    input MolliePaymentIntentInput {
+        """
+        The code of the Vendure payment method to use for the payment.
+        Must have Mollie as payment method handler.
+        Without this, the first method with Mollie as handler will be used.
+        """
+        paymentMethodCode: String
+        """
+        The redirect url to which the customer will be redirected after the payment is completed.
+        The configured fallback redirect will be used if this is not provided.
+        """
+        redirectUrl: String
+        """
+        Optional preselected Mollie payment method. When this is passed
+        the payment selection step will be skipped.
+        """
+        molliePaymentMethodCode: String
+        """
+        Use this to create a payment intent for a specific order. This allows you to create intents for
+        orders that are not active orders.
+        """
+        orderId: String
+    }
+
+    type MolliePaymentIntent {
+        url: String!
+    }
+
+    type MolliePaymentIntentError implements ErrorResult {
+        errorCode: ErrorCode!
+        message: String!
+    }
+
+    union MolliePaymentIntentResult = MolliePaymentIntent | MolliePaymentIntentError
+
+    extend type Mutation {
+        createMolliePaymentIntent(input: MolliePaymentIntentInput!): MolliePaymentIntentResult!
+    }
+
+`;
+
+export const shopApiExtensions = gql`
+
+   ${commonSchemaExtensions}
+
+    type MollieAmount {
+        value: String
+        currency: String
+    }
+    type MolliePaymentMethodImages {
+        size1x: String
+        size2x: String
+        svg: String
+    }
+    type MolliePaymentMethod {
+        id: ID!
+        code: String!
+        description: String
+        minimumAmount: MollieAmount
+        maximumAmount: MollieAmount
+        image: MolliePaymentMethodImages
+        status: String
+    }
+
+    input MolliePaymentMethodsInput {
+        paymentMethodCode: String!
+    }
+
+    extend type Query {
+        molliePaymentMethods(input: MolliePaymentMethodsInput!): [MolliePaymentMethod!]!
+    }
+`;
+
+export const adminApiExtensions = gql`
+    
+        ${commonSchemaExtensions}
+
+        extend enum ErrorCode {
+            ORDER_PAYMENT_STATE_ERROR
+        }
+`;

+ 34 - 0
packages/payments-plugin/src/mollie/mollie.common-resolver.ts

@@ -0,0 +1,34 @@
+import { Args, Mutation, ResolveField, Resolver } from '@nestjs/graphql';
+import { Allow, Ctx, Permission, RequestContext } from '@vendure/core';
+
+import {
+    MolliePaymentIntent,
+    MolliePaymentIntentError,
+    MolliePaymentIntentInput,
+    MolliePaymentIntentResult
+} from './graphql/generated-shop-types';
+import { MollieService } from './mollie.service';
+
+@Resolver()
+export class MollieCommonResolver {
+    constructor(private mollieService: MollieService) {}
+
+    @Mutation()
+    @Allow(Permission.Owner)
+    async createMolliePaymentIntent(
+        @Ctx() ctx: RequestContext,
+        @Args('input') input: MolliePaymentIntentInput,
+    ): Promise<MolliePaymentIntentResult> {
+        return this.mollieService.createPaymentIntent(ctx, input);
+    }
+
+    @ResolveField()
+    @Resolver('MolliePaymentIntentResult')
+    __resolveType(value: MolliePaymentIntentError | MolliePaymentIntent): string {
+        if ((value as MolliePaymentIntentError).errorCode) {
+            return 'MolliePaymentIntentError';
+        } else {
+            return 'MolliePaymentIntent';
+        }
+    }
+}

+ 22 - 0
packages/payments-plugin/src/mollie/mollie.shop-resolver.ts

@@ -0,0 +1,22 @@
+import { Args, Query, Resolver } from '@nestjs/graphql';
+import { Allow, Ctx, Permission, RequestContext } from '@vendure/core';
+
+import {
+    MolliePaymentMethod,
+    MolliePaymentMethodsInput
+} from './graphql/generated-shop-types';
+import { MollieService } from './mollie.service';
+
+@Resolver()
+export class MollieShopResolver {
+    constructor(private mollieService: MollieService) {}
+
+    @Query()
+    @Allow(Permission.Public)
+    async molliePaymentMethods(
+        @Ctx() ctx: RequestContext,
+        @Args('input') { paymentMethodCode }: MolliePaymentMethodsInput,
+    ): Promise<MolliePaymentMethod[]> {
+        return this.mollieService.getEnabledPaymentMethods(ctx, paymentMethodCode);
+    }
+}

+ 19 - 0
packages/payments-plugin/src/mollie/ui/providers.ts

@@ -0,0 +1,19 @@
+import { addActionBarDropdownMenuItem } from '@vendure/admin-ui/core';
+
+export default [
+    addActionBarDropdownMenuItem({
+        id: 'print-invoice',
+        locationId: 'order-detail',
+        label: 'Get Payment Link',
+        icon: 'euro',
+        buttonState: context => {
+            return context.entity$.pipe(
+                map((order) => {
+                    return (order?.state === 'ArrangingPayment' ?? order?.state === 'AddingItems')
+                        ? { disabled: false, visible: true }
+                        : { disabled: true, visible: true };
+                }),
+            );
+        },
+    }),
+];