Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(Mollie): Prevent duplicate payments #2691

Conversation

martijnvdbrug
Copy link
Collaborator

@martijnvdbrug martijnvdbrug commented Feb 21, 2024

Description

Short demo video

After talking to Mollie Support, we do the following to prevent duplicate payments:

  1. On each intent creation, we store a reference to the Mollie Checkout on order.customFields.mollieOrderId
  2. If a Mollie order already exists, we update it's contents. If not, we create a new order

ℹ️ Whenever updating the existing order fails, we continue the flow as before, which is to just create a new order.

Breaking changes

  • A DB migration is needed to add the mollieOrderId field on an order.

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

Copy link

netlify bot commented Feb 21, 2024

Deploy Preview for effervescent-donut-4977b2 failed.

Name Link
🔨 Latest commit 07d9b4d
🔍 Latest deploy log https://app.netlify.com/sites/effervescent-donut-4977b2/deploys/65d6fd7bbb80ab00080c4152

@martijnvdbrug martijnvdbrug changed the base branch from master to minor February 22, 2024 12:25
@martijnvdbrug martijnvdbrug marked this pull request as ready for review February 27, 2024 09:01
@@ -12,6 +12,7 @@ export * from './helpers/order-merger/order-merger';
export * from './helpers/order-modifier/order-modifier';
export * from './helpers/order-splitter/order-splitter';
export * from './helpers/order-state-machine/order-state';
export * from './helpers/order-state-machine/order-state-machine';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, this.injector.get(OrderStateMachine); in the Mollie service throws an error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it throws an error if you use a deep import to this?

@vendure/core/dist/service/helpers/order-state-machine/order-state-machine

weird, but ok - it's worth exposing anyway.

CreatePaymentMethod.Mutation,
CreatePaymentMethod.Variables
CreatePaymentMethodMutation,
CreatePaymentMethodMutationVariables
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These types were broken, but there is no type check or linting on test files. (Ideally there are, but that requires quite some time to set up...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah the e2e test suites could use a bit of maintenance re TS errors. Not a high prio though for me since the main function (telling us if we broke something) still works. But yeah I tend to fix errors I see whenever I touch an existing file.

customFields: CustomOrderFields & {
mollieOrderId?: string;
};
}
Copy link
Collaborator Author

@martijnvdbrug martijnvdbrug Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a custom interface instead of a *-types.d.ts file, because that would also infer customFields.mollieOrderId in the Stripe, Paypal and braintree plugin.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, makes sense to encapsulate this implementation detail 👍

return new PaymentIntentError(
'Cannot create payment intent for order with customer that has no firstName set',
);
}
if (!order.customer.lastName.length) {
if (!order.customer?.lastName.length) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other checks like Order has order lines have been removed, because they are checked by canTransitionTo('ArrangingPayment').

@martijnvdbrug
Copy link
Collaborator Author

Vendure:cli unit test is failing, is that expected on this branch, or did I break something?

Failed tasks:
   
   - @vendure/cli:test

@martijnvdbrug martijnvdbrug marked this pull request as ready for review February 29, 2024 08:32
@michaelbromley michaelbromley merged commit 34b61cd into vendure-ecommerce:minor Mar 4, 2024
7 of 12 checks passed
@michaelbromley
Copy link
Member

@martijnvdbrug thank you for this PR - clearly it took quite some time & careful effort to get right!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Customers are able to pay twice for an order in Mollie Locale context gets lost after paying with Mollie
2 participants