Hosted payment form API integration
This guide describes how use the Rebilly API to create an order and process a payment using a hosted payment form in the sandbox environment.
Rebilly hosted payment forms simplify the process of accepting payments. Rebilly hosts your payment form and ensures that your payments process is secure and PCI compliant.
Prerequisites
Complete this section to create the resources needed for this guide in your Rebilly sandbox, such as a product, pricing plan, and customer. This section also explains how to obtain required Rebilly sandbox IDs and a secret API key. If you have already created these resources, skip this step and continue to Step 1: Create an order.
To complete a payment using a Rebilly payment form:
- An active gateway is required. If you are testing in the sandbox environment, a test payment gateway called
TestProcessor
is already configured. - The ready to payout instruction must be active and configured on the gateway. This setting must be manually configured on the
TestProcessor
gateway. For more information, see set up a payment gateway.
Payment methods that are displayed in the hosted payment form are based on the gateway configuration. For more information, see Set up a payment gateway.
Expand to complete prerequisites
Obtain Rebilly sandbox IDs and secret key
When you first log in to Rebilly, you create an organization as part of the setup process. A default website is created when a new organization is created. For more information, see Organizations and websites.
- Log in or sign up to Rebilly.
- Obtain your organization ID and website ID:
- In the left navigation bar, press Settings .
- In the Management section, press My organization & websites.
- In the Organization details section, note the ID value.
- In the Website section, note the ID value. For more information, see Organizations and websites.
- Obtain your secret API key:
- In the left navigation bar, press Automations .
- In the Development section, press API keys.
- Optionally, if you have not created a secret key:
- In top right of the screen, press Create API key.
- In the API key type section, select Secret.
- Optionally, in the Organizations dropdown, select the organizations that can use the API key.
- Optionally, in the Allowed IPs field, enter the IP addresses that are permitted to use the API key.
- Press Save API key.
- Go to the API keys page.
- Select a secret key and copy the Key value.
Create a product
This API interaction creates a product in your Rebilly sandbox account. For more information, see Create a product.
To create a product you must have your Rebilly website ID, organization ID, and secret API key. For more information, see Prerequisites.
How to use the interactive example
- Enter your organization ID:
- Beneath the Environment field, press
{{server}}
. - Beneath the URL, press Show nested variables, then press Edit.
- In the Value field, enter your organization ID and press Save. For more information, see Obtain Rebilly sandbox IDs and secret key.
- Beneath the Environment field, press
- Enter your secret API key:
- Press Security.
- In the API key field, press
{{SecretApiKey}}
, then press Set value. - In the Value field, enter your secret Rebilly sandbox API key and press Save. For more information, see Obtain Rebilly sandbox IDs and secret key.
- Optionally, to change the product details, press Body.
- Press Send.
In the response, note theid
value. This is the product ID.
Create a pricing plan
This API interaction creates a pricing plan for a product in your Rebilly sandbox account. For more information, see Create a plan.
To create a pricing plan, you must have a product ID. For more information, see Create a product.
How to use the interactive example
- Enter your organization ID:
- Beneath the Environment field, press
{{server}}
. - Beneath the URL, press Show nested variables, then press Edit.
- In the Value field, enter your organization ID and press Save. For more information, see Obtain Rebilly sandbox IDs and secret key.
- Beneath the Environment field, press
- Enter your secret API key:
- Press Security.
- In the API key field, press
{{SecretApiKey}}
, then press Set value. - In the Value field, enter your secret Rebilly sandbox API key and press Save. For more information, see Obtain Rebilly sandbox IDs and secret key.
- Enter a product ID:
- Press Body.
- In the
productId
field, a product ID. For more information, see Create a product. - Optionally, change the plan details.
- Press Send.
In the response, note theid
value. This is the plan ID.
Upsert a customer
This step creates or updates (upserts) a customer with a specified ID. For more information, see Upsert a customer with predefined ID.
How to use the interactive example
- Enter your organization ID:
- Beneath the Environment field, press
{{server}}
. - Beneath the URL, press Show nested variables, then press Edit.
- In the Value field, enter your organization ID and press Save. For more information, see Obtain Rebilly sandbox IDs and secret key.
- Beneath the Environment field, press
- Enter your secret API key:
- Press Security.
- In the API key field, press
{{SecretApiKey}}
, then press Set value. - In the Value field, enter your secret Rebilly sandbox API key and press Save. For more information, see Obtain Rebilly sandbox IDs and secret key.
- Enter a customer ID:
- In the URL field beneath the Environment field, press
{{id}}
. - Press Set value.
- In the Value field, enter a customer ID.
Example:cus_01HDP7FFX2PGDVH1995EA4QY95
.
- In the URL field beneath the Environment field, press
- Enter your website ID:
- Press Body.
- In the
websiteId
, enter your website ID. For more information, see Obtain Rebilly sandbox IDs and secret key. - Optionally, change the customer details.
- Press Send.
In the response, note theid
value. This is the customer ID.
Step 1: Create an order
This step creates a subscription order for the customer you created in the previous step. For more information, see Create an order.
How to use the interactive example
To obtain the required values mentioned in this interactive example, complete the Prerequisites section.
- Enter your organization ID:
- Beneath the Environment field, press
{{server}}
. - Beneath the URL, press Show nested variables, then press Edit.
- In the Value field, enter your organization ID and press Save.
- Beneath the Environment field, press
- Enter your secret API key:
- Press Security.
- In the API key field, press
{{SecretApiKey}}
, then press Set value. - In the Value field, enter your secret Rebilly sandbox API key and press Save.
- Enter the order details:
- Press Body.
- In the
customerId
field, enter a customer ID. - In the
websiteId
field, enter your website ID. - In the
id
field, enter a pricing plan ID.
- Press Send.
- In the response, note the
recentInvoiceId
value. This is used in the next step.
Step 2: Create hosted payment form URL
This step creates a hosted payment form URL where the customer can complete payment for the invoice you created in the previous step. For more information, see Create a transaction.
How to use the interactive example
To obtain the required values mentioned in this interactive example, complete the Prerequisites section.
- Enter your organization ID:
- Beneath the Environment field, press
{{server}}
. - Beneath the URL, press Show nested variables, then press Edit.
- In the Value field, enter your organization ID and press Save.
- Beneath the Environment field, press
- Enter your secret API key:
- Press Security.
- In the API key field, press
{{SecretApiKey}}
, then press Set value. - In the Value field, enter your secret Rebilly sandbox API key and press Save.
- Enter the transaction details:
- In the
customerId
field, enter the customer ID used in Step 1. - In the
websiteId
field, enter the website ID used in Step 1. - In the
invoiceIds
field, enter therecentInvoiceId
value from the response in Step 1: Create an order.
- In the
- Press Send.
- In the response, in the
_links
field, locate theapprovalUrl
value. This is the hosted payment form URL. The customer uses this link to pay for the order using a hosted payment form in Step 3: Complete the payment.
Step 3: Complete the payment
This step completes the payment using the hosted payment form URL obtained in Step 2.
- Open the hosted payment form URL in a web browser.
- Enter this test card number
4111 1111 1111 1111
, with any future expiration date, and any 3 digits for the CVC number.
For more test cards, see Test payment cards, IBANs, and ACH details.