juice

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 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 Integrator 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(req *RegisterAccountData) (accountRes, error)

This is called to create a card integrator account. The payload should be of type spend-juice-go.RegisterAccountData. See below for spend-juice-go.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 := spend-juice-go.RegisterAccountData{
        BusinessAddress:    "Lekki Ikate",
        BusinessName:       "Algo Math",
        Chain:              "ETH",
        ContactNumber:      "+2349034384660",
        Country:            "NG",
        Domain:             "https://boro.com",
        Email:              "alaoolusolae@gmail.com",
        FirstName:          "Olusola",
        FloatCurrencies:    []string{"USD"},
        LastName:           "Alao",
        Password:           "@Password",
        RegistrationNumber: "RC-546787",
        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, businessAdd, domain string)

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 ETH +2349034384660 NG https://olusolaa.tech alaoolusolae@gmail.com Olusola [USD] 8de0c7a2-0004-4420-899b-f8d89c81f82b Alao RC-546789 {0x7af2fa93d4069655098a24dd055ff7aa51bab531 ETH USD}}}
.RegisterUser(req RegisterUserData, id string)

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"`
}

Id is the integrator account id. IdNumber is the user identity card number (in sandbox environment use 00000000000 as your BVN number)

A sample verify call is:

    payload := spend-juice-go.RegisterUserData{
        spend-juice-go.Address: 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",
    }
        
    id := "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 gets a list of card users attached to an integrator account. Limit is the number of users dispaly per page.

A sample initiate call is:

    got, 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 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 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(req CreateCardData) (createCardResp, error)

CreateCard creates a card for a user

func (*Client) CreditCard

func (cl *Client) CreditCard(req PaymentData) (cardResp, error)

CreditCard top-up a card for a user

func (*Client) DebitCard

func (cl *Client) DebitCard(req PaymentData) (cardResp, error)

DebitCard debits a card for a user

func (*Client) FreezeCard

func (cl *Client) FreezeCard(id string) (cardResp, error)

FreezeCard freezes a card for a user

func (*Client) GetCard

func (cl *Client) GetCard(id string) (cardResp, error)

GetCard gets a particular card

func (*Client) GetTransaction

func (cl *Client) GetTransaction(id 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, id string) ([]cardResp, error)

ListCards gets a list of cards of a user

func (*Client) ListTransactions

func (cl *Client) ListTransactions(id 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) RegisterAccount

func (cl *Client) RegisterAccount(req *RegisterAccountData) (accountRes, error)

RegisterAccount creates a card integrator account

func (*Client) RegisterUser

func (cl *Client) RegisterUser(req RegisterUserData, id string) (userResp, error)

RegisterUser creates an account for user requesting a card

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) UnfreezeCard

func (cl *Client) UnfreezeCard(id string) (cardResp, error)

UnfreezeCard unfreezes a card for a user

func (*Client) UpdateAccount

func (cl *Client) UpdateAccount(webhook, businessAdd, domain string) (accountRes, 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"`
	JuiceUserId      string `json:"juice_user_id"`
	Validity         int    `json:"validity"`
}

type Error

type Error struct {
	Errors struct {
		Message     string   `json:"message"`
		Amount      []string `json:"amount"`
		Domain      []string `json:"domain"`
		PhoneNumber []string `json:"phone_number"`
		JuiceUserId []string `json:"juice_user_id"`
	} `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 Param

type Param struct {
	Limit int
	Page  int
}

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 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"`
	CreditCurrency    interface{} `json:"credit_currency"`
	CreditId          interface{} `json:"credit_id"`
	DebitCurrency     interface{} `json:"debit_currency"`
	DebitId           interface{} `json:"debit_id"`
	Id                string      `json:"id"`
	Narrative         interface{} `json:"narrative"`
	Type              string      `json:"type"`
}

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"`
}

Jump to

Keyboard shortcuts

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