Skip to content

KoeInoue/square-go-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Square Go SDK

go license star Go Test

Tags

go square

Installation

go install github.com/KoeInoue/square-go-sdk

or

import the package in a file where you want to use the package

import "github.com/KoeInoue/square-go-sdk"

then run

go mod tidy

Minimal Example

  1. Set environment variables
export SQUARE_ACCESS_TOKEN=yourSandboxAccessToken
export ENV=dev

※ ENV is a variable that just identifies the environment

  1. Write code
package main

import (
    "os"

    "github.com/KoeInoue/square-go-sdk"
    "github.com/KoeInoue/square-go-sdk/http"
    "github.com/KoeInoue/square-go-sdk/models"
)

func main() {
    client := getClient()
    client.CustomerApi.CreateCustomer()
}

func getClient() *http.Client {
    envType := os.Getenv("ENV")
    accessToken := os.Getenv("SQUARE_ACCESS_TOKEN")

    if envType != "production" {
        return http.NewClient(square.Config[square.Sandbox]{
            AccessToken: accessToken,
            Environment: square.Environments.Sandbox,
        })
    } else {
        return http.NewClient(square.Config[square.Production]{
            AccessToken: accessToken,
            Environment: square.Environments.Production,
        })
    }
}

SDK Reference

Payments

Subscriptions

Item

Customers

Contributors