GithubHelp home page GithubHelp logo

sdk-go's Introduction

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.

sdk-go's People

Contributors

dependabot[bot] avatar hsatac avatar othree avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.