juice

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: MIT Imports: 13 Imported by: 0

README

image

Spend-Juice Go Library

Introduction

This is a Go wrapper around the API for Cards Integrators by Spend-Juice.

Installation

To install, run

go get github.com/bushaHQ/spend-juice-go

Import Package

The base class for this package is 'spend-juice-go'. To use this class, add:

 import (
 	"github.com/bushaHQ/spend-juice-go"
 )

Initialization

To use Spend Juice, instantiate Spend-Juice with your public key. We recommend that you store your secret key in an environment variable named, JUICE_PRIVATE_KEY. See example below.

   err := godotenv.Load("./.env")
   if err != nil {
       log.Fatal("Error loading .env file")
   }
   client := juice.NewClient()

You can override the default settings by passing in the following parameters:

    client.SetBaseURL("your-base-url")
    client.SetDebug(false)
    client.SetHTTPClient(&http.Client{
        Timeout: your-timeout,
    })
    client.SetAuth(os.Getenv({JUICE_PRIVATE_KEY}))

Card Integration Methods

This is the documentation for all of the components of card Integrator

Methods Included:

  • .RegisterAccount

  • .UpdateAccount

  • .RegisterUser

  • .ListUsers

  • .CreateCard

  • .ListCards

  • .GetCard

  • .CreditCard

  • .DebitCard

  • .FreezeCard

  • .UnfreezeCard

  • .ListTransactions

  • .GetTransaction

.RegisterAccount(data RegisterAccountData) (AccountResp, error)

This is called to create a card integrator account. The payload should be of type juice.RegisterAccountData. See below for juice.RegisterAccountData definition

    type RegisterAccountData struct {
        FloatCurrencies    []string `json:"float_currencies"`
        BusinessAddress    string   `json:"business_address"`
        BusinessName       string   `json:"business_name"`
        Chain              string   `json:"chain"`
        ContactNumber      string   `json:"contact_number"`
        Country            string   `json:"country"`
        Domain             string   `json:"domain"`
        Email              string   `json:"email"`
        FirstName          string   `json:"first_name"`
        LastName           string   `json:"last_name"`
        Password           string   `json:"password"`
        RegistrationNumber string   `json:"registration_number"`
        WebhookUrl         string   `json:"webhook_url"`
    }

A sample register call is:

    payload := juice.RegisterAccountData{
        BusinessAddress:    "Ajah",
        BusinessName:       "Algoro",
        Chain:              "ETH",
        ContactNumber:      "+2349034384669",
        Country:            "NG",
        Domain:             "https://ajalekoko.com",
        Email:              "ajalenkoko@gmail.com",
        FirstName:          "Olusola",
        FloatCurrencies:    []string{"USD"},
        LastName:           "Alao",
        Password:           "@Password",
        RegistrationNumber: "RC-5467898",
        WebhookUrl:         "https://webhook.site/7bdf91c4-6e84-4ff1-a3e1-185f138247c1",
    }

    response, err := client.RegisterAccount(payload)

    if err != nil {
        panic(err)
    }
    
    fmt.Println(response)
Sample Response
    {{Lekki Ikate Algo Math ETH +2349034384660 NG https://boro.com alaoolusolae@gmail.com Olusola [USD] 27de9f46-726a-4499-aa62-27c3ed274026 Alao RC-546787 {0xbaf2e14f27c106f0d078b397af9c7eebf1611d46 ETH USD}}}
.UpdateAccount(webhook, businessAddress, domain string) (AccountResp, error)

This is called to update the integrator account.

A sample validate call is:

    response, err := client.UpdateAccount("https://webhook.site/043c6db2-5c17-4885-b769-4491ce3b0b0e", "New Road Lincoln street", "https://olusolaa.tech")
    if err != nil {
        panic(err)
    }
    fmt.Println(response)
Sample Response
   {{New Road Lincoln street algo math  +2349034384662 NG https://olusolaa.tech email@gmail.com Olusola [USD] 8de0c7a2-0004-4420-899b-f8d89c81f82b Alao 12345 {0x7af2fa93d4069655098a24dd055ff7aa51bab531 ETH USD}}}
.RegisterUser(data RegisterUserData, accountId string) (UserResp, error)

This is called to create an account for user requesting a card. The payload should be of type spend-juice-go.RegisterUserData. See below for spend-juice-go.RegisterUserData definition

    type RegisterUserData struct {
        Address     UserAddress `json:"address"`
        Email       string      `json:"email"`
        FirstName   string      `json:"first_name"`
        IdNumber    string      `json:"id_number"`
        IdType      string      `json:"id_type"`
        LastName    string      `json:"last_name"`
        PhoneNumber string      `json:"phone_number"`
        UserPhoto   string      `json:"user_photo,omitempty"`
    }

IdNumber is the user identity card number (in sandbox environment use 00000000000 as your BVN number)

A sample register-user call is:

    payload := juice.RegisterUserData{
        Address: juice.UserAddress{
        City:    "Lagos",
        Country: "NG",
        Line1:   "Lekki Phase 1",
        Line2:   "Saltana Park",
        State:   "Lagos",
        ZipCode: "101233",
    },
        Email:       "user2@gmail.com",
        FirstName:   "Olusola",
        IdNumber:    "00000000000",
        IdType:      "BVN",
        LastName:    "Alao",
        PhoneNumber: "+2348023547675",
    }
        
    accountId := "27de9f46-726a-4499-aa62-27c3ed274026"

    response, err := client.RegisterUser(payload, id)
    if err != nil {
        panic(err)
    }
    fmt.Println(response)
Sample Response
{{{Lagos NG Lekki Phase 1 Saltana Park Lagos 101233} false 27de9f46-726a-4499-aa62-27c3ed274026 user2@gmail.com Olusola be2c7d1c-c02a-4925-a7c4-4c5b4fc579f1 00000000000 BVN Alao +2348023547675 false}}
.ListUsers(limit, page int) (usersResp, error)

This is called to get a list of card users attached to an integrator account. Limit is the number of users dispaly per page.

A sample list users call is:

    response, err := client.ListUsers(10, 1)
    if err != nil {
        panic(err)
    }
    fmt.Println(response)
Sample Response
{1 1 1 [{{Lagos NG Lekki Phase 1 <nil> <nil> 101233} false 27de9f46-726a-4499-aa62-27c3ed274026 user1@gmail.com Olusola 1c607ba6-4a59-405a-bf63-55cb76078ade 00000000000 BVN Alao +2348023547672 true}]}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	BusinessAddress    string      `json:"business_address"`
	BusinessName       string      `json:"business_name"`
	Chain              string      `json:"chain"`
	ContactNumber      string      `json:"contact_number"`
	Country            string      `json:"country"`
	Domain             string      `json:"domain"`
	Email              string      `json:"email"`
	FirstName          string      `json:"first_name"`
	FloatCurrencies    []string    `json:"float_currencies"`
	Id                 string      `json:"id"`
	LastName           string      `json:"last_name"`
	RegistrationNumber string      `json:"registration_number"`
	UsdcAddress        UsdcAddress `json:"usdc_address"`
}

type AccountResp

type AccountResp struct {
	Data Account `json:"data"`
}

type BalanceResp added in v1.0.3

type BalanceResp struct {
	Balance  int    `json:"balance"`
	Currency string `json:"currency"`
	Id       string `json:"id"`
}

type Card

type Card struct {
	Balance    int       `json:"balance"`
	BusinessId string    `json:"business_id"`
	CardName   string    `json:"card_name"`
	CardNumber string    `json:"card_number"`
	CardType   string    `json:"card_type"`
	Currency   string    `json:"currency"`
	Cvv2       string    `json:"cvv2"`
	DesignType string    `json:"design_type"`
	Expiry     time.Time `json:"expiry"`
	Id         string    `json:"id"`
	Provider   string    `json:"provider"`
	SingleUse  bool      `json:"single_use"`
	Status     string    `json:"status"`
	UserId     string    `json:"user_id"`
	Valid      string    `json:"valid"`
}

type CardResp

type CardResp struct {
	Balance    int       `json:"balance"`
	CardNumber string    `json:"card_number"`
	CardType   string    `json:"card_type"`
	Cvv2       string    `json:"cvv2"`
	Expiry     time.Time `json:"expiry"`
	Id         string    `json:"id"`
	SingleUse  bool      `json:"single_use"`
	Status     string    `json:"status"`
	Valid      string    `json:"valid"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client ...

func NewClient

func NewClient() *Client

NewClient creates a new Spend-Juice API client with the default base URL.

func (*Client) CreateCard

func (cl *Client) CreateCard(data CreateCardData) (CreateCardResp, error)

CreateCard creates a card for a user

func (*Client) CreditCard

func (cl *Client) CreditCard(data PaymentData) (CardResp, error)

CreditCard top-up a card for a user

func (*Client) DebitCard

func (cl *Client) DebitCard(data PaymentData) (CardResp, error)

DebitCard debits a card for a user

func (*Client) FreezeCard

func (cl *Client) FreezeCard(cardId string) (CardResp, error)

FreezeCard freezes a card for a user

func (*Client) GetCard

func (cl *Client) GetCard(cardId string) (CardResp, error)

GetCard gets a particular card

func (*Client) GetFloat added in v1.0.3

func (cl *Client) GetFloat() (BalanceResp, error)

GetFloat allows an integrator get their float balance

func (*Client) GetTransaction

func (cl *Client) GetTransaction(trxId string) (TransactionResp, error)

GetTransaction gets a particular transaction

func (Client) Health

func (cl Client) Health() (string, error)

func (*Client) ListCards

func (cl *Client) ListCards(limit, page int, userId string) ([]CardResp, error)

ListCards gets a list of cards of a user

func (*Client) ListTransactions

func (cl *Client) ListTransactions(cardId string, param Param) (TransactionsResp, error)

ListTransactions gets paginated transactions for the given card

func (*Client) ListUsers

func (cl *Client) ListUsers(limit, page int) (UsersResp, error)

ListUsers gets list of card users attached to an account

func (*Client) MockTransaction added in v1.0.4

func (cl *Client) MockTransaction(data MockTransactionData, cardId string) (Resp, error)

MockTransaction mocks card transaction. This endpoint is only available in the sandbox environment.

func (*Client) RegisterAccount

func (cl *Client) RegisterAccount(data RegisterAccountData) (AccountResp, error)

RegisterAccount creates a card integrator account

func (*Client) RegisterUser

func (cl *Client) RegisterUser(data RegisterUserData, accountId string) (UserResp, error)

RegisterUser creates an account for user requesting a card

func (*Client) SetAPIVersion

func (cl *Client) SetAPIVersion(version string)

SetAPIVersion overrides the default base URL. For internal use.

func (*Client) SetAuth

func (cl *Client) SetAuth(apiKey string) error

SetAuth provides the client with an API key and secret.

func (*Client) SetBaseURL

func (cl *Client) SetBaseURL(baseURL string)

SetBaseURL overrides the default base URL. For internal use.

func (*Client) SetDebug

func (cl *Client) SetDebug(debug bool)

SetDebug enables or disables debug mode. In debug mode, HTTP requests and responses will be logged.

func (*Client) SetHTTPClient

func (cl *Client) SetHTTPClient(httpClient HTTPClient)

SetHTTPClient sets the HTTP client that will be used for API calls.

func (*Client) TopUpFloat added in v1.0.3

func (cl *Client) TopUpFloat(amount int) (Resp, error)

TopUpFloat allows an integrator to top up float balance. This endpoint is only available in the sandbox environment.

func (*Client) UnfreezeCard

func (cl *Client) UnfreezeCard(cardId string) (CardResp, error)

UnfreezeCard unfreezes a card for a user

func (*Client) UpdateAccount

func (cl *Client) UpdateAccount(webhook, businessAddress, domain string) (AccountResp, error)

UpdateAccount updates the card integrator account

type CreateCardData

type CreateCardData struct {
	DesignType       string `json:"design_type"`
	SingleUse        bool   `json:"single_use"`
	Source           string `json:"source"`
	CardIntegratorId string `json:"card_integrator_id"`
	Currency         string `json:"currency"`
	UserId           string `json:"user_id"`
	Validity         int    `json:"validity"`
}

type CreateCardResp

type CreateCardResp struct {
	Data Card `json:"data"`
}

type Error

type Error struct {
	Errors  interface{} `json:"errors"`
	Message string      `json:"message"`
}

func (Error) Error

func (e Error) Error() string

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type MockTransactionData added in v1.0.4

type MockTransactionData struct {
	Amount int    `json:"amount"`
	Type   string `json:"type"`
}

type Param

type Param struct {
	Limit int `url:",omitempty"`
	Page  int `url:",omitempty"`
}

type PaymentData

type PaymentData struct {
	Source string `json:"source"`
	Amount int    `json:"amount"`
	CardId string `json:"card_id"`
}

type RegisterAccountData

type RegisterAccountData struct {
	FloatCurrencies    []string `json:"float_currencies"`
	BusinessAddress    string   `json:"business_address"`
	BusinessName       string   `json:"business_name"`
	Chain              string   `json:"chain"`
	ContactNumber      string   `json:"contact_number"`
	Country            string   `json:"country"`
	Domain             string   `json:"domain"`
	Email              string   `json:"email"`
	FirstName          string   `json:"first_name"`
	LastName           string   `json:"last_name"`
	Password           string   `json:"password"`
	RegistrationNumber string   `json:"registration_number"`
	WebhookUrl         string   `json:"webhook_url"`
}

type RegisterUserData

type RegisterUserData struct {
	Address     UserAddress `json:"address"`
	Email       string      `json:"email"`
	FirstName   string      `json:"first_name"`
	IdNumber    string      `json:"id_number"`
	IdType      string      `json:"id_type"`
	LastName    string      `json:"last_name"`
	PhoneNumber string      `json:"phone_number"`
	UserPhoto   string      `json:"user_photo,omitempty"`
}

type Resp added in v1.0.4

type Resp struct {
	Message string `json:"message"`
}

type TopUpFloatData added in v1.0.3

type TopUpFloatData struct {
	Amount int `json:"amount"`
}

type Transaction

type Transaction struct {
	Amount            int         `json:"amount"`
	CardBalanceAfter  int         `json:"card_balance_after"`
	CardBalanceBefore int         `json:"card_balance_before"`
	ConversionRate    int         `json:"conversion_rate"`
	CreatedAt         time.Time   `json:"created_at"`
	Currency          string      `json:"currency"`
	Id                string      `json:"id"`
	Narrative         interface{} `json:"narrative"`
	Type              string      `json:"type"`
}

type TransactionResp

type TransactionResp struct {
	Data    Transaction `json:"data"`
	Message string      `json:"message"`
}

type TransactionsResp

type TransactionsResp struct {
	Data     []Transaction `json:"data"`
	Message  string        `json:"message"`
	NextPage interface{}   `json:"next_page"`
}

type UpdateAccountData

type UpdateAccountData struct {
	WebhookUrl      string `json:"webhook_url"`
	BusinessAddress string `json:"business_address"`
	Domain          string `json:"domain"`
}

type UsdcAddress

type UsdcAddress struct {
	Address  string `json:"address"`
	Chain    string `json:"chain"`
	Currency string `json:"currency"`
}

type User

type User struct {
	Address          UserAddress `json:"address"`
	Archived         bool        `json:"archived"`
	CardIntegratorId string      `json:"card_integrator_id"`
	Email            string      `json:"email"`
	FirstName        string      `json:"first_name"`
	Id               string      `json:"id"`
	IdNumber         string      `json:"id_number"`
	IdType           string      `json:"id_type"`
	LastName         string      `json:"last_name"`
	PhoneNumber      string      `json:"phone_number"`
	Verified         bool        `json:"verified"`
}

type UserAddress

type UserAddress struct {
	City    string      `json:"city"`
	Country string      `json:"country"`
	Line1   string      `json:"line1"`
	Line2   interface{} `json:"line2"`
	State   interface{} `json:"state"`
	ZipCode string      `json:"zip_code"`
}

type UserResp

type UserResp struct {
	Data User `json:"data"`
}

type UsersResp

type UsersResp struct {
	Page       int    `json:"page"`
	Total      int    `json:"total"`
	TotalPages int    `json:"total_pages"`
	Data       []User `json:"data"`
}

Jump to

Keyboard shortcuts

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