Cashbag - This is golang sdk for implement promotion schema

Cashbag

This is golang sdk for implement promotion schema

How to use

package main

import "https://github.com/hualoqueros/cashbag"

func main() {
    promotion := Promo{
		Name:      "TEST",
		StartAt:   time.Now(),
		ExpiredAt: time.Now(),
		Schemas: []Schema{
			Schema{
				AmountType:     AMOUNT_TYPE_SUBTOTAL,
				ConditionType:  CONDITION_TYPE_MIN_PRICE,
				ConditionValue: "5000",
				RewardType:     REWARD_TYPE_DISCOUNT_AMOUNT,
				RewardValue:    "2500",
			},
		},
		AdditionalInfo: "123",
	}

	shoppingCart := ShoppingCart{
		Carts: []Cart{
			Cart{
				Price: 500000,
				Qty:   1,
			},
		},
		Subtotal:   500000,
		GrandTotal: 500000,
	}
	getPromo := NewPromo(promotion)
	rewards, newGrandTotal, totalDeduction, err := getPromo.Calculate(shoppingCart)
}

You can adding custom callback function in calculate using CalculateWithCallback

...
    promotion := Promo{
		Name:      "TEST",
		StartAt:   time.Now(),
		ExpiredAt: time.Now(),
		Schemas: []Schema{
			Schema{
				AmountType:     AMOUNT_TYPE_SUBTOTAL,
				ConditionType:  CONDITION_TYPE_MIN_PRICE,
				ConditionValue: "5000",
				RewardType:     REWARD_TYPE_DISCOUNT_AMOUNT,
				RewardValue:    "2500",
			},
		},
		AdditionalInfo: "123",
	}

	shoppingCart := ShoppingCart{
		Carts: []Cart{
			Cart{
				AdditionalID: "KFC-123",
				Price:        500000,
				Qty:          1,
			},
		},
		Subtotal:   500000,
		GrandTotal: 500000,
	}
	getPromo := NewPromo(promotion)
	// here we can create our own validation,
	// in this case, we validate the qty minimum is larger than 10
	checkingSKUAvailibilty := func() (err error) {
		for _, cart := range shoppingCart.Carts {
			skuIsNotAvailable := true
			if cart.Qty < 10 {
			    skuIsNotAvailable = false
			}
			if !skuIsNotAvailable {
				return errors.New(fmt.Sprintf("Please add more quantity for SKU %+s", cart.AdditionalID))
			}
		}
		return nil
	}

	_, _, _, err := getPromo.CalculateWithCallback(shoppingCart, checkingSKUAvailibilty)
...
Similar Resources

Confluent Golang SDK

Confluent Platform Client Maintainer: Quan Phuong [email protected] Provide Go client for Confluent platform, reference Confluent API document and C

Oct 11, 2021

百度ai golang SDK

BauDuAi 百度人工智能模块go语言SDK,持续更新中 安装 go get github.com/iscoderLee/BaiDuAi 使用说明 使用示例(人脸检测接口) package main import ( "encoding/base64" "fmt" "github.c

Dec 27, 2022

sdk for filedag in golang

FileDAG SDK Official GO SDK for FileDAG Overview The FileDAG GO SDK provides the quickest / easiest path for interacting with the FileDAG API. Install

Aug 18, 2021

golang sdk for BRCC ( BRCC:Better Remote Config Center)

golang sdk for BRCC ( BRCC:Better Remote Config Center)

brcc-go-sdk golang sdk for BRCC BRCC:Better Remote Config Center

Dec 6, 2021

Golang SDK du Logiciel de Facturation en ligne VosFactures

Golang VosFactures Implémentation sommaire de l'API VosFactures en Golang. Ce projet n'est pas complet, il l'est suffisamment pour les fonctionnalités

Oct 15, 2021

SSL wireless Golang SDK

ssl-wireless-pgw-golang-sdk (Beta) SSLCOMMERZ is the first payment gateway in Bangladesh opening doors for merchants to receive payments on the intern

Jan 18, 2022

🚀 BiliBili API SDK in Golang

🚀 BiliBili API SDK in Golang

BiliGO BiliBili API SDK in Golang 简介 BiliBili API 的 Golang 实现,目前已经实现了 100+ API,还在进一步更新中 特性 良好的设计,支持自定义 client 与 UA 完善的单元测试,易懂的函数命名,极少的第三方库依赖 代码、结构体注释完

Nov 13, 2022

A Golang SDK for binance API

go-binance A Golang SDK for binance API. All the REST APIs listed in binance API document are implemented, as well as the websocket APIs. For best com

Oct 28, 2021

Zenvia API - Golang SDK

Zenvia API - Golang SDK Zenvia API (2.0) Why? This project is part of my personal portfolio, so, I'll be happy if you could provide me any feedback ab

Nov 5, 2021
Nextengine-sdk-go: the NextEngine SDK for the Go programming language

NextEngine SDK for Go nextengine-sdk-go is the NextEngine SDK for the Go programming language. Getting Started Install go get github.com/takaaki-s/nex

Dec 7, 2021
Commercetools-go-sdk is fork of original commercetools-go-sdk

commercetools-go-sdk The Commercetools Go SDK is automatically generated based on the official API specifications of Commercetools. It should therefor

Dec 13, 2021
Sdk-go - Go version of the Synapse SDK

synapsesdk-go Synapse Protocol's Go SDK. Currently in super duper alpha, do not

Jan 7, 2022
Redash-go-sdk - An SDK for the programmatic management of Redash, in Go
Redash-go-sdk - An SDK for the programmatic management of Redash, in Go

Redash Go SDK An SDK for the programmatic management of Redash. The main compone

Dec 13, 2022
An unofficial package in Golang to help developers implement ZATCA (Fatoora) QR code easily.

Zatca SDK GO An unofficial package in Golang to help developers to implement ZATCA (Fatoora) QR code easily which required for e-invoicing ✅ The hash

Jan 1, 2023
A Golang SDK for Medium's OAuth2 API

Medium SDK for Go This repository contains the open source SDK for integrating Medium's OAuth2 API into your Go app. Install go get github.com/Medium/

Nov 28, 2022
Simple no frills AWS S3 Golang Library using REST with V4 Signing (without AWS Go SDK)

simples3 : Simple no frills AWS S3 Library using REST with V4 Signing Overview SimpleS3 is a golang library for uploading and deleting objects on S3 b

Nov 4, 2022
Twilight is an unofficial Golang SDK for Twilio APIs
Twilight is an unofficial Golang SDK for Twilio APIs

Twilight is an unofficial Golang SDK for Twilio APIs. Twilight was born as a result of my inability to spell Twilio correctly. I searched for a Twillio Golang client library and couldn’t find any, I decided to build one. Halfway through building this, I realized I had spelled Twilio as Twillio when searching for a client library on Github.

Jul 2, 2021
weixin/wechat/微信公众平台/微信企业号/微信商户平台/微信支付 go/golang sdk
weixin/wechat/微信公众平台/微信企业号/微信商户平台/微信支付 go/golang sdk

wechat SDK for golang https://github.com/chanxuehong/wechat 招人啦 golang 后端的坑, 趣头条集团下面的创新团队, 现在步入正常轨道了, 前景很好. 要求: golang中高级 自驱、有责任心 沟通没有问题 待遇: open, 看能力

Dec 30, 2022
DipDup Golang SDK

General instruments for DipDup in golang

Dec 14, 2022