Skip to content

Commit

Permalink
feat(payments-plugin): Make Mollie plugin redirecturl dynamic (#2094)
Browse files Browse the repository at this point in the history
Closes #2093
  • Loading branch information
seminarian authored Apr 24, 2023
1 parent bf2b1f5 commit b452419
Show file tree
Hide file tree
Showing 10 changed files with 401 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ export type AlreadyRefundedError = ErrorResult & {
export type ApplyCouponCodeResult = Order | CouponCodeExpiredError | CouponCodeInvalidError | CouponCodeLimitError;

export type Asset = Node & {
tags: Array<Tag>;
id: Scalars['ID'];
createdAt: Scalars['DateTime'];
updatedAt: Scalars['DateTime'];
Expand All @@ -175,6 +174,7 @@ export type Asset = Node & {
source: Scalars['String'];
preview: Scalars['String'];
focalPoint?: Maybe<Coordinate>;
tags: Array<Tag>;
customFields?: Maybe<Scalars['JSON']>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export type Asset = Node & {
source: Scalars['String'];
preview: Scalars['String'];
focalPoint?: Maybe<Coordinate>;
tags: Array<Tag>;
customFields?: Maybe<Scalars['JSON']>;
};

Expand Down
46 changes: 27 additions & 19 deletions packages/payments-plugin/e2e/mollie-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import { CREATE_MOLLIE_PAYMENT_INTENT, setShipping } from './payment-helpers';
* This should only be used to locally test the Mollie payment plugin
*/
/* tslint:disable:no-floating-promises */
(async () => {
async function runMollieDevServer(useDynamicRedirectUrl: boolean) {
console.log('Starting Mollie dev server with dynamic redirectUrl: ', useDynamicRedirectUrl);
require('dotenv').config();

registerInitializer('sqljs', new SqljsInitializer(path.join(__dirname, '__data__')));
Expand All @@ -42,7 +43,7 @@ import { CREATE_MOLLIE_PAYMENT_INTENT, setShipping } from './payment-helpers';
route: 'admin',
port: 5001,
}),
MolliePlugin.init({ vendureHost: tunnel.url }),
MolliePlugin.init({ vendureHost: tunnel.url, useDynamicRedirectUrl }),
],
logger: new DefaultLogger({ level: LogLevel.Debug }),
apiOptions: {
Expand All @@ -66,24 +67,26 @@ import { CREATE_MOLLIE_PAYMENT_INTENT, setShipping } from './payment-helpers';
}
`);
// Create method
await adminClient.query<CreatePaymentMethod.Mutation,
CreatePaymentMethod.Variables>(CREATE_PAYMENT_METHOD, {
input: {
code: 'mollie',
name: 'Mollie payment test',
description: 'This is a Mollie test payment method',
enabled: true,
handler: {
code: molliePaymentHandler.code,
arguments: [
{ name: 'redirectUrl', value: `${tunnel.url}/admin/orders?filter=open&page=1` },
// tslint:disable-next-line:no-non-null-assertion
{ name: 'apiKey', value: process.env.MOLLIE_APIKEY! },
{ name: 'autoCapture', value: 'false' },
],
await adminClient.query<CreatePaymentMethod.Mutation, CreatePaymentMethod.Variables>(
CREATE_PAYMENT_METHOD,
{
input: {
code: 'mollie',
name: 'Mollie payment test',
description: 'This is a Mollie test payment method',
enabled: true,
handler: {
code: molliePaymentHandler.code,
arguments: [
{ name: 'redirectUrl', value: `${tunnel.url}/admin/orders?filter=open&page=1&dynamicRedirectUrl=false` },
// tslint:disable-next-line:no-non-null-assertion
{ name: 'apiKey', value: process.env.MOLLIE_APIKEY! },
{ name: 'autoCapture', value: 'false' },
],
},
},
},
});
);
// Prepare order for payment
await shopClient.asUserWithCredentials('hayden.zieme12@hotmail.com', 'test');
await shopClient.query<AddItemToOrder.Order, AddItemToOrder.Variables>(ADD_ITEM_TO_ORDER, {
Expand Down Expand Up @@ -114,6 +117,7 @@ import { CREATE_MOLLIE_PAYMENT_INTENT, setShipping } from './payment-helpers';
});
const { createMolliePaymentIntent } = await shopClient.query(CREATE_MOLLIE_PAYMENT_INTENT, {
input: {
redirectUrl: `${tunnel.url}/admin/orders?filter=open&page=1&dynamicRedirectUrl=true`,
paymentMethodCode: 'mollie',
// molliePaymentMethodCode: 'klarnapaylater'
},
Expand All @@ -122,5 +126,9 @@ import { CREATE_MOLLIE_PAYMENT_INTENT, setShipping } from './payment-helpers';
throw createMolliePaymentIntent;
}
Logger.info(`Mollie payment link: ${createMolliePaymentIntent.url}`, 'Mollie DevServer');
})();
};

(async () => {
// Change the value of the parameter to true to test with the dynamic redirectUrl functionality
await runMollieDevServer(false);
})()
Loading

0 comments on commit b452419

Please sign in to comment.