sdk_go

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 9 Imported by: 0

README

Go PSPark SDK usage

You should have jwt-key and api-key keys to be able to use our API via this SDK. jwt-key is a CSR file.

Generating a CSR file

A Certificate Signing Request (.csr) file is required to authenticate an API user and to get your API-Key. The .csr file contains your API public key that will be used to validate the request signature. To generate your RSA 4096 private key (stored in pspakr_secret.key) for signing requests, use the following command line:

openssl req -new -newkey rsa:4096 -nodes -keyout pspakr_secret.key -out pspark_public_key.csr

Make sure you keep the API secret key (pspark_secret.key) safe and secure. Do not share your API secret key with anyone. To get your API-key you should upload your pspark_public_key in the cabinet.pspark.io.

Installation

To install the Go SDK, you can use go get:

go get github.com/pspark/sdk-go

Request examples

Bellow shown a simple example of SDK usage.

import (
  "fmt"
  "log"
  sdk_go "github.com/ps-park/sdk-go"
)

client := sdk_go.PSParkClient(jwtKey, apiKey)

balances, err := client.GetBalances()
if err != nil {
    log.Fatal(err)
}

fmt.PrintLn(balances)

Validation errors

The API doesn't implement all RESTFull API requirements and has its own response structure.

All HTTP responses from the server will have 200 status code. So, if your request will have some validation errors, the code, and it's description will be presented in the response body as shown bellow.

Response Example

{
  "code": 1002,
  "message": "error description",
  "data": {
    //... some data
  }
}

Each time when the server's response will have some validation errors, the SDK will throw ResponseValidationError.

Documentation

Index

Constants

View Source
const (
	BaseURL             = "https://api.pspark.io"
	APIVersion          = "v1"
	TokenExpirationTime = 30
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressRequest

type AddressRequest struct {
	Reference   string  `json:"reference"`
	Title       *string `json:"title,omitempty"`
	Description *string `json:"description,omitempty"`
	LimitMinute *int    `json:"limit_minute,omitempty"`
	CallbackURL *string `json:"callback_url,omitempty"`
}

type AddressResponse

type AddressResponse struct {
	ID            string  `json:"id"`
	Reference     string  `json:"reference"`
	WalletID      string  `json:"wallet_id"`
	Currency      string  `json:"currency"`
	Amount        float64 `json:"amount"`
	AmountInitial float64 `json:"amount_initial"`
	Type          string  `json:"type"`
	Status        string  `json:"status"`
	StatusCode    int     `json:"status_code,omitempty"`
	StatusMessage string  `json:"status_message,omitempty"`
	PaymentFee    float64 `json:"payment_fee"`
	Address       string  `json:"address,omitempty"`
	Memo          string  `json:"memo,omitempty"`
}

type BankInfo

type BankInfo struct {
	Account *string `json:"account,omitempty"`
	ID      *string `json:"id,omitempty"`
	Name    *string `json:"name,omitempty"`
}

type BillingInfo

type BillingInfo struct {
	Address     *string `json:"address,omitempty"`
	CountryCode *string `json:"country_code,omitempty"`
	Country     *string `json:"country,omitempty"`
}

type CardData

type CardData struct {
	ExpMonth *string `json:"exp_month,omitempty"`
	ExpYear  *string `json:"exp_year,omitempty"`
}

type CryptoInfo

type CryptoInfo struct {
	Memo *string `json:"memo,omitempty"`
}

type CustomerInfo

type CustomerInfo struct {
	FirstName *string `json:"first_name,omitempty"`
	LastName  *string `json:"last_name,omitempty"`
	Email     *string `json:"email,omitempty"`
	Phone     *string `json:"phone,omitempty"`
}

type FlowData

type FlowData struct {
	Action string        `json:"action"`
	Method string        `json:"method"`
	Params []interface{} `json:"params"`
}

type InvoiceRequest

type InvoiceRequest struct {
	Reference   string        `json:"reference"`
	Title       *string       `json:"title,omitempty"`
	Description *string       `json:"description,omitempty"`
	LimitMinute *int          `json:"limit_minute,omitempty"`
	CallbackURL *string       `json:"callback_url,omitempty"`
	Amount      float64       `json:"amount"`
	Currency    string        `json:"currency"`
	ReturnURL   string        `json:"return_url"`
	Customer    *CustomerInfo `json:"customer,omitempty"`
	BillingInfo *BillingInfo  `json:"billing_info,omitempty"`
	Bank        *BankInfo     `json:"bank,omitempty"`
	CardData    *CardData     `json:"card_data,omitempty"`
	WebData     *WebData      `json:"web_data,omitempty"`
	UI          *UISchema     `json:"ui,omitempty"`
}

type InvoiceResponse

type InvoiceResponse struct {
	ID            string    `json:"id"`
	Reference     string    `json:"reference"`
	WalletID      string    `json:"wallet_id"`
	Currency      string    `json:"currency"`
	Amount        float64   `json:"amount"`
	AmountInitial float64   `json:"amount_initial"`
	Type          string    `json:"type"`
	Status        string    `json:"status"`
	StatusCode    int       `json:"status_code,omitempty"`
	StatusMessage string    `json:"status_message,omitempty"`
	PaymentFee    float64   `json:"payment_fee"`
	Address       string    `json:"address,omitempty"`
	Memo          string    `json:"memo,omitempty"`
	FlowData      *FlowData `json:"flowData,omitempty"`
}

type PSPark

type PSPark struct {
	Secret  string
	APIKey  string
	BaseURL string
}

func PSParkClient

func PSParkClient(secret string, apiKey string) *PSPark

func (*PSPark) CreateAddress

func (client *PSPark) CreateAddress(walletId string, data AddressRequest) (AddressResponse, error)

func (*PSPark) CreateInvoice

func (client *PSPark) CreateInvoice(walletId string, data InvoiceRequest) (InvoiceResponse, error)

func (*PSPark) CreateWithdrawal

func (client *PSPark) CreateWithdrawal(walletId string, data WithdrawalRequest) (WithdrawalResponse, error)

func (*PSPark) GetBalances

func (client *PSPark) GetBalances() ([]WalletBalance, error)

func (*PSPark) GetWalletBalance

func (client *PSPark) GetWalletBalance(walletId string) (WalletBalance, error)

type ResponseDTO

type ResponseDTO[T any] struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    T      `json:"data"`
}

type ResponseValidationError

type ResponseValidationError struct {
	Message string
	Code    int
	Data    interface{}
}

func (*ResponseValidationError) Error

func (e *ResponseValidationError) Error() string

type SignedToken

type SignedToken struct {
	Token  string
	Claims map[string]interface{}
}

type UISchema

type UISchema struct {
	Language *string `json:"language,omitempty"` // Values: "en", "ua", "ru"
}

type WalletBalance

type WalletBalance struct {
	WalletId string `json:"wallet_id"`
	Currency string `json:"currency"`
	Balance  string `json:"balance"`
	Name     string `json:"name"`
}

type WebData

type WebData struct {
	IP        *string `json:"ip,omitempty"`
	UserAgent *string `json:"user_agent,omitempty"`
}

type WithdrawalDetails

type WithdrawalDetails struct {
	Crypto   *CryptoInfo   `json:"crypto,omitempty"`
	Customer *CustomerInfo `json:"customer,omitempty"`
	Billing  *BillingInfo  `json:"billing_info,omitempty"`
	Bank     *BankInfo     `json:"bank,omitempty"`
	CardData *CardData     `json:"card_data,omitempty"`
	WebData  *WebData      `json:"web_data,omitempty"`
}

type WithdrawalRequest

type WithdrawalRequest struct {
	Reference string             `json:"reference"`
	Amount    float64            `json:"amount"`
	Account   string             `json:"account"`
	Details   *WithdrawalDetails `json:"details,omitempty"`
}

type WithdrawalResponse

type WithdrawalResponse struct {
	ID            string  `json:"id"`
	Reference     string  `json:"reference"`
	Amount        float64 `json:"amount"`
	Currency      string  `json:"currency"`
	Type          string  `json:"type"`
	Status        string  `json:"status"`
	StatusCode    int     `json:"status_code,omitempty"`
	StatusMessage string  `json:"status_message,omitempty"`
	PaymentFee    float64 `json:"payment_fee"`
	AmountSpent   float64 `json:"amount_spent"`
}

Jump to

Keyboard shortcuts

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