Skip to content

craftgate/craftgate-go-client

Repository files navigation

Craftgate Go Client

Build Status

This repo contains the Go library for Craftgate API.

Requirements

  • Go 1.19 or newer

Installation

go get github.com/craftgate/craftgate-go-client

Usage

You can import Craftgate client using:

import (
    craftgate "github.com/craftgate/craftgate-go-client/adapter"
)

To access the Craftgate API you'll first need to obtain API credentials (e.g. an API key and a secret key). If you don't already have a Craftgate account, you can signup at https://craftgate.io

Once you've obtained your API credentials, you can start using Craftgate by instantiating a Craftgate with your credentials.

client, _ := craftgate.New("<YOUR API KEY>", "<YOUR SECRET KEY>", "https://api.craftgate.io")

request := craftgate.SearchInstallmentsRequest{
    BinNumber: "487074",
    Price:     100,
    Currency:  craftgate.Currency_TRY,
}

res, err := client.Installment.SearchInstallments(context.Background(), request)

if err != nil {
    t.Errorf("Error %s", err)
}

Also, you can pass the options to make localization for API responses. You can use tr or en right now.

client, _ := craftgate.New("<YOUR API KEY>", "<YOUR SECRET KEY>", "https://api.craftgate.io", craftgate.WithLocalization("en"))

request := craftgate.SearchInstallmentsRequest{
    BinNumber: "487074",
    Price:     100,
    Currency:  craftgate.Currency_TRY,
}

res, err := client.Installment.SearchInstallments(context.Background(), request)

if err != nil {
    t.Errorf("Error %s", err)
}

You should use production API servers at https://api.craftgate.io for real world. For testing purposes, please use the sandbox URL https://sandbox-api.craftgate.io.

Examples

Included in the project are a number of examples that cover almost all use-cases. Refer to the tests/ folder] for more info.

Running the Examples

If you've cloned this repo on your development machine and wish to run the examples you can run an example with the command go test ./... or run single test with the command go test tests/installment_test.go

Credit Card Payment Use Case

Let's quickly review an example where we implement a credit card payment scenario.

For more examples covering almost all use-cases, check out the examples in the tests/ folder

client, _ := craftgate.New("<YOUR API KEY>", "<YOUR SECRET KEY>", "https://sandbox-api.craftgate.io");

request := craftgate.CreatePaymentRequest{
    Price:     100,
    PaidPrice: 100,
    Currency:  craftgate.Currency_TRY,
    ...
}

res, err := client.Payment.CreatePayment(context.Background(), request)

if err != nil {
    t.Errorf("Error %s", err)
}

Contributions

For all contributions to this client please see the contribution guide here.

License

MIT