The Cashfree PG Go SDK offers a convenient solution to access Cashfree PG APIs from a server-side Go 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 !
go get github.com/cashfree/cashfree-pg/v4
import (
cashfree "github.com/cashfree/cashfree-pg/v4"
)
clientId := "<x-client-id>"
clientSecret := "<x-client-secret>"
cashfree.XClientId = &clientId
cashfree.XClientSecret = &clientSecret
cashfree.XEnvironment = cashfree.SANDBOX
Generate your API keys (x-client-id , x-client-secret) from Cashfree Merchant Dashboard
Create Order
returnUrl := "https://www.cashfree.com/devstudio/preview/pg/web/checkout?order_id={order_id}"
request := cashfree.CreateOrderRequest{
OrderAmount: 1.0,
OrderCurrency: "INR",
CustomerDetails: cashfree.CustomerDetails{
CustomerId: "walterwNrcMi",
CustomerPhone: "9999999999",
},
OrderMeta: &cashfree.OrderMeta{
ReturnUrl: &returnUrl,
},
}
version := "2022-09-01"
response, httpResponse, err := cashfree.PGCreateOrder(&version, &request, nil, nil, nil)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(httpResponse.StatusCode)
fmt.Println(response)
}
Get Order
version := "2022-09-01"
response, httpResponse, err := cashfree.PGFetchOrder(&version, "<order_id>", nil, nil, nil)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(httpResponse.StatusCode)
fmt.Println(response)
}
Apache Licensed. See LICENSE.md for more details