Guides

Coming from Stripe in Node

Move code that uses the official Stripe library for Node to Monetize.Pay: the base URL and key, your own Idempotency-Key, webhook verification, the tested versions and the known limits.

This page moves an application that already uses the official stripe package for Node to Monetize.Pay with the fewest changes. Follow it top to bottom. Coming from Stripe lists, call by call, what works, what is refused and what to use instead. Monetize.Pay is not affiliated with or endorsed by Stripe, Inc. Stripe is a trademark of Stripe, Inc. Billing runs in test mode in this release.

1. Point the library at Monetize.Pay

This page covers the client made with new Stripe(key, options).

JavaScript
const BASE_OPTS = { host: 'api.zeropoint.example', port: 443, protocol: 'https' };
const stripe = new Stripe(process.env.MONETIZEPAY_KEY, BASE_OPTS);

Use your Monetize.Pay host from the console in place of api.zeropoint.example, and your Monetize.Pay key (zp_test_...). Change nothing else, and keep the library's default retries. With more than one merchant in a mode, name the merchant with the stripeAccount option (it sends Stripe-Account: mch_...); with one merchant, leave it out. An acct_... id is refused.

2. Settings this library needs

Pass your own Idempotency-Key

JavaScript
const uid = () => crypto.randomUUID();
const key = `idem-${uid()}`;
const a = await stripe.customers.create({ email: 'replay@example.test' }, { idempotencyKey: key });
const b = await stripe.customers.create({ email: 'replay@example.test' }, { idempotencyKey: key });

The same call sent again with the same key returns the first answer and runs nothing twice: b is the customer a created. Pass { idempotencyKey: ... } as the request options the same way on every call that charges, refunds or changes a plan, for example a partial refund:

JavaScript
const r = await stripe.refunds.create({ payment_intent: paidSession.payment_intent, amount: 200 }, { idempotencyKey: `refund-${uid()}` });
  • Make one key per order or per change, store it and keep it with the order before you make the call, and send that stored key again when you retry. After a timeout, a 5xx or a dropped connection the outcome is unknown, and only the same request with the same key is safe: it replays the first answer or finishes the same payment, never a second one. The test code above makes each key inline only because each of its calls is a new order.
  • Do not rely on a key the library generates. The newest stripe-node releases add a key of their own to every POST; older ones only when maxNetworkRetries is above 0, which the oldest leave at 0 by default, so those send none. Where it adds one, that key is new on every call and your code never sees it, so a retry your code makes carries a new key and is a new request, run again (a partial refund sent twice this way is two refunds).
  • These requests require a key and answer a request without one 400 idempotency_key_required, with nothing run or charged (the message names idempotencyKey): POST /v1/subscriptions, POST /v1/subscriptions/{subscription_id}, POST /v1/invoices/{invoice_id}/pay, POST /v1/refunds, POST /v1/payments, POST /v1/payments/{payment_id}/cancel, POST /v1/payments/{payment_id}/refund, POST /v1/payments/{payment_id}/void, POST /v1/payment_methods, POST /v1/webhooks, POST /v1/webhooks/{webhook_id}/rotate-secret, POST /v1/billing_settings, POST /v1/merchants, POST /v1/merchants/{merchant_id}/terminals and, in test mode, POST /v1/test_helpers/checkout/sessions/{session_id}/confirm and POST /v1/test_helpers/merchants/{merchant_id}/settle (it settles the merchant's test sales now, so a refund can follow). On customer, catalog and checkout session creates a key is optional; with one, a retry replays the first answer.

3. Receive webhooks

Register each URL once with a plain HTTP request, for example with fetch (the library's webhookEndpoints calls are not served):

POST /v1/webhooks
Authorization: Bearer zp_test_...
Idempotency-Key: <a new unique value>
Content-Type: application/json

{"url":"https://api.acme.test/zeropoint/stripe","event_types":["checkout.session.completed","invoice.paid","invoice.payment_failed","customer.subscription.created","customer.subscription.updated","customer.subscription.deleted"],"stripe_signature_header":true,"stripe_compatible_payload":true}

Send no Stripe-Account header on it. List every billing type you handle: billing events are opt-in, and an empty list gets payment events only. Keep the whsec_ secret from the answer: it is shown once. Leave api_version out: stripe-node does not check an event's version.

Then verify each delivery with the library's own verifier:

JavaScript
const ev = stripe.webhooks.constructEvent(rawBody, req.headers['stripe-signature'], whsec);

rawBody is the raw request body as received (a Buffer or string, never parsed and serialized again) and whsec is the whsec_ secret. A body changed by even one byte throws. Every event to this endpoint carries request (id and idempotency_key, both null), as Stripe's events do. What each event holds: Billing webhooks.

4. Versions Monetize.Pay's test run covers

Monetize.Pay's own test-mode run drives each version below through its pilot flows (catalog, customers, checkout, subscriptions and plan changes, invoices, refunds, webhook verification and the retry cases) with only the base URL and key changed and the library's other settings at their defaults.

  • 8.222.0: it sends no Idempotency-Key by default, so the 17 calls that needed one were refused with idempotency_key_required and nothing was charged; an invoice pay with an explicit key passed, and every other call passed but the by-design param difference in section 5. invoices.createPreview is not in this version. It sends no Stripe-Version by default.
  • 10.17.0: the same as the version above. It sends no Stripe-Version by default.
  • 14.25.0: every call passed but the by-design param difference in section 5. invoices.createPreview is not in this version.
  • 17.7.0: every call passed but the by-design param difference in section 5.
  • 20.4.1: every call passed but the by-design param difference in section 5.
  • 23.1.0: every call passed but the by-design param difference in section 5.

Other versions are untested.

5. Known limits

  • A version that sends no key by default (section 2) cannot create or change a subscription, pay an invoice or refund until your code passes idempotencyKey; nothing is charged meanwhile.
  • Some stripe-node releases send a request once more after a dropped connection, whatever maxNetworkRetries says. With your own key that resend replays the first answer; without one it would be a second request.
  • An error's param for a metadata key reads metadata, never metadata[key], by design.
  • If your code reads an invoice line's price as an object, the request must carry a Stripe-Version dated before 2025-03-31, and the key must be allowed to read prices (catalog:read); without that header the line holds the price id. Set the apiVersion option of new Stripe(key, options) to the API version your code was written for. Section 4 marks the tested versions that send no Stripe-Version by default. An answer larger than 8 MiB (8,388,608 bytes) is sent with the price ids, not objects: a caller on an older API version whose subscriptions carry very large metadata should list invoices with a smaller limit (an ordinary page of 100 invoices is under a tenth of that bound).
  • Your Stripe ids (cus_, price_, sub_) do not exist here, and saved cards cannot be moved: see Coming from Stripe.