xoxoday

package module
v0.0.0-...-98dbaeb Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2022 License: MIT Imports: 11 Imported by: 0

README

xoxoday API client

// Generate a token and OAuth tokens here: https://stores.xoxoday.com/admin/accounts/platform-preferences/
const t = `{"success":1,"status":200,"access_token":"eyJ...`

var token xoxoday.Token
if err := json.Unmarshal([]byte(t), &token); err != nil {
    return fmt.Errorf("failed to parse token: %w", err)
}

api := xoxoday.New(
    context.Background(),
    xoxoday.EnvDevelopment,
    token,
    xoxoday.OAuthConfig{
        ClientID:     "As generated on the URL above",
        ClientSecret: "As generated on the URL above",
    },
)

res, err := api.Balance()
if err != nil {
    return fmt.Errorf("failed to get balance: %w", err)
}

fmt.Printf("Balance: %f%s\n", res.Points, res.Currency)

Documentation

Index

Constants

View Source
const (
	EnvDevelopment env = iota
	EnvProduction
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

func New

func New(
	ctx context.Context,
	env env,
	t Token,
	oac OAuthConfig,
) *API

func (*API) Balance

func (a *API) Balance() (*BalanceResponse, error)

func (*API) Filters

func (a *API) Filters(data FiltersRequestData) ([]FiltersResponse, error)

func (*API) OrderDetails

func (a *API) OrderDetails(data OrderDetailsRequestData) (*OrderDetailsResponse, error)

func (*API) OrderHistory

func (a *API) OrderHistory(data OrderHistoryRequestData) ([]OrderHistoryResponse, error)

func (*API) PlaceOrder

func (a *API) PlaceOrder(data PlaceOrderRequestData) (*PlaceOrderResponse, error)

func (*API) Run

func (a *API) Run(r Request) ([]byte, error)

func (*API) Vouchers

func (a *API) Vouchers(data VouchersRequestData) ([]VouchersResponse, error)

type BalanceResponse

type BalanceResponse struct {
	Points   float64 `json:"points"`
	Value    float64 `json:"value"`
	Currency string  `json:"currency"`
}

type Error

type Error struct {
	Code      int         `json:"code"`
	ErrorID   string      `json:"errorId"`
	ErrorInfo string      `json:"errorInfo"`
	Errors    interface{} `json:"error"`
}

func (Error) Error

func (e Error) Error() string

type FiltersRequestData

type FiltersRequestData struct {
	FilterGroupCode string `json:"filterGroupCode"`
	IncludeFilters  string `json:"includeFilters"`
	ExcludeFilters  string `json:"excludeFilters"`
}

type FiltersResponse

type FiltersResponse struct {
	FilterGroupName        string `json:"filterGroupName"`
	FilterGroupDescription string `json:"filterGroupDescription"`
	FilterGroupCode        string `json:"filterGroupCode"`
	Filters                []struct {
		FilterValue     string `json:"filterValue"`
		ISOCode         string `json:"isoCode"`
		FilterValueCode string `json:"filterValueCode"`
	} `json:"filters"`
}

type OAuthConfig

type OAuthConfig oauth2.Config

type OrderDetailsRequestData

type OrderDetailsRequestData struct {
	OrderID  int    `json:"orderId"`
	PONumber string `json:"poNumber"`
}

type OrderDetailsResponse

type OrderDetailsResponse struct {
	OrderID       int       `json:"orderId"`
	Vouchers      []Voucher `json:"vouchers"`
	AmountCharged float64   `json:"amountCharged"`
	CurrencyCode  string    `json:"currencyCode"`
	CurrencyValue float64   `json:"currencyValue"`
	Tag           string    `json:"tag"`
	// NOTE: API doc says that this is a float, when in fact it's a string
	DiscountPercent string `json:"discountPercent"`
	// NOTE: API doc says that this is a float, when in fact it's a string
	OrderDiscount  string  `json:"orderDiscount"`
	OrderTotal     float64 `json:"orderTotal"`
	OrderStatus    string  `json:"orderStatus"`
	DeliveryStatus string  `json:"deliveryStatus"`
}

type OrderHistoryRequestData

type OrderHistoryRequestData struct {
	StartDate string `json:"startDate"`
	EndDate   string `json:"endDate"`
	Limit     int    `json:"limit"`
	Page      int    `json:"page"`
}

func (*OrderHistoryRequestData) SetStartEnd

func (rd *OrderHistoryRequestData) SetStartEnd(start, end time.Time) *OrderHistoryRequestData

type OrderHistoryResponse

type OrderHistoryResponse struct {
	OrderID        int      `json:"orderId"`
	OrderDate      jsonTime `json:"orderDate"`
	EMail          string   `json:"email"`
	DeliveryStatus string   `json:"deliveryStatus"`
	Tag            string   `json:"tag"`
	PONumber       string   `json:"poNumber"`
	Products       []struct {
		ProductName          string  `json:"productName"`
		ReceiverMobileNumber string  `json:"receiverMobileNumber"`
		Price                float64 `json:"price"`
		Quantity             int     `json:"quantity"`
		OrderProductStatus   string  `json:"orderProductStatus"`
	} `json:"products"`
}

type PlaceOrderRequestData

type PlaceOrderRequestData struct {
	ProductID           int         `json:"productId"`
	Quantity            int         `json:"quantity"`
	Denomination        int         `json:"denomination"`
	EMail               string      `json:"email"`
	Contact             string      `json:"contact"`
	Tag                 string      `json:"tag"`
	PONumber            string      `json:"poNumber"`
	NotifyAdminEMail    jsonBoolInt `json:"notifyAdminEmail"`
	NotifyReceiverEMail jsonBoolInt `json:"notifyReceiverEmail"`
}

func (*PlaceOrderRequestData) SetNotifyAdminEMail

func (rd *PlaceOrderRequestData) SetNotifyAdminEMail(b bool) *PlaceOrderRequestData

func (*PlaceOrderRequestData) SetNotifyReceiverEMail

func (rd *PlaceOrderRequestData) SetNotifyReceiverEMail(b bool) *PlaceOrderRequestData

type PlaceOrderResponse

type PlaceOrderResponse struct {
	OrderID       int       `json:"orderId"`
	Vouchers      []Voucher `json:"vouchers"`
	AmountCharged float64   `json:"amountCharged"`
	CurrencyCode  string    `json:"currencyCode"`
	CurrencyValue float64   `json:"currencyValue"`
	Tag           string    `json:"tag"`
	// NOTE: API doc says that this is a float, when in fact it's a string
	DiscountPercent string `json:"discountPercent"`
	// NOTE: API doc says that this is a float, when in fact it's a string
	OrderDiscount  string  `json:"orderDiscount"`
	OrderTotal     float64 `json:"orderTotal"`
	OrderStatus    string  `json:"orderStatus"`
	DeliveryStatus string  `json:"deliveryStatus"`
}

type Request

type Request struct {
	Query     string      `json:"query"`
	Tag       string      `json:"tag"`
	Variables RequestData `json:"variables"`
}

type RequestData

type RequestData struct {
	Data interface{} `json:"data"`
}

type Token

type Token struct {
	Success            jsonBoolInt  `json:"success"`
	Status             int          `json:"status"`
	AccessToken        string       `json:"access_token"`
	TokenType          string       `json:"token_type"`
	ExpiresIn          int          `json:"expires_in,string"`
	RefreshToken       string       `json:"refresh_token"`
	AccessTokenExpiry  jsonUnixTime `json:"access_token_expiry"`
	RefreshTokenExpiry jsonUnixTime `json:"refresh_token_expiry"`
}

type Voucher

type Voucher struct {
	Amount        int     `json:"amount"`
	Country       string  `json:"country"`
	Currency      string  `json:"currency"`
	OrderID       int     `json:"orderId"`
	Pin           string  `json:"pin"`
	ProductID     int     `json:"productId"`
	Tag           string  `json:"tag"`
	Type          string  `json:"type"`
	Validity      string  `json:"validity"`
	VoucherCode   string  `json:"voucherCode"`
	CurrencyValue float64 `json:"currencyValue"`
}

type VouchersRequestData

type VouchersRequestData struct {
	Limit           int                         `json:"limit"`
	Page            int                         `json:"page"`
	IncludeProducts string                      `json:"includeProducts"`
	ExcludeProducts string                      `json:"excludeProducts"`
	ExchangeRate    float64                     `json:"exchangeRate"`
	Sort            VouchersRequestDataSort     `json:"sort"`
	Filters         []VouchersRequestDataFilter `json:"filters"`
}

type VouchersRequestDataFilter

type VouchersRequestDataFilter struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type VouchersRequestDataSort

type VouchersRequestDataSort struct {
	Field string `json:"field"`
	Order string `json:"order"`
}

type VouchersResponse

type VouchersResponse struct {
	ProductID                      int      `json:"productId"`
	Name                           string   `json:"name"`
	Description                    string   `json:"description"`
	TermsAndConditionsInstructions string   `json:"termsAndConditionsInstructions"`
	ExpiryAndValidity              string   `json:"expiryAndValidity"`
	RedemptionInstructions         string   `json:"redemptionInstructions"`
	Categories                     string   `json:"categories"`
	LastUpdateDate                 jsonTime `json:"lastUpdateDate"`
	ImageURL                       string   `json:"imageUrl"`
	CurrencyCode                   string   `json:"currencyCode"`
	CurrencyName                   string   `json:"currencyName"`
	CountryName                    string   `json:"countryName"`
	CountryCode                    string   `json:"countryCode"`
	Countries                      []struct {
		Code string `json:"code"`
		Name string `json:"name"`
	} `json:"countries"`
	ExchangeRateRule   float64 `json:"exchangeRateRule"`
	ValueType          string  `json:"valueType"`
	MaxValue           float64 `json:"maxValue"`
	MinValue           float64 `json:"minValue"`
	ValueDenominations string  `json:"valueDenominations"`
	TATInDays          int     `json:"tatInDays"`
	UsageType          string  `json:"usageType"`
	DeliveryType       string  `json:"deliveryType"`
	// TODO: This might need to be a boolean
	IsCommon     string  `json:"isCommon"`
	Fee          float64 `json:"fee"`
	Discount     float64 `json:"discount"`
	ExchangeRate int     `json:"exchangeRate"`
}

Jump to

Keyboard shortcuts

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