Skip to content

Latest commit

 

History

History
133 lines (105 loc) · 4.89 KB

README.md

File metadata and controls

133 lines (105 loc) · 4.89 KB

Contributors Forks Stargazers Issues Go Reference Go Report Card Apache 2.0 License Workflow


Smartpay Go SDK

Smartpay Go SDK offers easy access to Smartpay API from applications written in Go.

Prerequisites

Go v1.18+

Installation

go get github.com/smartpay-co/sdk-go

Usage

Let's give a quick example first about how to create a new checkout session.

package main

import (
	"context"
	"fmt"
	. "github.com/smartpay-co/sdk-go"
)

func main() {
	ctx := context.Background()
	client, _ := NewClientWithResponses("<YOUR_SECRET_KEY>", "<YOUR_PUBLIC_KEY>")

	checkoutPayload := CreateACheckoutSessionJSONRequestBody{
		Currency: CurrencyJPY,
		Amount:   350,
		Items: []Item{
			{Name: "レブロン 18 LOW", Amount: 1000, Currency: CurrencyJPY, Quantity: Ptr(1)},
			{Name: "discount", Amount: 100, Currency: CurrencyJPY, Kind: Ptr(LineItemKindDiscount)},
			{Name: "tax", Amount: 250, Currency: CurrencyJPY, Kind: Ptr(LineItemKindTax)},
		},
		ShippingInfo: ShippingInfo{
			Address:     Address{Country: AddressCountryJP, PostalCode: "123", Locality: "locality", Line1: "line1"},
			FeeAmount:   Ptr(float32(100)),
			FeeCurrency: Ptr(CurrencyJPY),
		},
		CaptureMethod: Ptr(CaptureMethodManual),
		Reference:     Ptr("order_ref_1234567"),
		SuccessUrl:    "https://smartpay.co",
		CancelUrl:     "https://smartpay.co",
	}

	result, err := client.CreateACheckoutSessionWithResponse(ctx, checkoutPayload)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(result.Body))
}

Initialize A New Client

You need to get your API key to initialize a new client. You can find it on your dashboard.

You can also customize the client by passing function options into the constructors.

client, _ := NewClientWithResponses("<SECRET_KEY>", WithHTTPClient(&httpClient), WithBaseURL("http://localhost:9000"))

Invoke an API Point

Our clients supprts struct parameters and responses for API calls. In most cases you'll be satisfied with this method. Take the example from above, CreateACheckoutSessionWithResponse is so much easier to use with the predefined request and response objects.

But if you want full control for maximium flexibility, then you can use CreateACheckoutSessionWithBody and handle the request and response on your own.

This design applies to all our APIs.

License

Distributed under the MIT License. See LICENSE.txt for more information.