Skip to content

cashfree/cashfree-pg-sdk-dotnet

Cashfree PG .Net SDK

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

The Cashfree PG .Net SDK offers a convenient solution to access Cashfree PG APIs from a server-side .Net 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

dotnet add package cashfree_pg

Configuration

using cashfree_pg.Client;
using cashfree_pg.Model;

Cashfree.XClientId = "<x-client-id>";
Cashfree.XClientSecret = "<x-client-secret>";
Cashfree.XEnvironment = Cashfree.SANDBOX;
var cashfree = new Cashfree();
var xApiVersion = "2022-09-01";

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

Basic Usage

Create Order

var customerDetails = new CustomerDetails("walterwNrcMi", null, "9999999999");
var createOrdersRequest = new CreateOrderRequest(null, 1.0, "INR", customerDetails);
try {
    // Create Order
    var result = cashfree.PGCreateOrder(xApiVersion, createOrdersRequest, null, null, null);
    Console.WriteLine(result);
    Console.WriteLine(result.StatusCode);
    Console.WriteLine((result.Content as OrderEntity));
} catch (ApiException e) {
    Console.WriteLine("Exception when calling PGCreateOrder: " + e.Message);
    Console.WriteLine("Status Code: " + e.ErrorCode);
    Console.WriteLine(e.StackTrace);
}

Get Order

try {
    var result = cashfree.PGFetchOrder(xApiVersion, "<order_id>>", null, null);
    Console.WriteLine(result);
    Console.WriteLine(result.StatusCode);
    Console.WriteLine((result.Content as OrderEntity));
} catch (ApiException e) {
    Console.WriteLine("Exception when calling PGFetchOrder: " + e.Message);
    Console.WriteLine("Status Code: " + e.ErrorCode);
    Console.WriteLine(e.StackTrace);
}

Licence

Apache Licensed. See LICENSE.md for more details