-
-
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): Prevent duplicate Mollie payments (#2691)
BREAKING CHANGE: MolliePlugin - A new mollieOrderId has been added in order to prevent duplicate payments in Mollie. This will require a DB migration to add the custom field to your DB schema.
- Loading branch information
1 parent
e0c0ae0
commit 34b61cd
Showing
9 changed files
with
427 additions
and
90 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
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
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 |
---|---|---|
|
@@ -26,11 +26,12 @@ import { | |
LanguageCode, | ||
} from './graphql/generated-admin-types'; | ||
import { AddItemToOrderMutation, AddItemToOrderMutationVariables } from './graphql/generated-shop-types'; | ||
import { ADD_ITEM_TO_ORDER } from './graphql/shop-queries'; | ||
import { ADD_ITEM_TO_ORDER, ADJUST_ORDER_LINE } from './graphql/shop-queries'; | ||
import { CREATE_MOLLIE_PAYMENT_INTENT, setShipping } from './payment-helpers'; | ||
|
||
/** | ||
* This should only be used to locally test the Mollie payment plugin | ||
* Make sure you have `MOLLIE_APIKEY=test_xxxx` in your .env file | ||
*/ | ||
/* eslint-disable @typescript-eslint/no-floating-promises */ | ||
async function runMollieDevServer(useDynamicRedirectUrl: boolean) { | ||
|
@@ -101,21 +102,19 @@ async function runMollieDevServer(useDynamicRedirectUrl: boolean) { | |
}, | ||
}, | ||
); | ||
// Prepare order for payment | ||
// Prepare order with 2 items | ||
await shopClient.asUserWithCredentials('[email protected]', 'test'); | ||
// Add another item to the order | ||
await shopClient.query<AddItemToOrderMutation, AddItemToOrderMutationVariables>(ADD_ITEM_TO_ORDER, { | ||
productVariantId: 'T_5', | ||
productVariantId: 'T_4', | ||
quantity: 1, | ||
}); | ||
const ctx = new RequestContext({ | ||
apiType: 'admin', | ||
isAuthorized: true, | ||
authorizedAsOwnerOnly: false, | ||
channel: await server.app.get(ChannelService).getDefaultChannel(), | ||
await shopClient.query<AddItemToOrderMutation, AddItemToOrderMutationVariables>(ADD_ITEM_TO_ORDER, { | ||
productVariantId: 'T_5', | ||
quantity: 1, | ||
}); | ||
await setShipping(shopClient); | ||
// Add pre payment to order | ||
const order = await server.app.get(OrderService).findOne(ctx, 1); | ||
// Create payment intent | ||
const { createMolliePaymentIntent } = await shopClient.query(CREATE_MOLLIE_PAYMENT_INTENT, { | ||
input: { | ||
redirectUrl: `${tunnel.url}/admin/orders?filter=open&page=1&dynamicRedirectUrl=true`, | ||
|
@@ -128,6 +127,24 @@ async function runMollieDevServer(useDynamicRedirectUrl: boolean) { | |
} | ||
// eslint-disable-next-line no-console | ||
console.log('\x1b[41m', `Mollie payment link: ${createMolliePaymentIntent.url as string}`, '\x1b[0m'); | ||
|
||
// Remove first orderLine | ||
await shopClient.query(ADJUST_ORDER_LINE, { | ||
orderLineId: 'T_1', | ||
quantity: 0, | ||
}); | ||
await setShipping(shopClient); | ||
|
||
// Create another intent after Xs, should update the mollie order | ||
await new Promise(resolve => setTimeout(resolve, 5000)); | ||
const { createMolliePaymentIntent: secondIntent } = await shopClient.query(CREATE_MOLLIE_PAYMENT_INTENT, { | ||
input: { | ||
redirectUrl: `${tunnel.url}/admin/orders?filter=open&page=1&dynamicRedirectUrl=true`, | ||
paymentMethodCode: 'mollie', | ||
}, | ||
}); | ||
// eslint-disable-next-line no-console | ||
console.log('\x1b[41m', `Second payment link: ${secondIntent.url as string}`, '\x1b[0m'); | ||
} | ||
|
||
(async () => { | ||
|
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
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,16 @@ | ||
import { CustomFieldConfig, Order, CustomOrderFields } from '@vendure/core'; | ||
|
||
export interface OrderWithMollieReference extends Order { | ||
customFields: CustomOrderFields & { | ||
mollieOrderId?: string; | ||
}; | ||
} | ||
|
||
export const orderCustomFields: CustomFieldConfig[] = [ | ||
{ | ||
name: 'mollieOrderId', | ||
type: 'string', | ||
internal: true, | ||
nullable: true, | ||
}, | ||
]; |
Oops, something went wrong.