Skip to content

Latest commit

 

History

History
188 lines (149 loc) · 26.6 KB

README.md

File metadata and controls

188 lines (149 loc) · 26.6 KB

Orders

(Orders)

Overview

Collection of APIs to create, accept payments and refund for an order.

Available Operations

Create

Order

An order is an entity which has a amount and currency associated with it. It is something for which you want to collect payment for. Use this API to create orders with Cashfree from your backend to get a payment_sessions_id. You can use the payment_sessions_id to create a transaction for the order.

Example Usage

package main

import(
	"github.com/speakeasy-sdks/cashfree-go/pkg/models/shared"
	cashfreego "github.com/speakeasy-sdks/cashfree-go"
	"context"
	"log"
)

func main() {
    s := cashfreego.New(
        cashfreego.WithSecurity(shared.Security{
            Option1: &shared.SecurityOption1{
                XClientID: "<YOUR_API_KEY_HERE>",
                XClientSecret: "<YOUR_API_KEY_HERE>",
            },
        }),
    )


    var xAPIVersion string = "2022-09-01"

    createOrderBackendRequest := &shared.CreateOrderBackendRequest{
        CustomerDetails: shared.CustomerDetails{
            CustomerBankAccountNumber: cashfreego.String("1518121112"),
            CustomerBankCode: cashfreego.Float64(3333),
            CustomerBankIfsc: cashfreego.String("XITI0000001"),
            CustomerEmail: cashfreego.String("john@cashfree.com"),
            CustomerID: "7112AAA812234",
            CustomerName: cashfreego.String("John Doe"),
            CustomerPhone: "9908734801",
        },
        OrderAmount: 10.15,
        OrderCurrency: "INR",
        OrderExpiryTime: cashfreego.String("2021-07-02T10:20:12+05:30"),
        OrderMeta: &shared.OrderMeta{
            NotifyURL: cashfreego.String("https://b8af79f41056.eu.ngrok.io/webhook.php"),
            ReturnURL: cashfreego.String("https://b8af79f41056.eu.ngrok.io?order_id={order_id}"),
        },
        OrderNote: cashfreego.String("Test order"),
        OrderTags: map[string]string{
            "product": "Laptop",
            "shipping_address": "123 Main St",
        },
        Terminal: &shared.TerminalDetails{
            TerminalID: "1",
            TerminalPhoneNo: "6309291183",
            TerminalType: "SPOS",
        },
    }

    var xIdempotencyKey *string = cashfreego.String("<value>")

    var xRequestID *string = cashfreego.String("<value>")

    ctx := context.Background()
    res, err := s.Orders.Create(ctx, xAPIVersion, createOrderBackendRequest, xIdempotencyKey, xRequestID)
    if err != nil {
        log.Fatal(err)
    }
    if res.OrdersEntity != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
xAPIVersion string ✔️ API version to be used. Format is in YYYY-MM-DD
createOrderBackendRequest *shared.CreateOrderBackendRequest Request body to create an order at cashfree
xIdempotencyKey *string Idempotency works by saving the resulting status code and body of the first request made for any given idempotency key, regardless of whether it succeeded or failed. Subsequent requests with the same key return the same result, including 500 errors.

Currently supported on all POST calls that uses x-client-id & x-client-secret. To use enable, pass x-idempotency-key in the request header. The value of this header must be unique to each operation you are trying to do. One example can be to use the same order_id that you pass while creating orders
xRequestID *string Request id for the API call. Can be used to resolve tech issues. Communicate this in your tech related queries to cashfree
opts []operations.Option The options for this request.

Response

*operations.CreateOrderResponse, error

Error Object Status Code Content Type
sdkerrors.BadRequestError 400 application/json
sdkerrors.AuthenticationError 401 application/json
sdkerrors.APIError404 404 application/json
sdkerrors.APIError409 409 application/json
sdkerrors.IdempotencyError 422 application/json
sdkerrors.RateLimitError 429 application/json
sdkerrors.APIError 500 application/json
sdkerrors.SDKError 4xx-5xx /

Get

Use this API to fetch the order that was created at Cashfree's using the order_id.

When to use this API

  • To check the status of your order
  • Once the order is PAID
  • Once your customer returns to return_url

Example Usage

package main

import(
	"github.com/speakeasy-sdks/cashfree-go/pkg/models/shared"
	cashfreego "github.com/speakeasy-sdks/cashfree-go"
	"context"
	"log"
)

func main() {
    s := cashfreego.New(
        cashfreego.WithSecurity(shared.Security{
            Option1: &shared.SecurityOption1{
                XClientID: "<YOUR_API_KEY_HERE>",
                XClientSecret: "<YOUR_API_KEY_HERE>",
            },
        }),
    )


    var orderID string = "<value>"

    var xAPIVersion string = "2022-09-01"

    var xRequestID *string = cashfreego.String("<value>")

    ctx := context.Background()
    res, err := s.Orders.Get(ctx, orderID, xAPIVersion, xRequestID)
    if err != nil {
        log.Fatal(err)
    }
    if res.OrdersEntity != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
orderID string ✔️ The order or invoice ID for which you want to view the order details.
xAPIVersion string ✔️ API version to be used. Format is in YYYY-MM-DD
xRequestID *string Request id for the API call. Can be used to resolve tech issues. Communicate this in your tech related queries to cashfree
opts []operations.Option The options for this request.

Response

*operations.GetOrderResponse, error

Error Object Status Code Content Type
sdkerrors.BadRequestError 400 application/json
sdkerrors.AuthenticationError 401 application/json
sdkerrors.APIError404 404 application/json
sdkerrors.APIError409 409 application/json
sdkerrors.IdempotencyError 422 application/json
sdkerrors.RateLimitError 429 application/json
sdkerrors.APIError 500 application/json
sdkerrors.SDKError 4xx-5xx /