Guides
Coming from Stripe in Go
Move code that uses the official stripe-go library to Monetize.Pay: the base URL and key, your own Idempotency-Key, request bodies without a stated length, webhook verification with the endpoint's api_version, the tested versions and the known limits.
This page moves an application that already uses the official github.com/stripe/stripe-go library 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.API style (client.New, then calls such as sc.Customers.New). Code that uses stripe.NewClient needs the same backends and key (stripe.WithBackends(...)), and Monetize.Pay's test run drives that style for one auto-paged list only.
func backends(base *string) *stripe.Backends {
config := func() *stripe.BackendConfig {
return &stripe.BackendConfig{MaxNetworkRetries: stripe.Int64(0), URL: base}
}
return stripe.NewBackendsWithConfig(config())
}var sc *client.API
sc = client.New(os.Getenv("MONETIZEPAY_KEY"), backends(stripe.String("https://api.zeropoint.example")))Use your Monetize.Pay host from the console in place of api.zeropoint.example, and your Monetize.Pay key (zp_test_...). stripe and client are the library's root package and its client package, imported with your major's module path. If your stripe-go has no stripe.NewBackendsWithConfig, return the backends this way instead, one fresh config each:
return &stripe.Backends{
API: stripe.GetBackendWithConfig(stripe.APIBackend, config()),
Connect: stripe.GetBackendWithConfig(stripe.ConnectBackend, config()),
Uploads: stripe.GetBackendWithConfig(stripe.UploadsBackend, config()),
}MaxNetworkRetries: stripe.Int64(0) is how Monetize.Pay's test run configures the library; leave that field out to keep the library's default, as Coming from Stripe advises. With more than one merchant in a mode, name the merchant on each call with params.SetStripeAccount("mch_...") on the call's parameters (it sends the Stripe-Account header); with one merchant, leave it out. An acct_... id is refused.
2. Settings this library needs
Request bodies: nothing to set
stripe-go sends every request body without a stated length (Transfer-Encoding: chunked, no Content-Length). Monetize.Pay accepts such a body on /v1 up to 1,048,576 bytes; a larger one is refused before anything runs: stripe-go receives HTTP 400 with code payload_too_large (zeropoint_status 413), and the connection is closed.
Pass your own Idempotency-Key
key := newUUID()
params := &stripe.SubscriptionParams{
// Customer, Items and DefaultPaymentMethod, as your code sends them today
}
params.SetIdempotencyKey(key)
sub, err := sc.Subscriptions.New(params)newUUID() is a helper in Monetize.Pay's test code that returns a random version 4 UUID: use your own. Set the key the same way, with SetIdempotencyKey on the call's parameters, on every call that charges, refunds or changes a plan. The same call sent again with the same key returns the first answer and runs nothing twice.
- 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. - Do not rely on a key the library generates. stripe-go adds a random key to every write when you pass none (older majors only when the call has parameters), but 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. Pass your own key on every such call, as above, and keep it with the order.
- These requests require a key and answer a request without one
400 idempotency_key_required, with nothing run or charged (the message namesSetIdempotencyKey):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
webhook.ConstructEvent refuses an event whose api_version does not match the version the library pins (an exact match in older releases, the same release name, the part after the dot, in newer ones), although the signature verifies. The library's value is the constant stripe.APIVersion. Set the endpoint's api_version to that exact value: Monetize.Pay then stamps every event to the endpoint with it. It is accepted only together with stripe_compatible_payload: true, and every event to such an endpoint also carries request (id and idempotency_key, both null), as Stripe's events do.
Register each URL once with a plain HTTP request (the library's webhook endpoint calls are not served):
Or set it on an endpoint you already have, also a plain HTTP request:
Replace <the library's pinned version> with the value of stripe.APIVersion (section 4 lists it for each tested version). Send no Stripe-Account header on either. 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 create answer: it is shown once. When you upgrade the library, set the endpoint's api_version to the new value; "api_version": null clears it. Change it right after the upgraded code is live. Until then your verifier refuses each event: answer it with a non-2xx status so Monetize.Pay retries it, on the schedule in Webhooks, section 5. Each retry carries the endpoint's api_version at the moment it is sent.
Then verify each delivery with the library's own verifier:
event, err := webhook.ConstructEvent(body, signature, secret)body is the raw request body as received (bytes, never parsed and serialized again), signature is the Stripe-Signature header and secret is the whsec_ secret. A body changed by even one byte returns webhook.ErrNoValidSignature. stripe-go leaves the event's data object as raw JSON in event.Data.Raw: decode it into the type you expect. 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, an explicit Idempotency-Key on the subscription create, and the webhook endpoint's api_version set to the version the library pins (shown beside it). Each passes all 15 checks: customers, paging, errors, idempotent replay, prices, subscriptions, invoices, checkout sessions and webhook verification.
v72.122.0, which pins2020-08-27; it does not check an event's versionv74.30.0, which pins2022-11-15v76.25.0, which pins2023-10-16v81.4.0, which pins2025-02-24.acaciav84.4.1, which pins2026-02-25.cloverv87.2.0, which pins2026-11-18.endive
Other versions are untested.
5. Known limits
- Without the endpoint's
api_version(section 3),webhook.ConstructEventrefuses every event on every tested version but the oldest, which has no such check (section 4), although the signature verifies. - A request body over 1,048,576 bytes is refused (section 2).
- When the library sends a
Stripe-Versiondated before 2025-03-31, each invoice line'spriceis the full price object, as Stripe sends it to those versions, provided the key may read prices (catalog:read); otherwise it is the price id. 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.