-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(payments-plugin): Unstaged files
- Loading branch information
1 parent
af80f26
commit 1ef282a
Showing
4 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
packages/payments-plugin/src/mollie/mollie.common-resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
packages/payments-plugin/src/mollie/mollie.shop-resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
}), | ||
); | ||
}, | ||
}), | ||
]; |