Guides
Coming from Stripe in .NET
Move code that uses the official Stripe.net library to Monetize.Pay: the base URL and key, your own Idempotency-Key, the status and invoice line price Monetize.Pay sends it, 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 Stripe.net 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 global client: StripeConfiguration.StripeClient, used by services made with their parameterless constructors. Code that passes its own StripeClient to each service needs the same base URL and key set on that client, and that style is not covered by Monetize.Pay's test run.
StripeConfiguration.ApiKey = Environment.GetEnvironmentVariable("MONETIZEPAY_KEY");
StripeConfiguration.StripeClient = new StripeClient(
apiKey: Environment.GetEnvironmentVariable("MONETIZEPAY_KEY"),
apiBase: "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_...). The services (CustomerService, SubscriptionService and the others) made with their parameterless constructors then use this client. 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 new RequestOptions { StripeAccount = "mch_..." } (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
var service = new CustomerService();
var key = Guid.NewGuid().ToString();
var first = service.Create(
new CustomerCreateOptions { Email = "dotnet-idem@example.test" },
new RequestOptions { IdempotencyKey = key });
var second = service.Create(
new CustomerCreateOptions { Email = "dotnet-idem@example.test" },
new RequestOptions { IdempotencyKey = 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 RequestOptions with IdempotencyKey the same way on every call that charges, refunds or changes a plan, for example a subscription create:
var sub = new SubscriptionService().Create(
new SubscriptionCreateOptions
{
// Customer, Items and DefaultPaymentMethod, as your code sends them today
},
new RequestOptions { IdempotencyKey = Guid.NewGuid().ToString() });- 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.net adds a random key to every POST when you pass none, 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 namesRequestOptions.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}/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.
Create answers: nothing to set
Stripe.net accepts no success status but 200. Monetize.Pay answers a Stripe library with 200 where it answers other callers 201 (for example a customer, product, price, coupon, promotion code or saved card create); the body is the same.
Invoice line prices: nothing to set, but the key must read prices
Older Stripe.net releases read an invoice line's price as a full price object, as Stripe sends it to API versions dated before 2025-03-31, and cannot read an invoice whose line holds only the price id. Monetize.Pay sends the full price object, exactly as GET /v1/prices/{price_id} returns it, whenever the request's Stripe-Version (which the library sends on every request) is dated before 2025-03-31; newer versions get the id. The key must be allowed to read prices (catalog:read): without it the line keeps the id and those releases cannot read the invoice. pricing.price_details.price is always the 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 smaller limit (an ordinary page of 100 invoices is under a tenth of that bound).
3. Receive webhooks
EventUtility.ConstructEvent, with its default arguments, 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), after the signature has verified. The library's value is StripeConfiguration.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), which older Stripe.net releases need to read an event at all.
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 StripeConfiguration.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 and read the typed object:
var body = new UTF8Encoding(false, true).GetString(bytes);
Event stripeEvent;
stripeEvent = EventUtility.ConstructEvent(body, signature, secret);
var dataObject = stripeEvent.Data?.Object;bytes 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 throws StripeException. dataObject is the library's typed model (a Subscription for customer.subscription.created). What each event holds: Billing webhooks.
Invoice events need nothing more. When the endpoint's api_version is dated before 2025-03-31, which it is for the older Stripe.net releases once it matches the library (section 4), each invoice line's price in invoice.paid, invoice.payment_succeeded, invoice.payment_failed, invoice.voided, invoice.marked_uncollectible and invoice.upcoming is the full price object, as GET /v1/prices/{price_id} returns it, so the typed Invoice reads; for a newer api_version it is the id, as those releases expect. pricing.price_details.price stays the id. The view is applied before the event is signed, so the signature covers the bytes you receive. A sample event names no real price, so its lines keep the id.
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 read through the typed model, checkout sessions, and webhook verification with the typed data object.
39.126.0, which pins2020-08-2741.28.0, which pins2022-11-1543.23.0, which pins2023-10-1647.4.0, which pins2025-02-24.acacia50.4.1, which pins2026-02-25.clover53.2.0, which pins2026-11-18.endive
Other versions are untested.
5. Known limits
- Without the endpoint's
api_version(section 3),EventUtility.ConstructEventrefuses every event on every tested version, although the signature verifies. - Stripe.net has one exception class for every API error,
StripeException: branch onStripeError.Code(Monetize.Pay's code), never on the HTTP status. - Your Stripe ids (
cus_,price_,sub_) do not exist here, and saved cards cannot be moved: see Coming from Stripe.