Smartpay Go SDK offers easy access to Smartpay API from applications written in Go.
Go v1.18+
go get github.com/smartpay-co/sdk-go
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))
}
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"))
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.
Distributed under the MIT License. See LICENSE.txt
for more information.