Forpay SDK for Go
Installing
Use go get
to retrive the SDK to add it to your GOPATH
workspace, or project's go module dependencies.
go get github.com/forpay/forpay-sdk-go/forpay
To update the SDK use go get -u to retrieve the latest version of the SDK.
go get -u github.com/forpay/forpay-sdk-go/forpay
Quick Start
package main
import (
"fmt"
"github.com/forpay/forpay-sdk-go/forpay"
"github.com/forpay/forpay-sdk-go/forpay/response"
)
var client *forpay.Client
func main() {
var err error
// Prepare required variables.
appID := "00000000"
keyID := "00000000000000000000000000000000"
keyFile := "./priv.pem"
// Create forpay sdk client instance.
client, err = forpay.NewClientWithRSA(appID, keyID, keyFile)
if err != nil {
panic(err)
}
// Prepare required request parameters.
currencyID := uint16(1)
walletID := uint64(8888888888888888)
// Create request using `CreateXXXRequest` funcs.
req := forpay.CreateGetBalanceRequest(walletID, currencyID)
// Send request and receive response.
resp, err := client.GetBalance(req)
if err != nil {
// Check if the error is `*response.Error`.
if e, ok := err.(*response.Error); ok {
fmt.Println(e.Error())
// You can handle specific errors according to the following info.
// fmt.Println(e.HTTPStatus)
// fmt.Println(e.IsBusinessFailed())
// fmt.Println(e.Code)
// fmt.Println(e.Msg)
// fmt.Println(e.SubCode)
// fmt.Println(e.SubMsg)
} else {
fmt.Println(err)
}
return
}
// Handle response.
fmt.Printf("CurrencyID: %d\n", resp.Data.CurrencyID)
fmt.Printf("Available: %v\n", resp.Data.Available)
fmt.Printf("Frozen: %v\n", resp.Data.Frozen)
fmt.Printf("Locked %v\n", resp.Data.Locked)
}
License
This SDK is distributed under the Apache License, Version 2.0.