square

package module
v0.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

README

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

Documentation

Index

Constants

View Source
const (
	ENV_SANDBOX    = Sandbox("https://connect.squareupsandbox.com")
	ENV_PRODUCTION = Production("https://connect.squareup.com")
)

Variables

View Source
var Environments = struct {
	Sandbox    Sandbox
	Production Production
}{
	Sandbox:    ENV_SANDBOX,
	Production: ENV_PRODUCTION,
}

Environment has part of the domain that varies with the environment.

Functions

This section is empty.

Types

type Config

type Config[T Env] struct {
	AccessToken string
	Environment T
}

Config struct contains access token and environment

type Env

type Env interface {
	Sandbox | Production
}

Environment has part of the domain that varies with the environment.

type Production

type Production string

type Sandbox

type Sandbox string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL