smartbonus

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 7 Imported by: 0

README

Smartbonus package for Go language

This package provides Go implementation of Smartbonus api. Supported all public api of smartbonus.

With 100% test coverage.

Installation

Use the go command:

$ go get github.com/smartbonus/smartbonus-api

Requirements

Smartbonus package tested against Go 1.13.

Example

package main

import (
    smartbonus "github.com/smartbonus/smartbonus-api"
    "fmt"
)

func main() {
    // Creating sb: panic on error
    // Ask about params smartbonus team
    sb := smartbonus.NewSmartBonus("your store id", "https://your.smartbonus.com/api/v2/")

    // Get smartbonus info about client
    if client, err := sb.GetClient("0555555555"); err != nil {
        fmt.Println(err.Error())
    } else {
        fmt.Printf("Client <phone: %s; name: %s; balance: %.2f>\n", client.Phone, client.Name, client.Balance)
    }

    // see tests for more
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalyticObject

type AnalyticObject struct {
	ExecutedModules []ExecutedModule `json:"executed_modules"`
}

List of executed modules

type Characteristic

type Characteristic struct {
	ID   int64     `json:"id"`
	Num  *float64  `json:"num"`
	Text *TextLang `json:"text"`
}

type Client

type Client struct {
	Phone   string  `json:"phone"`   // phone number of client (unique)
	Balance float64 `json:"balance"` // amount of bonuses in smartbonus account
	Name    string  `json:"name"`    // client name (optional)
}

Client instance is smartbonus app user

type ExecutedModule

type ExecutedModule struct {
	Id         string  `json:"id"`              // identifier of smartbonus module
	Type       string  `json:"type"`            // type of object: subscriber_module|discount_module|coupon_module
	Accrued    float64 `json:"accrued_bonus"`   // amount of accrued bonuses
	Immediate  float64 `json:"immediate_bonus"` // amount of immediate discount
	Withdrawn  float64 `json:"withdrawn_bonus"` // amount of withdrawn bonuses
	ModuleType string  `json:"module_type"`     // type of smartbonus module
	Name       string  `json:"name"`            // title of module
}

Smartbonus modules that accrued/withdrawn bonuses or added discount

type MeasureType

type MeasureType string
const (
	PIECE    MeasureType = "piece"
	KILOGRAM MeasureType = "kilogram"
	GRAM     MeasureType = "gram"
)

type Nomenclature

type Nomenclature struct {
	Id          string   `json:"id"`                    // unique identifier of product in your db
	Name        string   `json:"name"`                  // title of product
	Description string   `json:"description,omitempty"` // description of product (optional)
	Image       string   `json:"photo_url,omitempty"`   // image of product, if you have more than one image join them by comma (optional)
	IsDeleted   bool     `json:"is_deleted,omitempty"`  // send true if you deleted that product (optional)
	CategoryId  string   `json:"category,omitempty"`    // unique identifier of category in your db (optional)
	Barcode     string   `json:"barcode,omitempty"`     // barcode of your product (optional)
	Price       float64  `json:"price,omitempty"`       // price of your product (optional)
	IsCategory  bool     `json:"is_category,omitempty"` // send true if current instance is category or false if it's product (optional)
	Tags        []string `json:"tags,omitempty"`        // list of tag identifiers (optional)
	CanBuy      bool     `json:"can_buy,omitempty"`     // send true if this product can be buyed in smartbonus app (optional)
	IsHidden    *bool    `json:"is_hidden,omitempty"`   // send false if you want to show this product in smartbonus app catalog for clients (optional)
	IsWeight    bool     `json:"is_weight"`             // send true if nomenclature item is weight product.
	Multiplier  float64  `json:"multiplier"`            // send 0.01 price at 0.1 kg & 0.001 at 1 kg
	Quantity    float64  `json:"quantity"`              // product quantity
	OldPrice    float64  `json:"old_price"`             // previous price that identify discount of product.
	Priority    int64    `json:"priority"`              // priority in apps
	Articul     string   `json:"articul"`               // articul of product
}

Nomenclature instance has to be sync to smartbonus after it created, changed or deleted. If you cannot trigger nomenclature events, send it by some interval: once a day for example.

type NomenclatureItem

type NomenclatureItem struct {
	Id       string  `json:"nomenclature_id"` // your product identifier
	Quantity float64 `json:"amount"`          // quantity or product
	Price    float64 `json:"unit_price"`      // price of product
	MasterID string  `json:"master_id"`
	PosterID string  `json:"poster_id"` // the nomenlautre is related to the store, not to the customer
}

type Order

type Order struct {
	Store                          // your StoreId token that configured
	Id              string         `json:"remote_id"`       // unique identifier of order in smartbonus
	Code            string         `json:"code"`            // number of order for client
	UserId          string         `json:"user_id"`         // client identifier that has to be used to sync receipt
	Phone           string         `json:"phone"`           // phone number of client
	UserName        string         `json:"user_name"`       // name of client
	Amount          float64        `json:"amount"`          // amount for pay
	Currency        string         `json:"currency"`        // ISO 4217: UAH, USD, EUR
	Date            int64          `json:"date_unix"`       // date of order
	IsPaid          bool           `json:"is_paid"`         // order paid online by client
	ProductsAmount  float64        `json:"products_amount"` // amount of products
	DeliveryCost    float64        `json:"delivery_cost"`   // cost of delivery
	Discount        float64        `json:"discount"`        // amount of discount
	Products        []OrderProduct `json:"products"`
	Statuses        []OrderStatus  `json:"statuses"`
	Comment         string         `json:"comment"`  // client comment
	DeliveryType    string         `json:"delivery"` // type of delivery
	DeliveryAddress string         `json:"deliveryAddress"`
	DeliveryTime    string         `json:"deliveryTime"`
}

Order instance - send new order that created in smartbonus to your api after webhook is configured:

type OrderProduct

type OrderProduct struct {
	Id       string  `json:"id"`       // your nomenclature identifier
	Price    float64 `json:"amount"`   // price of product
	Quantity float64 `json:"quantity"` // quantity of product
}

OrderProduct instance - element of products in Order:

type OrderStatus

type OrderStatus struct {
	Date   int64           `json:"date_unix"` // date of status creation
	Status OrderStatusType `json:"status"`
}

OrderStatus instance - element of statuses in Order:

type OrderStatusType

type OrderStatusType int

List of order statuses

const (
	NEW OrderStatusType = iota
	PAYMENT_PENDING
	PAYMENT_CANCELED
	PROCESSING
	AWAITING_SHIPMENT
	AWAITING_PICKUP
	COMPLETED
	CANCELED
	REFUNDED
	AWAITING_WEB_PAYMENT
	WEB_PAYMENT_SUCCESSFUL

	AWAITING_FOR_COLLECT
	COLLECTING
	TRANSFERRED_FOR_DELIVERY
	DELIVERING
	CANCEL_REQUEST
	AWAITING_POST_PAYMENT
)

func (OrderStatusType) Get

func (s OrderStatusType) Get(status string) (OrderStatusType, error)

func (OrderStatusType) String

func (a OrderStatusType) String() string

type Price

type Price struct {
	Value    float64     `json:"value"`
	StoreID  string      `json:"store_id,omitempty"`
	OldPrice float64     `json:"old_price,omitempty"`
	Measure  MeasureType `json:"measure"`
	Quantity float64     `json:"quantity,omitempty"`
}

type Product

type Product struct {
	ProductItem
	Modifiers []ProductItem `json:"modifiers"`
}

type ProductItem

type ProductItem struct {
	ID              string           `json:"id"`
	Titles          TextLang         `json:"titles"`
	Descriptions    TextLang         `json:"descriptions"`
	Images          []string         `json:"images"`
	Categories      []string         `json:"categories"`
	Priority        int64            `json:"priority"`
	Barcode         string           `json:"barcode"`
	IsHidden        bool             `json:"is_hidden"`
	CanBuy          bool             `json:"can_buy"`
	Prices          []Price          `json:"prices"`
	Characteristics []Characteristic `json:"characteristics"`
	Brand           string           `json:"brand"`
}

type ReceiptConfirm

type ReceiptConfirm struct {
	Store
	UserId     string                 `json:"user_id"`           // Phone or sanned key from smartbonus app
	Date       int64                  `json:"date,omitempty"`    // Date of receipt (optional)
	Discount   float64                `json:"discount"`          // Amount of discount that received from DiscountReceipt method.
	Items      []NomenclatureItem     `json:"list"`              // List of products
	Id         string                 `json:"remote_id"`         // Unique receipt identifier
	Change     float64                `json:"accrued,omitempty"` // Rest of money that will accrue to smartbonus account
	Additional map[string]interface{} `json:"additional"`
}

Body for receipt confirmation

type ReceiptDiscount

type ReceiptDiscount struct {
	Store
	UserId     string                 `json:"user_id"`             // Phone or sanned key from smartbonus app
	Date       int64                  `json:"date,omitempty"`      // Date of receipt (optional)
	Withdrawn  float64                `json:"withdrawn,omitempty"` // Amount of money that cashier want to withdraw from client account (optional)
	Items      []NomenclatureItem     `json:"receipt"`             // products of receipt
	Additional map[string]interface{} `json:"additional"`
}

Body for receipt discount method

type ReceiptItems

type ReceiptItems struct {
	Id        string  `json:"id"`         // your product identifier
	Accrued   float64 `json:"accrued"`    // amount of accrued bonuses
	Withdrawn float64 `json:"withdrawn"`  // amount of withdrawn bonuses
	Immediate float64 `json:"immediate"`  // amount of immediate discount
	Quantity  float64 `json:"amount"`     // quantity of product
	Price     float64 `json:"unit_price"` // price of product
}

Item of receipt response

type ReceiptRefund

type ReceiptRefund struct {
	Store
	Id        string       `json:"refund_id"` // identifier of your refund receipt
	ReceiptId string       `json:"remote_id"` // identifier of your sell receipt
	Items     []RefundItem `json:"list"`      // list of refund products
}

Receipt refund request body

type ReceiptResult

type ReceiptResult struct {
	Discount        float64        `json:"discount"`         // amount of discount: withdrawn + immediate
	Info            string         `json:"info"`             // description of modules
	Accrued         float64        `json:"user_add_bonus"`   // amount of accrued bonuses
	Withdrawn       float64        `json:"withdrawn"`        // amount of withdrawn bonuses
	Immediate       float64        `json:"immediate"`        // amount of immediate discount
	UserName        string         `json:"user_name"`        // client name
	Items           []ReceiptItems `json:"nomenclatures"`    // list of products
	AnalyticObjects AnalyticObject `json:"analytics_object"` // details of smartbonus modules
}

Receipt response of discount and confirm methods

type RefundItem

type RefundItem struct {
	Id       string  `json:"nomenclature_id"` // your product identifier
	Quantity float64 `json:"amount"`          // quantity of product
}

Item of receipt refund request

type RefundItemResult

type RefundItemResult struct {
	Id        string  `json:"id"`        // your product identifier
	Immediate float64 `json:"immediate"` // amount of immediate discount
	Withdrawn float64 `json:"withdrawn"` // amount of withdrawn bonuses
	Accrued   float64 `json:"accrued"`   // amount of accrued bonuses
}

Item response of refund receipt request rest = price * quantity - withdrawn - immediate

type RefundResult

type RefundResult []RefundItemResult

Refund response: list of refund items

type SmartBonus

type SmartBonus struct {
	Store
}

Object implement all features

func NewSmartBonus

func NewSmartBonus(storeId, sbRoute, customerId string) *SmartBonus

Create new instance of SmartBonus object On testing set to env variable with name SB_ROUTE Ask smartbonus team for your sbRoute

func (*SmartBonus) ChangeOrderStatus

func (s *SmartBonus) ChangeOrderStatus(statusBody StatusBody) error

func (*SmartBonus) ConfigOrder

func (s *SmartBonus) ConfigOrder(orderUrl, statusUrl, token string, syncNomenclatureFull, syncNomenclatureByCustomer bool) error

func (*SmartBonus) ConfirmReceipt

func (s *SmartBonus) ConfirmReceipt(receipt ReceiptConfirm) (*ReceiptResult, error)

func (*SmartBonus) DeleteReceipts

func (s *SmartBonus) DeleteReceipts(receipts []string) error

func (*SmartBonus) DiscountReceipt

func (s *SmartBonus) DiscountReceipt(receipt ReceiptDiscount) (*ReceiptResult, error)

func (*SmartBonus) GetClient

func (s *SmartBonus) GetClient(userId string) (*Client, error)

func (*SmartBonus) RefundReceipt

func (s *SmartBonus) RefundReceipt(receipt ReceiptRefund) (*RefundResult, error)

func (*SmartBonus) SyncNomenclatures

func (s *SmartBonus) SyncNomenclatures(nomes []Product) error

func (*SmartBonus) SyncNomenclaturesV2

func (s *SmartBonus) SyncNomenclaturesV2(nomes []Nomenclature) error

func (*SmartBonus) SyncReceipts

func (s *SmartBonus) SyncReceipts(receipts []ReceiptConfirm) error

func (*SmartBonus) SyncTags

func (s *SmartBonus) SyncTags(tags []Tag) error

type StatusBody

type StatusBody struct {
	Store
	OrderId string          `json:"order_id"` // identifier of order in smartbonus
	Status  OrderStatusType `json:"status"`   //  one of OrderStatuses
}

Body of status:

type Store

type Store struct {
	StoreId    string `json:"store"`
	CustomerId string `json:"customer_id"`
}

Base struct

type Tag

type Tag struct {
	Id      string `json:"id"`
	Name    string `json:"name"`
	GroupId string `json:"group_id,omitempty"`
	IsGroup bool   `json:"is_group"`
}

Tag is smartbonus filter, used in smartbonus app catalog

type TextLang

type TextLang struct {
	UK string `json:"uk"`
	RU string `json:"ru"`
	EN string `json:"en"`
}

Jump to

Keyboard shortcuts

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