The Cashfree PG Java SDK offers a convenient solution to access Cashfree PG APIs from a server-side Java applications.
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 !
- 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>
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
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);
}
Apache Licensed. See LICENSE.md for more details