Getting Started With Zuora SDK – The Right Way
Zuora is the ultimate choice when it comes to subscription-based businesses.
And to ease your efforts when using Zuora Billing services, Zuora Software Development Kit (Zuora SDK) is the key. Zuora SDK comes with a language idiomatic programming interface that cuts down on the implementation effort.
Being a user-friendly object model, the edge that you get with Zuora SDK is that you can keep the flexibility of the platform intact and streamline any integration with Zuora.
Zuora SDK for Java: What You Need to Know
The Zuora SDK for Java comprises a set of libraries that can be accessed by Java developers as and when required. The available set of libraries enables you to use Zuora Billing services with utmost ease and comfort. The Zuora SDK for Java is built on an easy-to-use lightweight object model for you to understand each concept faster. With the Zuora SDK, you can make the process of building your applications a breeze.
Here are some recommended objects and methods available in Zuora’s SDK for Java:
- Product, Plan, and Price
- Account and Contact
- Subscription
- Billing Document
- Payment Method, Payment, and Refund
Steps to Install Zuora SDK
You can find the Zuora SDK in the Maven Central repository. All you have to do is add the following code to the dependencies in the pom.xml file of your project. After this step, Zuora SDK becomes available to you:
<dependency>
<groupId>com.zuora.sdk</groupId>
<artifactId>zuora-sdk-java</artifactId>
<version>${version}</version>
</dependency>
Authentication of Zuora SDK
In order to authenticate Zuora SDK, you need to follow the below-mentioned parameters:
- Client ID
- Client Secret
- Endpoint (Base URL)
After this, perform the following steps to complete the authentication process:
- Determine the Base URL for REST Endpoint:
- Create Client ID and Client Secret in Zuora Tenant:
- Incorporate Authentication Parameters in Your Code:
Different Zuora environments have different base URLs. These environment-based variables can be used to manage base URLs. The credentials that you have for various Zuora environments can also be managed easily with the help of these base URLs. Remember, when working with the SDK, you must choose the endpoint base URL that you want to use.
Tenant | Base URL for REST endpoint |
---|---|
US Production | https://rest.zuora.com |
US API Sandbox | https://rest.apisandbox.zuora.com |
US Central Sandbox | https://rest.test.zuora.com |
US Performance Test | https://rest.pt1.zuora.com |
US Cloud Production | https://rest.na.zuora.com |
US Cloud API Sandbox | https://rest.sandbox.na.zuora.com |
EU Production | https://rest.eu.zuora.com |
EU Sandbox | https://rest.sandbox.eu.zuora.com |
EU Central Sandbox | https://rest.test.eu.zuora.com |
To generate Client ID and Client Secret in your Zuora tenant, you can:
a. Create a dedicated user for conducting API calls
b. Create an OAuth client for the user
Add the following snippet to your code to authenticate:
• String CLIENT_ID = "{CLIENT_ID}";
• String CLIENT_SECRET = "{CLIENT_SECRET}";
• String ENDPOINT = "{ENDPOINT_BASE}";
• ZuoraClient zuoraClient = new ZuoraClient(CLIENT_ID, CLIENT_SECRET, ENDPOINT);
Make sure that you include these authentication parameters in your code to finish the process smoothly, without any friction.
Working With Zuora SDK
This section gives insights into the key objects and code samples used in Zuora SDK for some common use cases.
– Create a Product and Plan
– Create a Subscription for an Account
– Edit Contact Information for an Account
– Retrieve Customer’s Subscriptions
– Create Payment Pages
- Retrieve Payment Methods for an Account
- Retrieve Invoices for an Account
- Retrieve Credit Memos for an Account
- Retrieve a Credit Memo
- Add a Product to a Subscription
- Remove a Product from a Subscription
- Renew a Subscription
- Cancel a Subscription
- Update Product Quantity on a Subscription
To redirect all the payment methods that are associated with a user’s account, you can apply the zuoraClient.accounts().getPaymentMethods() code. Here’s an example of how SDK retrieves all payment methods for an account.
Account account = zuoraClient.accounts().get(“A-000001”);
List<PaymentMethod> paymentMethods = account.getPaymentMethods();
Subscribers get the option to view the invoices associated with their accounts, by using the zuoraClient.accounts().getInvoices() code. This retrieves all invoices associated with a customer’s account.
Account account = zuoraClient.accounts().get(“A-000001”);
List<BillingDocument> invoices = account.getInvoices();
In order to enable subscribers to get a hawk-eye view of the credit memos linked with their account, you can use the zuoraClient.billingDocuments().findByAccount() code. This way, you will be able to retrieve all credit memos associated with a customer’s account.
Account account = zuoraClient.accounts().get(“A-000001”);
List<BillingDocument> creditMemos = zuoraClient.billingDocuments()
.findByAccount(account,BillingDocumentType.CREDIT_MEMO);
To extract a credit memo, you can apply the code: zuoraClient.BillingDocuments.get() to (number = “CM00000012”).
Account account = zuoraClient.accounts().get(“A-000001”);
List<Payment> payments = account.getPayments();
If subscribers decide to add a product to their subscription, you need to pick a plan for the product.
ProductCreateRequest productCreateRequest = ProductCreateRequest.builder().name("Gold").build();
Product product = zuoraClient.products().create(productCreateRequest);
Plan plan = zuoraClient.products().getPlan(“Gold Membership Plan”);
plan.getItems().stream().filter(item -> item.getName() == "Gold Monthly Price"). item.setUnitAmounts(Collections.singletonMap(Currency.getInstance("USD"), 200.0));
Subscription subscription = zuoraClient.subscriptions().get(“S00007412”);
Subscription subscription = zuoraClient.subscriptions().addPlan(subscription, plan, LocalDate.now());
In the event where an end subscriber wishes to delete or omit a product from a subscription, they can do it and delete a subscription from the plan using the below-mentioned code:
Subscription subscription = zuoraClient.subscriptions().get(“S00007412”);
List<SubscriptionPlan> subscriptionPlans = zuoraClient.subscriptions()
.get(“S00007412”)
.getSubscriptionPlans();
Subscription subscription = zuoraClient.subscriptions()
.removeSubscriptionPlan(subscription, subscriptionPlans.get(0));
As the expiration date of a subscription approaches, you can request a renewal at the end as its current expiration by applying this code:
Subscription subscription = zuoraClient.subscriptions()
.get(“S00007412”);
subscription = zuoraClient.subscriptions().renew(subscription.getId());
In this use case, if a subscriber wants to cancel their subscription, they can use this code:
Subscription subscription = zuoraClient.subscriptions()
.get(“S00007412”);
Subscription subscription = zuoraClient.subscriptions().cancel(subscription);
You can update the subscription product quantity or quality. But a customer can do this only when the product’s price is not an average price, flat fee, or a discount.
Subscription subscription = zuoraClient.subscriptions().get(“S00007412”);
SubscriptionItem subscriptionItem = subscriptions.getSubscriptionPlans().get(0).getItems().get(0);
SubscriptionItemRequest subscriptionItemRequest = subscriptionItem.toBuilder().setQuantity(60.0).build();
Subscription subscription = zuoraClient.subscriptions().updateSubscriptionItem(subscription, subscriptionItemRequest, LocalDate.now());
Wrapping Up
Zuora enables you to plug your platform into your tech stack with ease. With SDKs in your corner, you can eliminate friction, developers can spend less time configuring and more time executing. In this article, we looked at how to integrate with Zuora’s SDK so that you can make developing with Zuora a breeze.
Need assistance leveraging Zuora SDK the right way? Feel free to drop us a line at [email protected] and we’ll take it from there.