Skip to content

Commit

Permalink
feat(payments-plugin): Unstaged files
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnvdbrug committed Feb 27, 2024
1 parent af80f26 commit 1ef282a
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 0 deletions.
85 changes: 85 additions & 0 deletions packages/payments-plugin/src/mollie/api-extensions.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 34 additions & 0 deletions packages/payments-plugin/src/mollie/mollie.common-resolver.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 22 additions & 0 deletions packages/payments-plugin/src/mollie/mollie.shop-resolver.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 0 deletions packages/payments-plugin/src/mollie/ui/providers.ts
Original file line number Diff line number Diff line change
@@ -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 };
}),
);
},
}),
];

0 comments on commit 1ef282a

Please sign in to comment.