From 3a1ed748390865c80d487133e4c8e9df030eb4f7 Mon Sep 17 00:00:00 2001 From: Angel Leonardo Banderas Larios <70727659+angelbanderasudg@users.noreply.github.com> Date: Tue, 18 Nov 2025 10:21:44 -0600 Subject: [PATCH] feat(payment-stripe): OXXO payment provider support with configurable expiration (#13805) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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 #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`. > > Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 4d7fe0658b91e6948f011a73d77a6281c85cdd26. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot). Co-authored-by: William Bouchard <46496014+willbouch@users.noreply.github.com> --- .changeset/tidy-starfishes-watch.md | 5 ++++ .../payment-stripe/src/core/stripe-base.ts | 3 ++- .../providers/payment-stripe/src/index.ts | 2 ++ .../payment-stripe/src/services/index.ts | 1 + .../src/services/stripe-oxxo.ts | 24 +++++++++++++++++++ .../payment-stripe/src/types/index.ts | 12 +++++++++- 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 .changeset/tidy-starfishes-watch.md create mode 100644 packages/modules/providers/payment-stripe/src/services/stripe-oxxo.ts diff --git a/.changeset/tidy-starfishes-watch.md b/.changeset/tidy-starfishes-watch.md new file mode 100644 index 0000000000..139ec069d8 --- /dev/null +++ b/.changeset/tidy-starfishes-watch.md @@ -0,0 +1,5 @@ +--- +"@medusajs/payment-stripe": patch +--- + +feat(payment-stripe): OXXO payment provider support with configurable expiration diff --git a/packages/modules/providers/payment-stripe/src/core/stripe-base.ts b/packages/modules/providers/payment-stripe/src/core/stripe-base.ts index 5d31e5c487..ec86a32e1b 100644 --- a/packages/modules/providers/payment-stripe/src/core/stripe-base.ts +++ b/packages/modules/providers/payment-stripe/src/core/stripe-base.ts @@ -114,7 +114,8 @@ abstract class StripeBase extends AbstractPaymentProvider { extra?.payment_method_data as Stripe.PaymentIntentCreateParams.PaymentMethodData res.payment_method_options = - extra?.payment_method_options as Stripe.PaymentIntentCreateParams.PaymentMethodOptions + (extra?.payment_method_options as Stripe.PaymentIntentCreateParams.PaymentMethodOptions) ?? + this.paymentIntentOptions.payment_method_options res.automatic_payment_methods = (extra?.automatic_payment_methods as { enabled: true } | undefined) ?? diff --git a/packages/modules/providers/payment-stripe/src/index.ts b/packages/modules/providers/payment-stripe/src/index.ts index b2b1e8e7f1..9693abd5c2 100644 --- a/packages/modules/providers/payment-stripe/src/index.ts +++ b/packages/modules/providers/payment-stripe/src/index.ts @@ -7,6 +7,7 @@ import { StripeProviderService, StripePrzelewy24Service, StripePromptpayService, + OxxoProviderService, } from "./services" const services = [ @@ -17,6 +18,7 @@ const services = [ StripeProviderService, StripePrzelewy24Service, StripePromptpayService, + OxxoProviderService, ] export default ModuleProvider(Modules.PAYMENT, { diff --git a/packages/modules/providers/payment-stripe/src/services/index.ts b/packages/modules/providers/payment-stripe/src/services/index.ts index cbfeadc3fa..37fd70ae28 100644 --- a/packages/modules/providers/payment-stripe/src/services/index.ts +++ b/packages/modules/providers/payment-stripe/src/services/index.ts @@ -5,3 +5,4 @@ export { default as StripeIdealService } from "./stripe-ideal" export { default as StripeProviderService } from "./stripe-provider" export { default as StripePrzelewy24Service } from "./stripe-przelewy24" export { default as StripePromptpayService } from "./stripe-promptpay" +export { default as OxxoProviderService } from "./stripe-oxxo" diff --git a/packages/modules/providers/payment-stripe/src/services/stripe-oxxo.ts b/packages/modules/providers/payment-stripe/src/services/stripe-oxxo.ts new file mode 100644 index 0000000000..f8323feaf0 --- /dev/null +++ b/packages/modules/providers/payment-stripe/src/services/stripe-oxxo.ts @@ -0,0 +1,24 @@ +import StripeBase from "../core/stripe-base" +import { PaymentIntentOptions, PaymentProviderKeys } from "../types" + +class OxxoProviderService extends StripeBase { + static identifier = PaymentProviderKeys.OXXO + + constructor(_, options) { + super(_, options) + } + + get paymentIntentOptions(): PaymentIntentOptions { + return { + payment_method_types: ["oxxo"], + capture_method: "automatic", + payment_method_options: { + oxxo: { + expires_after_days: this.options.oxxoExpiresDays || 3, + }, + }, + } + } +} + +export default OxxoProviderService diff --git a/packages/modules/providers/payment-stripe/src/types/index.ts b/packages/modules/providers/payment-stripe/src/types/index.ts index 0a56367ec6..5763b1daae 100644 --- a/packages/modules/providers/payment-stripe/src/types/index.ts +++ b/packages/modules/providers/payment-stripe/src/types/index.ts @@ -19,12 +19,21 @@ export interface StripeOptions { * Set a default description on the intent if the context does not provide one */ paymentDescription?: string + /** + * Set the number of days before an OXXO payment expires + */ + oxxoExpiresDays?: number } export interface PaymentIntentOptions { capture_method?: "automatic" | "manual" setup_future_usage?: "on_session" | "off_session" payment_method_types?: string[] + payment_method_options?: { + oxxo?: { + expires_after_days?: number + } + } } export const ErrorCodes = { @@ -38,10 +47,11 @@ export const ErrorIntentStatus = { export const PaymentProviderKeys = { STRIPE: "stripe", + OXXO: "stripe-oxxo", BAN_CONTACT: "stripe-bancontact", BLIK: "stripe-blik", GIROPAY: "stripe-giropay", IDEAL: "stripe-ideal", PRZELEWY_24: "stripe-przelewy24", - PROMPT_PAY : "stripe-promptpay", + PROMPT_PAY: "stripe-promptpay", }