Skip to content

speakeasy-sdks/cashfree-go

Repository files navigation

Go SDK

Payments infrastructure for India

SDK Installation

go get github.com/speakeasy-sdks/cashfree-go

SDK Example Usage

Example

package main

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

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

	var customerID string = "<value>"

	var instrumentID string = "<value>"

	var xAPIVersion string = "2022-09-01"

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

	ctx := context.Background()
	res, err := s.TokenVault.DeleteSavedInstrument(ctx, customerID, instrumentID, xAPIVersion, xRequestID)
	if err != nil {
		log.Fatal(err)
	}
	if res.FetchAllSavedInstruments != nil {
		// handle response
	}
}

Available Resources and Operations

  • Cancel - Cancel Payment Link
  • Create - Create Payment Link
  • Fetch - Fetch Payment Link Details
  • GetOrders - Get Orders for a Payment Link
  • Create - Create Offer
  • Get - Get Offer by ID
  • Get - PG Reconciliation

Special Types

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or an error, they will never return both. When specified by the OpenAPI spec document, the SDK will return the appropriate subclass.

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.APIError502 502 application/json
sdkerrors.SDKError 4xx-5xx /

Example

package main

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

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

	var customerID string = "<value>"

	var instrumentID string = "<value>"

	var xAPIVersion string = "2022-09-01"

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

	ctx := context.Background()
	res, err := s.TokenVault.DeleteSavedInstrument(ctx, customerID, instrumentID, xAPIVersion, xRequestID)
	if err != nil {

		var e *sdkerrors.BadRequestError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *sdkerrors.AuthenticationError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *sdkerrors.APIError404
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *sdkerrors.APIError409
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *sdkerrors.IdempotencyError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *sdkerrors.RateLimitError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *sdkerrors.APIError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *sdkerrors.APIError502
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}

		var e *sdkerrors.SDKError
		if errors.As(err, &e) {
			// handle error
			log.Fatal(e.Error())
		}
	}
}

Server Selection

Select Server by Index

You can override the default server globally using the WithServerIndex option when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:

# Server Variables
0 https://sandbox.cashfree.com/pg None
1 https://api.cashfree.com/pg None

Example

package main

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

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

	var customerID string = "<value>"

	var instrumentID string = "<value>"

	var xAPIVersion string = "2022-09-01"

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

	ctx := context.Background()
	res, err := s.TokenVault.DeleteSavedInstrument(ctx, customerID, instrumentID, xAPIVersion, xRequestID)
	if err != nil {
		log.Fatal(err)
	}
	if res.FetchAllSavedInstruments != nil {
		// handle response
	}
}

Override Server URL Per-Client

The default server can also be overridden globally using the WithServerURL option when initializing the SDK client instance. For example:

package main

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

func main() {
	s := cashfreego.New(
		cashfreego.WithServerURL("https://sandbox.cashfree.com/pg"),
		cashfreego.WithSecurity(shared.Security{
			Option1: &shared.SecurityOption1{
				XClientID:     "<YOUR_API_KEY_HERE>",
				XClientSecret: "<YOUR_API_KEY_HERE>",
			},
		}),
	)

	var customerID string = "<value>"

	var instrumentID string = "<value>"

	var xAPIVersion string = "2022-09-01"

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

	ctx := context.Background()
	res, err := s.TokenVault.DeleteSavedInstrument(ctx, customerID, instrumentID, xAPIVersion, xRequestID)
	if err != nil {
		log.Fatal(err)
	}
	if res.FetchAllSavedInstruments != nil {
		// handle response
	}
}

Custom HTTP Client

The Go SDK makes API calls that wrap an internal HTTP client. The requirements for the HTTP client are very simple. It must match this interface:

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

The built-in net/http client satisfies this interface and a default client based on the built-in is provided by default. To replace this default with a client of your own, you can implement this interface yourself or provide your own client configured as desired. Here's a simple example, which adds a client with a 30 second timeout.

import (
	"net/http"
	"time"
	"github.com/myorg/your-go-sdk"
)

var (
	httpClient = &http.Client{Timeout: 30 * time.Second}
	sdkClient  = sdk.New(sdk.WithClient(httpClient))
)

This can be a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration.

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a RetryConfig object to the call by using the WithRetries option:

package main

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

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

	var customerID string = "<value>"

	var instrumentID string = "<value>"

	var xAPIVersion string = "2022-09-01"

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

	ctx := context.Background()
	res, err := s.TokenVault.DeleteSavedInstrument(ctx, customerID, instrumentID, xAPIVersion, xRequestID, operations.WithRetries(
		utils.RetryConfig{
			Strategy: "backoff",
			Backoff: &utils.BackoffStrategy{
				InitialInterval: 1,
				MaxInterval:     50,
				Exponent:        1.1,
				MaxElapsedTime:  100,
			},
			RetryConnectionErrors: false,
		}))
	if err != nil {
		log.Fatal(err)
	}
	if res.FetchAllSavedInstruments != nil {
		// handle response
	}
}

If you'd like to override the default retry strategy for all operations that support retries, you can use the WithRetryConfig option at SDK initialization:

package main

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

func main() {
	s := cashfreego.New(
		cashfreego.WithRetryConfig(
			utils.RetryConfig{
				Strategy: "backoff",
				Backoff: &utils.BackoffStrategy{
					InitialInterval: 1,
					MaxInterval:     50,
					Exponent:        1.1,
					MaxElapsedTime:  100,
				},
				RetryConnectionErrors: false,
			}),
		cashfreego.WithSecurity(shared.Security{
			Option1: &shared.SecurityOption1{
				XClientID:     "<YOUR_API_KEY_HERE>",
				XClientSecret: "<YOUR_API_KEY_HERE>",
			},
		}),
	)

	var customerID string = "<value>"

	var instrumentID string = "<value>"

	var xAPIVersion string = "2022-09-01"

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

	ctx := context.Background()
	res, err := s.TokenVault.DeleteSavedInstrument(ctx, customerID, instrumentID, xAPIVersion, xRequestID)
	if err != nil {
		log.Fatal(err)
	}
	if res.FetchAllSavedInstruments != nil {
		// handle response
	}
}

Authentication

Per-Client Security Schemes

This SDK supports multiple security scheme combinations globally. You can choose from one of the alternatives by using the WithSecurity option when initializing the SDK client instance. The selected option will be used by default to authenticate with the API for all operations that support it.

Option1

All of the following schemes must be satisfied to use the Option1 alternative:

Name Type Scheme
XClientID apiKey API key
XClientSecret apiKey API key

Example:

package main

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

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

	var customerID string = "<value>"

	var instrumentID string = "<value>"

	var xAPIVersion string = "2022-09-01"

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

	ctx := context.Background()
	res, err := s.TokenVault.DeleteSavedInstrument(ctx, customerID, instrumentID, xAPIVersion, xRequestID)
	if err != nil {
		log.Fatal(err)
	}
	if res.FetchAllSavedInstruments != nil {
		// handle response
	}
}

Option2

All of the following schemes must be satisfied to use the Option2 alternative:

Name Type Scheme
XClientID apiKey API key
XPartnerAPIKey apiKey API key

Example:

package main

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

func main() {
	s := cashfreego.New(
		cashfreego.WithSecurity(shared.Security{
			Option2: &shared.SecurityOption2{
				XClientID:      "<YOUR_API_KEY_HERE>",
				XPartnerAPIKey: "<YOUR_API_KEY_HERE>",
			},
		}),
	)

	var customerID string = "<value>"

	var instrumentID string = "<value>"

	var xAPIVersion string = "2022-09-01"

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

	ctx := context.Background()
	res, err := s.TokenVault.DeleteSavedInstrument(ctx, customerID, instrumentID, xAPIVersion, xRequestID)
	if err != nil {
		log.Fatal(err)
	}
	if res.FetchAllSavedInstruments != nil {
		// handle response
	}
}

Option3

All of the following schemes must be satisfied to use the Option3 alternative:

Name Type Scheme
XClientID apiKey API key
XClientSignatureHeader apiKey API key

Example:

package main

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

func main() {
	s := cashfreego.New(
		cashfreego.WithSecurity(shared.Security{
			Option3: &shared.SecurityOption3{
				XClientID:              "<YOUR_API_KEY_HERE>",
				XClientSignatureHeader: "<YOUR_API_KEY_HERE>",
			},
		}),
	)

	var customerID string = "<value>"

	var instrumentID string = "<value>"

	var xAPIVersion string = "2022-09-01"

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

	ctx := context.Background()
	res, err := s.TokenVault.DeleteSavedInstrument(ctx, customerID, instrumentID, xAPIVersion, xRequestID)
	if err != nil {
		log.Fatal(err)
	}
	if res.FetchAllSavedInstruments != nil {
		// handle response
	}
}

Option4

All of the following schemes must be satisfied to use the Option4 alternative:

Name Type Scheme
XPartnerAPIKey apiKey API key
XPartnerMerchantID apiKey API key

Example:

package main

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

func main() {
	s := cashfreego.New(
		cashfreego.WithSecurity(shared.Security{
			Option4: &shared.SecurityOption4{
				XPartnerAPIKey:     "<YOUR_API_KEY_HERE>",
				XPartnerMerchantID: "<YOUR_API_KEY_HERE>",
			},
		}),
	)

	var customerID string = "<value>"

	var instrumentID string = "<value>"

	var xAPIVersion string = "2022-09-01"

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

	ctx := context.Background()
	res, err := s.TokenVault.DeleteSavedInstrument(ctx, customerID, instrumentID, xAPIVersion, xRequestID)
	if err != nil {
		log.Fatal(err)
	}
	if res.FetchAllSavedInstruments != nil {
		// handle response
	}
}

Maturity

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!

SDK Created by Speakeasy