Guides

Coming from Stripe in Java

Move code that uses the official Stripe library for Java to Monetize.Pay: the base URL and key, your own Idempotency-Key, the invoice line price, 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 com.stripe:stripe-java 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 style: the base URL and key set on Stripe, and calls such as Customer.create. Code that uses 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.

JAVA
Stripe.overrideApiBase("https://api.zeropoint.example");
Stripe.apiKey = System.getenv("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 RequestOptions.builder().setStripeAccount("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

JAVA
static RequestOptions withIdempotencyKey(String key) {
  return RequestOptions.builder().setIdempotencyKey(key).build();
}
JAVA
String key = UUID.randomUUID().toString();
CustomerCreateParams params =
    CustomerCreateParams.builder().setEmail("java-idem@example.test").build();
Customer first = Customer.create(params, withIdempotencyKey(key));
Customer second = Customer.create(params, withIdempotencyKey(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 those RequestOptions the same way on every call that charges, refunds or changes a plan, for example a subscription create:

JAVA
SubscriptionCreateParams params =
    SubscriptionCreateParams.builder()
        // setCustomer, addItem and setDefaultPaymentMethod, as your code sends them today
        .build();
Subscription sub =
    Subscription.create(params, withIdempotencyKey(UUID.randomUUID().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 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. stripe-java 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 names RequestOptions.builder().setIdempotencyKey): 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.

Invoice line prices: nothing to set, but the key must read prices

Older stripe-java 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

stripe-java's default typed accessor, getDataObjectDeserializer().getObject(), returns an empty Optional unless the event's api_version matches the version the library pins (an exact match in older releases, the same release name, the part after the dot, in newer ones). The library's value is Stripe.API_VERSION. 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.

Register each URL once with a plain HTTP request (the library's webhook endpoint 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,"api_version":"<the library's pinned version>"}

Or set it on an endpoint you already have, also a plain HTTP request:

PATCH /v1/webhooks/{webhook_id}
Authorization: Bearer zp_test_...
Content-Type: application/json

{"stripe_compatible_payload":true,"api_version":"<the library's pinned version>"}

Replace <the library's pinned version> with the value of Stripe.API_VERSION (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. Treat an empty getObject() as a refusal: the signature verifies, so a handler that answers 2xx to an empty object loses the event.

Then verify each delivery with the library's own verifier and read the typed object:

JAVA
String body = new String(raw, StandardCharsets.UTF_8);
Event event = Webhook.constructEvent(body, signature, secret);
Optional<StripeObject> object = event.getDataObjectDeserializer().getObject();

raw 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 throws SignatureVerificationException. Every event to this endpoint also carries request (id and idempotency_key, both null), as Stripe's events do. 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-java 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.

  • 20.136.0, which pins 2020-08-27
  • 22.31.0, which pins 2022-11-15
  • 24.24.0, which pins 2023-10-16
  • 28.4.0, which pins 2025-02-24.acacia
  • 31.4.1, which pins 2026-02-25.clover
  • 34.2.0, which pins 2026-11-18.endive

Other versions are untested.

5. Known limits

  • Without the endpoint's api_version (section 3) the signature still verifies, but getObject() is empty on every tested version.
  • Your Stripe ids (cus_, price_, sub_) do not exist here, and saved cards cannot be moved: see Coming from Stripe.