Collect payments with payment form
This tutorial builds a working checkout that collects a card payment using Zuora’s hosted Payment Form. Your server mints a short-lived payment session; the browser loads zuora.js, renders the form, and reports the result — all without card data ever touching your backend.
You’ll need a Zuora publishable key (Settings > Payments > Payment Form) and a set of OAuth credentials (client ID and secret) for the server. Test with card 4111 1111 1111 1111.
Walkthrough
Scroll through the steps below. The code panel on the right follows along — switching files and focusing the lines that matter for each step.
Set your OAuth client ID and secret, then construct the ZuoraClient against the sandbox environment (SBX).
In the Zuora UI, open Settings > Payments > Payment Form to review your form and copy its publishable key into the client.
Create a Zuora object in the browser with the publishable key you copied.
Build and start the sample server, then open the checkout page in your browser.
Open the checkout page and pay with the Zuora test card to run a payment end to end.
Adjust the order summary markup to match your product and branding.
Style the page shoppers land on after paying. It displays the returned payment ID.
The onComplete callback receives the result. Redirect to the return page on success, or surface the error message on failure.
Add the Zuora Java SDK as a Maven dependency. Check Maven Central for the latest version.
For multi-entity tenants, scope requests to a specific entity by calling zuoraClient.setEntityId(...) after building the client.
This endpoint creates an account for the shopper, then creates a payment session and returns its one-time token to the browser.
Include the Zuora Payments library on your checkout page.
Add the element the hosted form mounts into.
Instantiate the Zuora object with your publishable key.
Configure the form -- locale, region, currency, amount, and a createPaymentSession callback that calls your backend when the shopper clicks Pay.
Create the hosted payment form from the configuration and mount it into the container element.
Run it
- Build the server:
mvn package - Start it:
java -cp target/sample-jar-with-dependencies.jar com.zuora.sample.Server - Open
http://localhost:8888/checkout.htmland pay with the test card.
On success, the customer is redirected to your return page with the resulting paymentId.
What’s next
- Save the payment method — switch the payment session to a create-and-save flow to reuse the method for recurring billing.
- Handle failures — inspect
result.errorin theonCompletecallback to surface gateway decline reasons. - Go to production — pin a versioned
zuora.jsURL and swap the sandbox publishable key for your live key.