Guides
Coming from Stripe in PHP
Move code that uses the official Stripe library for PHP to Monetize.Pay: the base URL and key, your own Idempotency-Key, the global base for paging, webhook verification, the tested versions and the known limits.
This page moves an application that already uses the official stripe/stripe-php 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 StripeClient style ($client->customers->create(...)). Code that uses the static calls (\Stripe\Customer::create) reads the global base, \Stripe\Stripe::$apiBase, for every request, so the line in section 2 is the base URL for that style on every version; the static style is otherwise not covered by Monetize.Pay's test run.
function newClient(): \Stripe\StripeClient
{
return new \Stripe\StripeClient(['api_key' => getenv('MONETIZEPAY_KEY'), 'api_base' => 'https://api.zeropoint.example']);
}
$client = newClient();Use your Monetize.Pay host from the console in place of api.zeropoint.example, and your Monetize.Pay key (zp_test_...). 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
Set the global base too, before stripe-php 23.1.0
Before stripe-php 23.1.0, also assign the same base URL to the library's global setting, once, before the first call (the library has no setApiBase()):
\Stripe\Stripe::$apiBase = 'https://api.zeropoint.example';Without it, a StripeClient sends the second and later pages of an auto-paged list (autoPagingIterator()) to the global base, which is Stripe's host unless you set it, so those pages never reach Monetize.Pay. Use the same host as in section 1. With the global base set, the oldest and the newest of the affected tested versions passed every check (section 4).
Pass your own Idempotency-Key
$key = uuid4();
$first = $client->customers->create(['email' => 'php-idem@example.test'], ['idempotency_key' => $key]);
$second = $client->customers->create(['email' => 'php-idem@example.test'], ['idempotency_key' => $key]);uuid4() is a helper in Monetize.Pay's test code that returns a random version 4 UUID: use your own. 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 = $client->subscriptions->create([
// customer, items and default_payment_method, as your code sends them today
], ['idempotency_key' => uuid4()]);- 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-php adds a key of its own only when its network retries are above 0, and they are 0 by default at every tested version, so by default it sends none and a subscription create is refused. 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-php does not check an event's version.
Then verify each delivery with the library's own verifier:
$event = \Stripe\Webhook::constructEvent($body, $signature, $secret);
$gotId = $event->data->object->id ?? null;$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 throws \Stripe\Exception\SignatureVerificationException. 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 (on a StripeClient, without the global base) and an explicit Idempotency-Key on the subscription create: customers, paging, errors, idempotent replay, prices, subscriptions, invoices, checkout sessions and webhook verification, 15 checks.
7.128.1: 14 of 15; auto-paging fails as section 2 describes. With the global base also set, all 15 passed. It sends noStripe-Versionby default.10.21.1: 14 of 15; auto-paging fails as section 2 describes. It sends noStripe-Versionby default.13.18.1: 14 of 15; auto-paging fails as section 2 describes.16.6.1: 14 of 15; auto-paging fails as section 2 describes.19.4.2: 14 of 15; auto-paging fails as section 2 describes. With the global base also set, all 15 passed.23.1.0: all 15.
Other versions are untested.
5. Known limits
- Until the global base is set (section 2), an auto-paged list on an older version sends its later pages to Stripe's host, not to Monetize.Pay.
- Without your own key (section 2) a subscription create, an invoice pay or a refund is refused; 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. Set the'stripe_version'option of theStripeClientconfiguration to 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.