Skip to content

Latest commit

 

History

History
83 lines (65 loc) · 2.88 KB

README.md

File metadata and controls

83 lines (65 loc) · 2.88 KB

Cashfree PG Java SDK

GitHub Discord GitHub last commit (branch) GitHub release (with filter) GitHub forks Coverage Status

The Cashfree PG Java SDK offers a convenient solution to access Cashfree PG APIs from a server-side Java applications.

Documentation

Cashfree's PG API Documentation - https://docs.cashfree.com/reference/pg-new-apis-endpoint

Learn and understand payment gateway workflows at Cashfree Payments here

Try out our interactive guides at Cashfree Dev Studio !

Getting Started

Installation

  • Gradle Project
implementation `com.cashfree.pg.java:cashfree_pg:4.2.4`
  • Maven Project
<dependency>
  <groupId>com.cashfree.pg.java</groupId>
  <artifactId>cashfree_pg</artifactId>
  <version>4.2.4</version>
  <scope>compile</scope>
</dependency>
<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>4.10.0</version>
</dependency>

Configuration

import com.cashfree.*;

Cashfree.XClientId = "<x-client-id>";
Cashfree.XClientSecret = "<x-client-secret>";
Cashfree.XEnvironment = Cashfree.SANDBOX;

Cashfree cashfree = new Cashfree();
String xApiVersion = "2022-09-01";

Generate your API keys (x-client-id , x-client-secret) from Cashfree Merchant Dashboard

Basic Usage

Create Order

CustomerDetails customerDetails = new CustomerDetails();
customerDetails.setCustomerId("walterwNrcMi");
customerDetails.setCustomerPhone("9999999999");

CreateOrderRequest request = new CreateOrderRequest();
request.setOrderAmount(1.0);
request.setOrderCurrency("INR");
request.setCustomerDetails(customerDetails);
try {
    ApiResponse<OrderEntity> response = cashfree.PGCreateOrder(xApiVersion, request, null, null, null);
    System.out.println(response.getData().getOrderId());
} catch (ApiException e) {
    throw new RuntimeException(e);
}

Get Order

try {
    ApiResponse<OrderEntity> responseFetchOrder = cashfree.PGFetchOrder(xApiVersion, "<order_id>", null, null, null);
    System.out.println(response.getData().getOrderId());
} catch (ApiException e) {
    throw new RuntimeException(e);
}

Licence

Apache Licensed. See LICENSE.md for more details