Java
Latest commit 4768623 Jan 10, 2017 @ankit-rzp ankit-rzp committed on GitHub Update README
Updating with the new version
Permalink
Failed to load latest commit information.
src/main/java/com/razorpay [Invoice API] Dec 3, 2016
.gitignore Update Readme File Nov 7, 2016
LICENSE.txt Add MIT License Nov 8, 2016
README.md Update README Jan 10, 2017
pom.xml [Invoice API] Upgrading version Dec 3, 2016

README.md

Razorpay Java SDK

Official java bindings for the Razorpay API.

Documentation

Documentation of Razorpay's API and their usage is available at https://docs.razorpay.com

Requirements

Java 1.7 or later

Installation

Maven users

Add this dependency to your project's POM:

<dependency>
<groupId>com.razorpay</groupId>
<artifactId>razorpay-java</artifactId>
<version>1.1.0</version>
</dependency>

Gradle users

Add this dependency to your project's build file:

compile "com.razorpay:razorpay-java:1.1.0"

Usage

Instantiate RazorpayClient with key_id & key_secret. You can obtain the keys from the dashboard app https://dashboard.razorpay.com/#/app/keys

// Initialize client
RazorpayClient razorpayClient = new RazorpayClient("key_id", "key_secret");

Payments

  • Fetch all payments
List<Payment> payments = razorpayClient.Payments.fetchAll();
  • Fetch a particular payment:
Payment payment = razorpayClient.Payments.fetch("payment_id");
// The the Entity.get("attribute_key") method has flexible return types depending on the attribute
int amount = payment.get("amount");
String id = payment.get("id");
Date createdAt = payment.get("created_at");
  • Capturing a payment:
JSONObject options = new JSONObject();
options.put("amount", 1000);
razorpayClient.Payments.capture("payment_id", options);
// Note: Amount should be same as the original amount while creating the payment. The amount should be in paise.
  • Refund a payment:
// For full refunds
Refund refund = razorpayClient.Payments.refund("payment_id");

// For partial refunds
JSONObject refundRequest = new JSONObject();
refundRequest.put("amount", 100);
Refund refund = razorpay.Payments.refund("payment_id", refundRequest);
// Note: Amount to be refunded should be less than or equal to the original amount.The amount should be in paise.
  • Fetch all refunds for a payment:
List<Refund> refund = razorpayClient.Payments.fetchAllRefunds("payment_id");
  • Fetch refund for a payment:
Refund refund = razorpayClient.Payments.fetchRefund("payment_id", "refund_id");

Refunds

  • Fetch all refunds:
List<Refund> refunds = razorpayClient.Refunds.fetchAll();
  • Fetch a particular refund:
Refund refund = razorpayClient.Refunds.fetch("refund_id");

Orders

  • Create a new order:
JSONObject options = new JSONObject();
options.put("amount", 5000); // Note: The amount should be in paise.
options.put("currency", "INR");
options.put("receipt", "txn_123456");
Order order = razorpayClient.Orders.create(options);
  • Fetch a particular order:
Order order = razorpayClient.Orders.fetch("order_id");
  • Fetch all orders:
List<Order> orders = razorpayClient.Orders.fetchAll();
  • Fetch payments for an order:
List<Payment> payments = razorpayClient.Orders.fetchPayments("order_id");

Invoices

  • Create a new invoice:
JSONObject lineItem = new JSONObject();
lineItem.put("amount", 100); // Note: The amount should be in paise.
lineItem.put("name", "name_invoice");

JSONArray lineItems = new JSONArray();
lineItems.put(lineItem);

JSONObject request = new JSONObject();
request.put("line_items", lineItems);
request.put("date", 1480768625); // Timestamp in seconds
request.put("currency", "INR");
request.put("sms_notify", "0"); 

Invoice invoice = razorpayClient.Invoices.create(request);
  • Fetch a particular invoice:
Invoice invoice = razorpayClient.Invoices.fetch("invoice_id");
  • Fetch all invoices:
List<Invoice> invoices = razorpayClient.Invoices.fetchAll();