Guides
Coming from Stripe in Ruby
Move code that uses the official Stripe gem for Ruby 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 gem for Ruby 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 global style: the base URL and key set on Stripe, and calls such as Stripe::Customer.create. Code that uses Stripe::StripeClient needs the same base URL and key set in its own way, and that style is not covered by Monetize.Pay's test run.
require "stripe"
Stripe.api_base = "https://api.zeropoint.example"
Stripe.api_key = ENV.fetch("MONETIZEPAY_KEY")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 on each call with { stripe_account: 'mch_...' } in the request options (it sends the Stripe-Account header); with one merchant, leave it out. An acct_... id is refused.
2. Settings this library needs
Pass your own Idempotency-Key
key = SecureRandom.uuid
first = Stripe::Customer.create({ email: "rb-idem@example.test" }, { idempotency_key: key })
second = Stripe::Customer.create({ email: "rb-idem@example.test" }, { idempotency_key: key })The same call sent again with the same key returns the first answer and runs nothing twice: second is the customer first created. Pass { idempotency_key: ... } as the request options the same way on every call that charges, refunds or changes a plan, for example a subscription create:
sub = Stripe::Subscription.create(
{
# customer, items and default_payment_method, as your code sends them today
},
{ idempotency_key: SecureRandom.uuid }
)- 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
5xxor 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. stripe-ruby adds a key of its own only when
Stripe.max_network_retriesis above 0, and older releases leave it at 0 by default, so they 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. - These requests require a key and answer a request without one
400 idempotency_key_required, with nothing run or charged (the message namesidempotency_key):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}/terminalsand, in test mode,POST /v1/test_helpers/checkout/sessions/{session_id}/confirmandPOST /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 (the library's webhook endpoint calls are not served):
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-ruby does not check an event's version.
Then verify each delivery with the library's own verifier:
event = Stripe::Webhook.construct_event(body.dup, signature, secret)
object = event[:data][:object]body is the raw request body as received (never parsed and serialized again), signature is the Stripe-Signature header and secret is the whsec_ secret. A body changed by even one byte raises Stripe::SignatureVerificationError. 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 checks each version below with only the base URL and key changed and an explicit Idempotency-Key on the subscription create. Each passes all 15 checks: customers, paging, errors, idempotent replay, prices, subscriptions, invoices, checkout sessions and webhook verification.
5.55.0: it sends noStripe-Versionby default.8.7.1: it sends noStripe-Versionby default.10.15.113.5.218.4.321.1.0
Other versions are untested.
5. Known limits
- A version that sends no key by default (section 2) cannot create a subscription, pay an invoice or refund until your code passes
idempotency_key; nothing is charged meanwhile. - If your code reads an invoice line's
priceas an object, the request must carry aStripe-Versiondated before 2025-03-31, and the key must be allowed to read prices (catalog:read); without that header the line holds the price id. SetStripe.api_versionto the API version your code was written for. Section 4 marks the tested versions that send noStripe-Versionby 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 smallerlimit(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.