-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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(payment): provider service #6308
Conversation
🦋 Changeset detectedLatest commit: e97954b The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
3 Ignored Deployments
|
Be careful about this PR when merging. It seems to have been based off another already merged branch. |
c07564e
to
d39aa4e
Compare
Should be resolved now |
As discussed previously, I think we should go with making all methods that interface with 3rd party providers singular and handle the bulk operations (and the errors that may occur) separately in the API or workflows. This should mitigate the risk of unexpected behavior or an inconsistent state of payments between systems. That way, we can handle an issue with one payment operation in isolation from the others instead of having to deal with scenarios like reconciling payments because 4 captures succeeded in Stripe but none in Medusa. To illustrate, this would look something like this: Payment Module async capturePayment(paymentId) {
const payment = await this.retrievePayment(paymentId)
const provider = await this.retrieveProvider(payment.provider_id)
await provider.capturePayment(payment)
return await paymentService.update({ captured_at: new Date() })
} API // POST /admin/payment-collection/:id/capture
const route = (req, res) => {
const workflow = capturePaymentsWorkflow(req.scope)
const paymentCollection = await paymentModule.retrieve(req.query.id)
const result = await workflow.run({ input: paymentCollection }, { throwOnError: false })
// handle errors … e.g. one out of 5 captures might have succeeded
} Or alternatively, just do five requests to a single API endpoint // POST /admin/payments/:id/capture
const route = (req, res) => {
const workflow = capturePaymentWorkflow(req.scope)
const payment = await paymentModule.retrievePayment(req.query.id)
const result = workflow.run({ input: p })
// handle errors
} Aside from making it less error-prone, it would also simply the Payment Module business logic quite a bit. |
@olivermrbl I agree! Converting this temporarily to a draft while I work on a refactor. |
…ate authorize collection and set sessions methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, think this is good to merge now. I imagine things will change a bit when we integrate Stripe and the BigNumber class, so let's push forward 💪
@adrien2p or @carlos-r-l-rodrigues – do any of you want to go through this before we merge? |
What
Note