Commit 3a1ed74
feat(payment-stripe): OXXO payment provider support with configurable expiration (medusajs#13805)
## Summary
**What** — What changes are introduced in this PR?
This pull request adds support for OXXO payments to the Stripe payment provider module. The main changes include the addition of a new `OxxoProviderService`, updates to type definitions to support OXXO-specific options, and integration of the new service into the provider's exports and registration.
**Why** — Why are these changes relevant or necessary?
I was testing the MedusaJs server, I live in México and here oxxo as a Payment method is very used.
**How** — How have these changes been implemented?
* Introduced `OxxoProviderService` in `stripe-oxxo.ts`, which extends `StripeBase` and configures Stripe payment intents for OXXO, including expiration settings.
* Updated `StripeOptions` and `PaymentIntentOptions` types to include `oxxoExpiresDays` and OXXO-specific payment method options for intent configuration.
* Added `OXXO` to the `PaymentProviderKeys` enum for provider identification.
**Testing** — How have these changes been tested, or how can the reviewer test the feature?
You need to launch the medusa server, add Stripe OXXO as Payment Provider in your Store Region (OXXO only works in México and with mxn currency) and set payment_method_data type to oxxo.
Also you need to allow oxxo payment as payment method in stripe and configure your stripe webhook to your medusa server
---
## Examples
Provide examples or code snippets that demonstrate how this feature works, or how it can be used in practice.
This helps with documentation and ensures maintainers can quickly understand and verify the change.
```ts
// Example usage using nextjs starter
const confirmParams: any = {
return_url: returnUrl,
}
if (isOxxo(providerId)) {
confirmParams.payment_method_data = {
type: "oxxo",
billing_details: {
name:
cart.billing_address?.first_name +
" " +
cart.billing_address?.last_name,
address: {
city: cart.billing_address?.city ?? undefined,
country: cart.billing_address?.country_code ?? undefined,
line1: cart.billing_address?.address_1 ?? undefined,
line2: cart.billing_address?.address_2 ?? undefined,
postal_code: cart.billing_address?.postal_code ?? undefined,
state: cart.billing_address?.province ?? undefined,
},
email: cart.email,
phone: cart.billing_address?.phone ?? undefined,
},
}
await stripe
.confirmPayment({
clientSecret,
confirmParams,
redirect: "if_required",
})
.then(({ error, paymentIntent }) => {
console.log({ error, paymentIntent })
const validateIntent = async (paymentIntent: any) => {
const link =
paymentIntent.next_action?.oxxo_display_details
?.hosted_voucher_url
if (link) {
setSubmitting(false)
setMessage(
"Se ha generado un cupón de pago de OXXO. Por favor, revisa la nueva pestaña abierta."
)
await onPaymentCompleted() // Here I call the function because I have custom logic for creating a pending order
}
}
if (error) {
const pi = error.payment_intent
if (
(pi && pi.status === "requires_capture") ||
(pi && pi.status === "succeeded")
) {
onPaymentCompleted()
}
if (pi && pi.status === "requires_action") {
validateIntent(pi)
return
}
setErrorMessage(error.message || null)
setSubmitting(false)
return
}
if (
(paymentIntent && paymentIntent.status === "requires_capture") ||
(paymentIntent && paymentIntent.status === "succeeded")
) {
return onPaymentCompleted()
}
if (paymentIntent && paymentIntent.status === "requires_action") {
validateIntent(paymentIntent) // This is the action that you normally get
}
})
}
}
// Configuration on the server (medusa-config.ts)
modules: [
{
resolve: "@medusajs/medusa/payment",
options: {
providers: [
{
resolve: "@medusa/payment-stripe",
id: "stripe",
options: {
apiKey: process.env.STRIPE_API_KEY,
webhookSecret: process.env.STRIPE_WEBHOOK_SECRET,
capture: true,
oxxoExpiresDays: 7, // default to 3
},
},
],
},
},
],
// And not necessary buy you can extend even more creating a pending-orders module (for showing the vouchers created that costumer need to pay in the frontend, because if not the order only creates after the user have payed the voucher, for testing is 3 minutes), this is an example model:
import { model } from "@medusajs/framework/utils";
export const PendingOrder = model.define("pending_order", {
id: model.id().primaryKey(),
cart_id: model.text().unique(),
user_id: model.text(),
total: model.number(),
payment_type: model.text(),
voucher_url: model.text().nullable(),
payment_session_id: model.text(), // this are the ones that works to identify the payment
payment_collection_id: model.text(), // this are the ones that works to identify the payment
});
export default PendingOrder;
```
---
## Checklist
Please ensure the following before requesting a review:
- [x] I have added a **changeset** for this PR
- Every non-breaking change should be marked as a **patch**
- To add a changeset, run `yarn changeset` and follow the prompts
- [x] The changes are covered by relevant **tests**
- [x] I have verified the code works as intended locally
- [x ] I have linked the related issue(s) if applicable
---
## Additional Context
medusajs#13804
---
> [!NOTE]
> Adds OXXO payment support to the Stripe provider with configurable expiration days and updates intent option handling and typings.
>
> - **Payment Providers**:
> - **New `OxxoProviderService`** (`services/stripe-oxxo.ts`): configures `payment_intent` for OXXO with `expires_after_days` (defaults to `3`, configurable via `options.oxxoExpiresDays`).
> - Registered in `src/index.ts` and exported from `services/index.ts`.
> - **Types**:
> - `StripeOptions` adds `oxxoExpiresDays`.
> - `PaymentIntentOptions` adds `payment_method_options.oxxo.expires_after_days`.
> - `PaymentProviderKeys` adds `OXXO`.
> - **Core**:
> - `core/stripe-base.ts`: `normalizePaymentIntentParameters` now falls back to `this.paymentIntentOptions.payment_method_options` when not provided in `extra`.
> - **Changeset**:
> - Patch release for `@medusajs/payment-stripe`.
>
> <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 4d7fe06. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
Co-authored-by: William Bouchard <[email protected]>1 parent 62d103b commit 3a1ed74
File tree
6 files changed
+45
-2
lines changed- .changeset
- packages/modules/providers/payment-stripe/src
- core
- services
- types
6 files changed
+45
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
| 118 | + | |
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
Lines changed: 24 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
27 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
28 | 37 | | |
29 | 38 | | |
30 | 39 | | |
| |||
38 | 47 | | |
39 | 48 | | |
40 | 49 | | |
| 50 | + | |
41 | 51 | | |
42 | 52 | | |
43 | 53 | | |
44 | 54 | | |
45 | 55 | | |
46 | | - | |
| 56 | + | |
47 | 57 | | |
0 commit comments