From 8454bdfc9da29e4759294ac46ae36444838476a4 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Tue, 18 Jul 2023 16:15:40 +0800 Subject: [PATCH 01/14] feat: Support stripe --- dao/t_das_order_info.go | 14 +++++++++ http_server/handle/order_change.go | 32 +++++++++++++++---- http_server/handle/order_register.go | 46 ++++++++++++++++++++-------- http_server/handle/order_renew.go | 34 ++++++++++++++++---- tables/t_das_order_info.go | 6 ++++ unipay/unipay.go | 13 +++++--- 6 files changed, 116 insertions(+), 29 deletions(-) diff --git a/dao/t_das_order_info.go b/dao/t_das_order_info.go index cf26eec7..0f5597e3 100644 --- a/dao/t_das_order_info.go +++ b/dao/t_das_order_info.go @@ -130,6 +130,20 @@ func (d *DbDao) CreateOrder(order *tables.TableDasOrderInfo) error { return d.db.Create(&order).Error } +func (d *DbDao) CreateOrderWithPayment(order tables.TableDasOrderInfo, payment tables.TableDasOrderPayInfo) error { + return d.db.Transaction(func(tx *gorm.DB) error { + if err := tx.Create(&order).Error; err != nil { + return err + } + if payment.Hash != "" { + if err := tx.Create(&payment).Error; err != nil { + return err + } + } + return nil + }) +} + func (d *DbDao) CreateCouponOrder(order *tables.TableDasOrderInfo, coupon string) error { return d.db.Transaction(func(tx *gorm.DB) error { if err := tx.Create(order).Error; err != nil { diff --git a/http_server/handle/order_change.go b/http_server/handle/order_change.go index 7e501c32..f97fa8b3 100644 --- a/http_server/handle/order_change.go +++ b/http_server/handle/order_change.go @@ -39,8 +39,12 @@ type RespOrderChange struct { TokenId tables.PayTokenId `json:"token_id"` ReceiptAddress string `json:"receipt_address"` Amount decimal.Decimal `json:"amount"` - CodeUrl string `json:"code_url"` - PayType tables.PayType `json:"pay_type"` + //CodeUrl string `json:"code_url"` + //PayType tables.PayType `json:"pay_type"` + ContractAddress string `json:"contract_address"` + ClientSecret string `json:"client_secret"` + PremiumPercentage decimal.Decimal `json:"premium_percentage"` + PremiumBase decimal.Decimal `json:"premium_base"` } func (h *HttpHandle) RpcOrderChange(p json.RawMessage, apiResp *api_code.ApiResp) { @@ -202,6 +206,7 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, } var order tables.TableDasOrderInfo + var paymentInfo tables.TableDasOrderPayInfo // unipay if config.Cfg.Server.UniPayUrl != "" { addrNormal, err := h.dasCore.Daf().HexToNormal(core.DasAddressHex{ @@ -243,7 +248,7 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, Timestamp: time.Now().UnixNano() / 1e6, PayTokenId: req.PayTokenId, PayType: req.PayType, - PayAmount: amountTotalPayToken, + PayAmount: res.Amount, Content: string(contentDataStr), PayStatus: tables.TxStatusDefault, HedgeStatus: tables.TxStatusDefault, @@ -254,6 +259,21 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, CrossCoinType: req.CrossCoinType, IsUniPay: tables.IsUniPayTrue, } + if req.PayTokenId == tables.TokenIdStripeUSD && res.StripePaymentIntentId != "" { + paymentInfo = tables.TableDasOrderPayInfo{ + Hash: res.StripePaymentIntentId, + OrderId: res.OrderId, + ChainType: order.ChainType, + Address: order.Address, + Status: tables.OrderTxStatusDefault, + Timestamp: time.Now().UnixMilli(), + AccountId: order.AccountId, + } + } + resp.ContractAddress = res.ContractAddress + resp.ClientSecret = res.ClientSecret + resp.PremiumPercentage = res.PremiumPercentage + resp.PremiumBase = res.PremiumBase } else { order = tables.TableDasOrderInfo{ Id: 0, @@ -282,9 +302,9 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, resp.OrderId = order.OrderId resp.TokenId = req.PayTokenId - resp.PayType = req.PayType + //resp.PayType = req.PayType resp.Amount = order.PayAmount - resp.CodeUrl = "" + //resp.CodeUrl = "" if addr, ok := config.Cfg.PayAddressMap[order.PayTokenId.ToChainString()]; !ok { apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("not supported [%s]", order.PayTokenId)) return @@ -292,7 +312,7 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, resp.ReceiptAddress = addr } - if err := h.dbDao.CreateOrder(&order); err != nil { + if err := h.dbDao.CreateOrderWithPayment(order, paymentInfo); err != nil { log.Error("CreateOrder err:", err.Error()) apiResp.ApiRespErr(api_code.ApiCodeError500, "create order fail") return diff --git a/http_server/handle/order_register.go b/http_server/handle/order_register.go index 771e7d5c..1f4d48bc 100644 --- a/http_server/handle/order_register.go +++ b/http_server/handle/order_register.go @@ -51,12 +51,16 @@ type ReqOrderRegisterBase struct { } type RespOrderRegister struct { - OrderId string `json:"order_id"` - TokenId tables.PayTokenId `json:"token_id"` - ReceiptAddress string `json:"receipt_address"` - Amount decimal.Decimal `json:"amount"` - CodeUrl string `json:"code_url"` - PayType tables.PayType `json:"pay_type"` + OrderId string `json:"order_id"` + TokenId tables.PayTokenId `json:"token_id"` + ReceiptAddress string `json:"receipt_address"` + Amount decimal.Decimal `json:"amount"` + ContractAddress string `json:"contract_address"` + ClientSecret string `json:"client_secret"` + PremiumPercentage decimal.Decimal `json:"premium_percentage"` + PremiumBase decimal.Decimal `json:"premium_base"` + //CodeUrl string `json:"code_url"` + //PayType tables.PayType `json:"pay_type"` } type AccountAttr struct { @@ -420,6 +424,7 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap } var order tables.TableDasOrderInfo + var paymentInfo tables.TableDasOrderPayInfo // unipay if config.Cfg.Server.UniPayUrl != "" { addrNormal, err := h.dasCore.Daf().HexToNormal(core.DasAddressHex{ @@ -461,7 +466,7 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap Timestamp: time.Now().UnixNano() / 1e6, PayTokenId: req.PayTokenId, PayType: req.PayType, - PayAmount: amountTotalPayToken, + PayAmount: res.Amount, Content: string(contentDataStr), PayStatus: tables.TxStatusDefault, HedgeStatus: tables.TxStatusDefault, @@ -471,7 +476,24 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap CoinType: req.CoinType, CrossCoinType: req.CrossCoinType, IsUniPay: tables.IsUniPayTrue, + PremiumPercentage: res.PremiumPercentage, + PremiumBase: res.PremiumBase, + } + if req.PayTokenId == tables.TokenIdStripeUSD && res.StripePaymentIntentId != "" { + paymentInfo = tables.TableDasOrderPayInfo{ + Hash: res.StripePaymentIntentId, + OrderId: res.OrderId, + ChainType: order.ChainType, + Address: order.Address, + Status: tables.OrderTxStatusDefault, + Timestamp: time.Now().UnixMilli(), + AccountId: order.AccountId, + } } + resp.ContractAddress = res.ContractAddress + resp.ClientSecret = res.ClientSecret + resp.PremiumPercentage = res.PremiumPercentage + resp.PremiumBase = res.PremiumBase } else { order = tables.TableDasOrderInfo{ OrderType: tables.OrderTypeSelf, @@ -499,9 +521,9 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap resp.OrderId = order.OrderId resp.TokenId = req.PayTokenId - resp.PayType = req.PayType + //resp.PayType = req.PayType resp.Amount = order.PayAmount - resp.CodeUrl = "" + //resp.CodeUrl = "" if addr, ok := config.Cfg.PayAddressMap[order.PayTokenId.ToChainString()]; !ok { apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("not supported [%s]", order.PayTokenId)) @@ -510,7 +532,7 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap resp.ReceiptAddress = addr } - if err := h.dbDao.CreateOrder(&order); err != nil { + if err := h.dbDao.CreateOrderWithPayment(order, paymentInfo); err != nil { log.Error("CreateOrder err:", err.Error()) apiResp.ApiRespErr(api_code.ApiCodeError500, "create order fail") return @@ -635,9 +657,9 @@ func (h *HttpHandle) doRegisterCouponOrder(req *ReqOrderRegister, apiResp *api_c resp.OrderId = order.OrderId resp.TokenId = req.PayTokenId - resp.PayType = req.PayType + //resp.PayType = req.PayType resp.Amount = order.PayAmount - resp.CodeUrl = "" + //resp.CodeUrl = "" err = h.dbDao.CreateCouponOrder(&order, coupon.Code) if redisErr := h.rc.DeleteCouponLockWithRedis(coupon.Code); redisErr != nil { diff --git a/http_server/handle/order_renew.go b/http_server/handle/order_renew.go index 79b59079..7135e3ef 100644 --- a/http_server/handle/order_renew.go +++ b/http_server/handle/order_renew.go @@ -39,8 +39,12 @@ type RespOrderRenew struct { TokenId tables.PayTokenId `json:"token_id"` ReceiptAddress string `json:"receipt_address"` Amount decimal.Decimal `json:"amount"` - CodeUrl string `json:"code_url"` - PayType tables.PayType `json:"pay_type"` + //CodeUrl string `json:"code_url"` + //PayType tables.PayType `json:"pay_type"` + ContractAddress string `json:"contract_address"` + ClientSecret string `json:"client_secret"` + PremiumPercentage decimal.Decimal `json:"premium_percentage"` + PremiumBase decimal.Decimal `json:"premium_base"` } func (h *HttpHandle) RpcOrderRenew(p json.RawMessage, apiResp *api_code.ApiResp) { @@ -219,6 +223,7 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen } // unipay var order tables.TableDasOrderInfo + var paymentInfo tables.TableDasOrderPayInfo if config.Cfg.Server.UniPayUrl != "" { addrNormal, err := h.dasCore.Daf().HexToNormal(core.DasAddressHex{ DasAlgorithmId: req.ChainType.ToDasAlgorithmId(true), @@ -259,7 +264,7 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen Timestamp: time.Now().UnixNano() / 1e6, PayTokenId: req.PayTokenId, PayType: req.PayType, - PayAmount: amountTotalPayToken, + PayAmount: res.Amount, Content: string(contentDataStr), PayStatus: tables.TxStatusDefault, HedgeStatus: tables.TxStatusDefault, @@ -267,7 +272,24 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen RegisterStatus: tables.RegisterStatusDefault, OrderStatus: tables.OrderStatusDefault, IsUniPay: tables.IsUniPayTrue, + PremiumPercentage: res.PremiumPercentage, + PremiumBase: res.PremiumBase, + } + if req.PayTokenId == tables.TokenIdStripeUSD && res.StripePaymentIntentId != "" { + paymentInfo = tables.TableDasOrderPayInfo{ + Hash: res.StripePaymentIntentId, + OrderId: res.OrderId, + ChainType: order.ChainType, + Address: order.Address, + Status: tables.OrderTxStatusDefault, + Timestamp: time.Now().UnixMilli(), + AccountId: order.AccountId, + } } + resp.ContractAddress = res.ContractAddress + resp.ClientSecret = res.ClientSecret + resp.PremiumPercentage = res.PremiumPercentage + resp.PremiumBase = res.PremiumBase } else { order = tables.TableDasOrderInfo{ OrderType: tables.OrderTypeSelf, @@ -293,9 +315,9 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen resp.OrderId = order.OrderId resp.TokenId = req.PayTokenId - resp.PayType = req.PayType + //resp.PayType = req.PayType resp.Amount = order.PayAmount - resp.CodeUrl = "" + //resp.CodeUrl = "" if addr, ok := config.Cfg.PayAddressMap[order.PayTokenId.ToChainString()]; !ok { apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("not supported [%s]", order.PayTokenId)) return @@ -303,7 +325,7 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen resp.ReceiptAddress = addr } - if err := h.dbDao.CreateOrder(&order); err != nil { + if err := h.dbDao.CreateOrderWithPayment(order, paymentInfo); err != nil { log.Error("CreateOrder err:", err.Error()) apiResp.ApiRespErr(api_code.ApiCodeError500, "create order fail") return diff --git a/tables/t_das_order_info.go b/tables/t_das_order_info.go index e6c4795a..d5857ace 100644 --- a/tables/t_das_order_info.go +++ b/tables/t_das_order_info.go @@ -32,6 +32,8 @@ type TableDasOrderInfo struct { CoinType string `json:"coin_type" gorm:"column:coin_type; type:varchar(255) NOT NULL DEFAULT '';"` CrossCoinType string `json:"cross_coin_type" gorm:"column:cross_coin_type; type:varchar(255) NOT NULL DEFAULT '';"` IsUniPay IsUniPay `json:"is_uni_pay" gorm:"column:is_uni_pay; type:smallint(6) NOT NULL DEFAULT '0' COMMENT '0-no 1-yes';"` + PremiumPercentage decimal.Decimal `json:"premium_percentage" gorm:"column:premium_percentage; type:decimal(20,10) NOT NULL DEFAULT '0' COMMENT '';"` + PremiumBase decimal.Decimal `json:"premium_base" gorm:"column:premium_base; type:decimal(20,10) NOT NULL DEFAULT '0' COMMENT '';"` CreatedAt time.Time `json:"created_at" gorm:"column:created_at;type:timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ''"` UpdatedAt time.Time `json:"updated_at" gorm:"column:updated_at;type:timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ''"` } @@ -91,6 +93,10 @@ const ( TokenIdMatic PayTokenId = "polygon_matic" TokenCoupon PayTokenId = "coupon" TokenIdDoge PayTokenId = "doge_doge" + TokenIdStripeUSD PayTokenId = "stripe_usd" + TokenIdErc20USDT PayTokenId = "eth_erc20_usdt" + TokenIdTrc20USDT PayTokenId = "tron_trc20_usdt" + TokenIdBep20USDT PayTokenId = "bsc_bep20_usdt" ) func (p PayTokenId) IsTokenIdCkbInternal() bool { diff --git a/unipay/unipay.go b/unipay/unipay.go index 6f05b9f3..869a69ea 100644 --- a/unipay/unipay.go +++ b/unipay/unipay.go @@ -31,11 +31,14 @@ type ReqOrderCreate struct { } type RespOrderCreate struct { - OrderId string `json:"order_id"` - PaymentAddress string `json:"payment_address"` - ContractAddress string `json:"contract_address"` - StripePaymentIntentId string `json:"stripe_payment_intent_id"` - ClientSecret string `json:"client_secret"` + OrderId string `json:"order_id"` + PaymentAddress string `json:"payment_address"` + ContractAddress string `json:"contract_address"` + StripePaymentIntentId string `json:"stripe_payment_intent_id"` + ClientSecret string `json:"client_secret"` + Amount decimal.Decimal `json:"amount"` + PremiumPercentage decimal.Decimal `json:"premium_percentage"` + PremiumBase decimal.Decimal `json:"premium_base"` } func CreateOrder(req ReqOrderCreate) (resp RespOrderCreate, err error) { From a87d2481968d4a67acf6f2061a6f6d0df3f78f5b Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Thu, 27 Jul 2023 09:54:38 +0800 Subject: [PATCH 02/14] feat: Support stripe --- config/config.go | 4 +++ http_server/handle/account_search.go | 18 +++++++----- http_server/handle/order_change.go | 42 ++++++++++++++------------ http_server/handle/order_register.go | 44 +++++++++++++++------------- http_server/handle/order_renew.go | 44 +++++++++++++++------------- unipay/unipay.go | 23 +++++++-------- 6 files changed, 95 insertions(+), 80 deletions(-) diff --git a/config/config.go b/config/config.go index 56ef448c..b1bda73c 100644 --- a/config/config.go +++ b/config/config.go @@ -112,6 +112,10 @@ type CfgServer struct { Premium decimal.Decimal `json:"premium" yaml:"premium"` Discount decimal.Decimal `json:"discount" yaml:"discount"` } `json:"das" yaml:"das"` + Stripe struct { + PremiumPercentage decimal.Decimal `json:"premium_percentage" yaml:"premium_percentage"` + PremiumBase decimal.Decimal `json:"premium_base" yaml:"premium_base"` + } `json:"stripe" yaml:"stripe"` } type DbMysql struct { diff --git a/http_server/handle/account_search.go b/http_server/handle/account_search.go index 65f0013a..a83aec26 100644 --- a/http_server/handle/account_search.go +++ b/http_server/handle/account_search.go @@ -24,13 +24,15 @@ type ReqAccountSearch struct { } type RespAccountSearch struct { - Status tables.SearchStatus `json:"status"` - Account string `json:"account"` - AccountPrice decimal.Decimal `json:"account_price"` - BaseAmount decimal.Decimal `json:"base_amount"` - IsSelf bool `json:"is_self"` - RegisterTxMap map[tables.RegisterStatus]RegisterTx `json:"register_tx_map"` - OpenTimestamp int64 `json:"open_timestamp"` + Status tables.SearchStatus `json:"status"` + Account string `json:"account"` + AccountPrice decimal.Decimal `json:"account_price"` + BaseAmount decimal.Decimal `json:"base_amount"` + IsSelf bool `json:"is_self"` + RegisterTxMap map[tables.RegisterStatus]RegisterTx `json:"register_tx_map"` + OpenTimestamp int64 `json:"open_timestamp"` + PremiumPercentage decimal.Decimal `json:"premium_percentage"` + PremiumBase decimal.Decimal `json:"premium_base"` } type RegisterTx struct { @@ -83,6 +85,8 @@ func (h *HttpHandle) AccountSearch(ctx *gin.Context) { func (h *HttpHandle) doAccountSearch(req *ReqAccountSearch, apiResp *api_code.ApiResp) error { var resp RespAccountSearch resp.RegisterTxMap = make(map[tables.RegisterStatus]RegisterTx) + resp.PremiumPercentage = config.Cfg.Stripe.PremiumPercentage + resp.PremiumBase = config.Cfg.Stripe.PremiumBase if req.ChainType == common.ChainTypeCkb || req.Address == "" { diff --git a/http_server/handle/order_change.go b/http_server/handle/order_change.go index f97fa8b3..bfcb74e3 100644 --- a/http_server/handle/order_change.go +++ b/http_server/handle/order_change.go @@ -35,16 +35,12 @@ type ReqOrderChange struct { } type RespOrderChange struct { - OrderId string `json:"order_id"` - TokenId tables.PayTokenId `json:"token_id"` - ReceiptAddress string `json:"receipt_address"` - Amount decimal.Decimal `json:"amount"` - //CodeUrl string `json:"code_url"` - //PayType tables.PayType `json:"pay_type"` - ContractAddress string `json:"contract_address"` - ClientSecret string `json:"client_secret"` - PremiumPercentage decimal.Decimal `json:"premium_percentage"` - PremiumBase decimal.Decimal `json:"premium_base"` + OrderId string `json:"order_id"` + TokenId tables.PayTokenId `json:"token_id"` + ReceiptAddress string `json:"receipt_address"` + Amount decimal.Decimal `json:"amount"` + ContractAddress string `json:"contract_address"` + ClientSecret string `json:"client_secret"` } func (h *HttpHandle) RpcOrderChange(p json.RawMessage, apiResp *api_code.ApiResp) { @@ -220,6 +216,14 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("HexToNormal err: %s", err.Error())) return } + premiumPercentage := decimal.Zero + premiumBase := decimal.Zero + if req.PayTokenId == tables.TokenIdStripeUSD { + premiumPercentage = config.Cfg.Stripe.PremiumPercentage + premiumBase = config.Cfg.Stripe.PremiumBase + amountTotalPayToken = amountTotalPayToken.Mul(premiumPercentage.Add(decimal.NewFromInt(1))).Add(premiumBase.Mul(decimal.NewFromInt(100))) + amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.IntPart()) + } res, err := unipay.CreateOrder(unipay.ReqOrderCreate{ ChainTypeAddress: core.ChainTypeAddress{ Type: "blockchain", @@ -228,10 +232,12 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, Key: addrNormal.AddressNormal, }, }, - BusinessId: unipay.BusinessIdDasRegisterSvr, - Amount: amountTotalPayToken, - PayTokenId: req.PayTokenId, - PaymentAddress: config.GetUnipayAddress(req.PayTokenId), + BusinessId: unipay.BusinessIdDasRegisterSvr, + Amount: amountTotalPayToken, + PayTokenId: req.PayTokenId, + PaymentAddress: config.GetUnipayAddress(req.PayTokenId), + PremiumPercentage: premiumPercentage, + PremiumBase: premiumBase, }) if err != nil { apiResp.ApiRespErr(api_code.ApiCodeError500, "Failed to create order by unipay") @@ -248,7 +254,7 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, Timestamp: time.Now().UnixNano() / 1e6, PayTokenId: req.PayTokenId, PayType: req.PayType, - PayAmount: res.Amount, + PayAmount: amountTotalPayToken, Content: string(contentDataStr), PayStatus: tables.TxStatusDefault, HedgeStatus: tables.TxStatusDefault, @@ -258,6 +264,8 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, CoinType: req.CoinType, CrossCoinType: req.CrossCoinType, IsUniPay: tables.IsUniPayTrue, + PremiumPercentage: premiumPercentage, + PremiumBase: premiumBase, } if req.PayTokenId == tables.TokenIdStripeUSD && res.StripePaymentIntentId != "" { paymentInfo = tables.TableDasOrderPayInfo{ @@ -272,8 +280,6 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, } resp.ContractAddress = res.ContractAddress resp.ClientSecret = res.ClientSecret - resp.PremiumPercentage = res.PremiumPercentage - resp.PremiumBase = res.PremiumBase } else { order = tables.TableDasOrderInfo{ Id: 0, @@ -302,9 +308,7 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, resp.OrderId = order.OrderId resp.TokenId = req.PayTokenId - //resp.PayType = req.PayType resp.Amount = order.PayAmount - //resp.CodeUrl = "" if addr, ok := config.Cfg.PayAddressMap[order.PayTokenId.ToChainString()]; !ok { apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("not supported [%s]", order.PayTokenId)) return diff --git a/http_server/handle/order_register.go b/http_server/handle/order_register.go index 1f4d48bc..fb312b5d 100644 --- a/http_server/handle/order_register.go +++ b/http_server/handle/order_register.go @@ -51,16 +51,12 @@ type ReqOrderRegisterBase struct { } type RespOrderRegister struct { - OrderId string `json:"order_id"` - TokenId tables.PayTokenId `json:"token_id"` - ReceiptAddress string `json:"receipt_address"` - Amount decimal.Decimal `json:"amount"` - ContractAddress string `json:"contract_address"` - ClientSecret string `json:"client_secret"` - PremiumPercentage decimal.Decimal `json:"premium_percentage"` - PremiumBase decimal.Decimal `json:"premium_base"` - //CodeUrl string `json:"code_url"` - //PayType tables.PayType `json:"pay_type"` + OrderId string `json:"order_id"` + TokenId tables.PayTokenId `json:"token_id"` + ReceiptAddress string `json:"receipt_address"` + Amount decimal.Decimal `json:"amount"` + ContractAddress string `json:"contract_address"` + ClientSecret string `json:"client_secret"` } type AccountAttr struct { @@ -438,6 +434,14 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("HexToNormal err: %s", err.Error())) return } + premiumPercentage := decimal.Zero + premiumBase := decimal.Zero + if req.PayTokenId == tables.TokenIdStripeUSD { + premiumPercentage = config.Cfg.Stripe.PremiumPercentage + premiumBase = config.Cfg.Stripe.PremiumBase + amountTotalPayToken = amountTotalPayToken.Mul(premiumPercentage.Add(decimal.NewFromInt(1))).Add(premiumBase.Mul(decimal.NewFromInt(100))) + amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.IntPart()) + } res, err := unipay.CreateOrder(unipay.ReqOrderCreate{ ChainTypeAddress: core.ChainTypeAddress{ Type: "blockchain", @@ -446,10 +450,12 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap Key: addrNormal.AddressNormal, }, }, - BusinessId: unipay.BusinessIdDasRegisterSvr, - Amount: amountTotalPayToken, - PayTokenId: req.PayTokenId, - PaymentAddress: config.GetUnipayAddress(req.PayTokenId), + BusinessId: unipay.BusinessIdDasRegisterSvr, + Amount: amountTotalPayToken, + PayTokenId: req.PayTokenId, + PaymentAddress: config.GetUnipayAddress(req.PayTokenId), + PremiumPercentage: premiumPercentage, + PremiumBase: premiumBase, }) if err != nil { apiResp.ApiRespErr(api_code.ApiCodeError500, "Failed to create order by unipay") @@ -466,7 +472,7 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap Timestamp: time.Now().UnixNano() / 1e6, PayTokenId: req.PayTokenId, PayType: req.PayType, - PayAmount: res.Amount, + PayAmount: amountTotalPayToken, Content: string(contentDataStr), PayStatus: tables.TxStatusDefault, HedgeStatus: tables.TxStatusDefault, @@ -476,8 +482,8 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap CoinType: req.CoinType, CrossCoinType: req.CrossCoinType, IsUniPay: tables.IsUniPayTrue, - PremiumPercentage: res.PremiumPercentage, - PremiumBase: res.PremiumBase, + PremiumPercentage: premiumPercentage, + PremiumBase: premiumBase, } if req.PayTokenId == tables.TokenIdStripeUSD && res.StripePaymentIntentId != "" { paymentInfo = tables.TableDasOrderPayInfo{ @@ -492,8 +498,6 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap } resp.ContractAddress = res.ContractAddress resp.ClientSecret = res.ClientSecret - resp.PremiumPercentage = res.PremiumPercentage - resp.PremiumBase = res.PremiumBase } else { order = tables.TableDasOrderInfo{ OrderType: tables.OrderTypeSelf, @@ -521,9 +525,7 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap resp.OrderId = order.OrderId resp.TokenId = req.PayTokenId - //resp.PayType = req.PayType resp.Amount = order.PayAmount - //resp.CodeUrl = "" if addr, ok := config.Cfg.PayAddressMap[order.PayTokenId.ToChainString()]; !ok { apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("not supported [%s]", order.PayTokenId)) diff --git a/http_server/handle/order_renew.go b/http_server/handle/order_renew.go index 7135e3ef..bcea860f 100644 --- a/http_server/handle/order_renew.go +++ b/http_server/handle/order_renew.go @@ -35,16 +35,12 @@ type ReqOrderRenew struct { } type RespOrderRenew struct { - OrderId string `json:"order_id"` - TokenId tables.PayTokenId `json:"token_id"` - ReceiptAddress string `json:"receipt_address"` - Amount decimal.Decimal `json:"amount"` - //CodeUrl string `json:"code_url"` - //PayType tables.PayType `json:"pay_type"` - ContractAddress string `json:"contract_address"` - ClientSecret string `json:"client_secret"` - PremiumPercentage decimal.Decimal `json:"premium_percentage"` - PremiumBase decimal.Decimal `json:"premium_base"` + OrderId string `json:"order_id"` + TokenId tables.PayTokenId `json:"token_id"` + ReceiptAddress string `json:"receipt_address"` + Amount decimal.Decimal `json:"amount"` + ContractAddress string `json:"contract_address"` + ClientSecret string `json:"client_secret"` } func (h *HttpHandle) RpcOrderRenew(p json.RawMessage, apiResp *api_code.ApiResp) { @@ -236,6 +232,14 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("HexToNormal err: %s", err.Error())) return } + premiumPercentage := decimal.Zero + premiumBase := decimal.Zero + if req.PayTokenId == tables.TokenIdStripeUSD { + premiumPercentage = config.Cfg.Stripe.PremiumPercentage + premiumBase = config.Cfg.Stripe.PremiumBase + amountTotalPayToken = amountTotalPayToken.Mul(premiumPercentage.Add(decimal.NewFromInt(1))).Add(premiumBase.Mul(decimal.NewFromInt(100))) + amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.IntPart()) + } res, err := unipay.CreateOrder(unipay.ReqOrderCreate{ ChainTypeAddress: core.ChainTypeAddress{ Type: "blockchain", @@ -244,10 +248,12 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen Key: addrNormal.AddressNormal, }, }, - BusinessId: unipay.BusinessIdDasRegisterSvr, - Amount: amountTotalPayToken, - PayTokenId: req.PayTokenId, - PaymentAddress: config.GetUnipayAddress(req.PayTokenId), + BusinessId: unipay.BusinessIdDasRegisterSvr, + Amount: amountTotalPayToken, + PayTokenId: req.PayTokenId, + PaymentAddress: config.GetUnipayAddress(req.PayTokenId), + PremiumPercentage: premiumPercentage, + PremiumBase: premiumBase, }) if err != nil { apiResp.ApiRespErr(api_code.ApiCodeError500, "Failed to create order by unipay") @@ -264,7 +270,7 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen Timestamp: time.Now().UnixNano() / 1e6, PayTokenId: req.PayTokenId, PayType: req.PayType, - PayAmount: res.Amount, + PayAmount: amountTotalPayToken, Content: string(contentDataStr), PayStatus: tables.TxStatusDefault, HedgeStatus: tables.TxStatusDefault, @@ -272,8 +278,8 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen RegisterStatus: tables.RegisterStatusDefault, OrderStatus: tables.OrderStatusDefault, IsUniPay: tables.IsUniPayTrue, - PremiumPercentage: res.PremiumPercentage, - PremiumBase: res.PremiumBase, + PremiumPercentage: premiumPercentage, + PremiumBase: premiumBase, } if req.PayTokenId == tables.TokenIdStripeUSD && res.StripePaymentIntentId != "" { paymentInfo = tables.TableDasOrderPayInfo{ @@ -288,8 +294,6 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen } resp.ContractAddress = res.ContractAddress resp.ClientSecret = res.ClientSecret - resp.PremiumPercentage = res.PremiumPercentage - resp.PremiumBase = res.PremiumBase } else { order = tables.TableDasOrderInfo{ OrderType: tables.OrderTypeSelf, @@ -315,9 +319,7 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen resp.OrderId = order.OrderId resp.TokenId = req.PayTokenId - //resp.PayType = req.PayType resp.Amount = order.PayAmount - //resp.CodeUrl = "" if addr, ok := config.Cfg.PayAddressMap[order.PayTokenId.ToChainString()]; !ok { apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("not supported [%s]", order.PayTokenId)) return diff --git a/unipay/unipay.go b/unipay/unipay.go index 869a69ea..0930282b 100644 --- a/unipay/unipay.go +++ b/unipay/unipay.go @@ -24,21 +24,20 @@ const ( type ReqOrderCreate struct { core.ChainTypeAddress - BusinessId string `json:"business_id"` - Amount decimal.Decimal `json:"amount"` - PayTokenId tables.PayTokenId `json:"pay_token_id"` - PaymentAddress string `json:"payment_address"` + BusinessId string `json:"business_id"` + Amount decimal.Decimal `json:"amount"` + PayTokenId tables.PayTokenId `json:"pay_token_id"` + PaymentAddress string `json:"payment_address"` + PremiumPercentage decimal.Decimal `json:"premium_percentage"` + PremiumBase decimal.Decimal `json:"premium_base"` } type RespOrderCreate struct { - OrderId string `json:"order_id"` - PaymentAddress string `json:"payment_address"` - ContractAddress string `json:"contract_address"` - StripePaymentIntentId string `json:"stripe_payment_intent_id"` - ClientSecret string `json:"client_secret"` - Amount decimal.Decimal `json:"amount"` - PremiumPercentage decimal.Decimal `json:"premium_percentage"` - PremiumBase decimal.Decimal `json:"premium_base"` + OrderId string `json:"order_id"` + PaymentAddress string `json:"payment_address"` + ContractAddress string `json:"contract_address"` + StripePaymentIntentId string `json:"stripe_payment_intent_id"` + ClientSecret string `json:"client_secret"` } func CreateOrder(req ReqOrderCreate) (resp RespOrderCreate, err error) { From 309eeff0033d68791c25c5dafe654fab5194163b Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Thu, 27 Jul 2023 15:25:41 +0800 Subject: [PATCH 03/14] feat: Support stripe --- http_server/handle/order_change.go | 4 ++++ http_server/handle/order_register.go | 4 ++++ http_server/handle/order_renew.go | 4 ++++ tables/t_das_order_info.go | 1 + unipay/unipay.go | 1 + 5 files changed, 14 insertions(+) diff --git a/http_server/handle/order_change.go b/http_server/handle/order_change.go index bfcb74e3..32a47f85 100644 --- a/http_server/handle/order_change.go +++ b/http_server/handle/order_change.go @@ -218,11 +218,13 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, } premiumPercentage := decimal.Zero premiumBase := decimal.Zero + premiumAmount := amountTotalPayToken if req.PayTokenId == tables.TokenIdStripeUSD { premiumPercentage = config.Cfg.Stripe.PremiumPercentage premiumBase = config.Cfg.Stripe.PremiumBase amountTotalPayToken = amountTotalPayToken.Mul(premiumPercentage.Add(decimal.NewFromInt(1))).Add(premiumBase.Mul(decimal.NewFromInt(100))) amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.IntPart()) + premiumAmount = amountTotalPayToken.Sub(premiumAmount) } res, err := unipay.CreateOrder(unipay.ReqOrderCreate{ ChainTypeAddress: core.ChainTypeAddress{ @@ -238,6 +240,7 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, PaymentAddress: config.GetUnipayAddress(req.PayTokenId), PremiumPercentage: premiumPercentage, PremiumBase: premiumBase, + PremiumAmount: premiumAmount, }) if err != nil { apiResp.ApiRespErr(api_code.ApiCodeError500, "Failed to create order by unipay") @@ -266,6 +269,7 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, IsUniPay: tables.IsUniPayTrue, PremiumPercentage: premiumPercentage, PremiumBase: premiumBase, + PremiumAmount: premiumAmount, } if req.PayTokenId == tables.TokenIdStripeUSD && res.StripePaymentIntentId != "" { paymentInfo = tables.TableDasOrderPayInfo{ diff --git a/http_server/handle/order_register.go b/http_server/handle/order_register.go index fb312b5d..57e004c1 100644 --- a/http_server/handle/order_register.go +++ b/http_server/handle/order_register.go @@ -436,11 +436,13 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap } premiumPercentage := decimal.Zero premiumBase := decimal.Zero + premiumAmount := amountTotalPayToken if req.PayTokenId == tables.TokenIdStripeUSD { premiumPercentage = config.Cfg.Stripe.PremiumPercentage premiumBase = config.Cfg.Stripe.PremiumBase amountTotalPayToken = amountTotalPayToken.Mul(premiumPercentage.Add(decimal.NewFromInt(1))).Add(premiumBase.Mul(decimal.NewFromInt(100))) amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.IntPart()) + premiumAmount = amountTotalPayToken.Sub(premiumAmount) } res, err := unipay.CreateOrder(unipay.ReqOrderCreate{ ChainTypeAddress: core.ChainTypeAddress{ @@ -456,6 +458,7 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap PaymentAddress: config.GetUnipayAddress(req.PayTokenId), PremiumPercentage: premiumPercentage, PremiumBase: premiumBase, + PremiumAmount: premiumAmount, }) if err != nil { apiResp.ApiRespErr(api_code.ApiCodeError500, "Failed to create order by unipay") @@ -484,6 +487,7 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap IsUniPay: tables.IsUniPayTrue, PremiumPercentage: premiumPercentage, PremiumBase: premiumBase, + PremiumAmount: premiumAmount, } if req.PayTokenId == tables.TokenIdStripeUSD && res.StripePaymentIntentId != "" { paymentInfo = tables.TableDasOrderPayInfo{ diff --git a/http_server/handle/order_renew.go b/http_server/handle/order_renew.go index bcea860f..d78526a8 100644 --- a/http_server/handle/order_renew.go +++ b/http_server/handle/order_renew.go @@ -234,11 +234,13 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen } premiumPercentage := decimal.Zero premiumBase := decimal.Zero + premiumAmount := amountTotalPayToken if req.PayTokenId == tables.TokenIdStripeUSD { premiumPercentage = config.Cfg.Stripe.PremiumPercentage premiumBase = config.Cfg.Stripe.PremiumBase amountTotalPayToken = amountTotalPayToken.Mul(premiumPercentage.Add(decimal.NewFromInt(1))).Add(premiumBase.Mul(decimal.NewFromInt(100))) amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.IntPart()) + premiumAmount = amountTotalPayToken.Sub(premiumAmount) } res, err := unipay.CreateOrder(unipay.ReqOrderCreate{ ChainTypeAddress: core.ChainTypeAddress{ @@ -254,6 +256,7 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen PaymentAddress: config.GetUnipayAddress(req.PayTokenId), PremiumPercentage: premiumPercentage, PremiumBase: premiumBase, + PremiumAmount: premiumAmount, }) if err != nil { apiResp.ApiRespErr(api_code.ApiCodeError500, "Failed to create order by unipay") @@ -280,6 +283,7 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen IsUniPay: tables.IsUniPayTrue, PremiumPercentage: premiumPercentage, PremiumBase: premiumBase, + PremiumAmount: premiumAmount, } if req.PayTokenId == tables.TokenIdStripeUSD && res.StripePaymentIntentId != "" { paymentInfo = tables.TableDasOrderPayInfo{ diff --git a/tables/t_das_order_info.go b/tables/t_das_order_info.go index d5857ace..124f379f 100644 --- a/tables/t_das_order_info.go +++ b/tables/t_das_order_info.go @@ -34,6 +34,7 @@ type TableDasOrderInfo struct { IsUniPay IsUniPay `json:"is_uni_pay" gorm:"column:is_uni_pay; type:smallint(6) NOT NULL DEFAULT '0' COMMENT '0-no 1-yes';"` PremiumPercentage decimal.Decimal `json:"premium_percentage" gorm:"column:premium_percentage; type:decimal(20,10) NOT NULL DEFAULT '0' COMMENT '';"` PremiumBase decimal.Decimal `json:"premium_base" gorm:"column:premium_base; type:decimal(20,10) NOT NULL DEFAULT '0' COMMENT '';"` + PremiumAmount decimal.Decimal `json:"premium_amount" gorm:"column:premium_amount; type:decimal(60,0) NOT NULL DEFAULT '0' COMMENT '';"` CreatedAt time.Time `json:"created_at" gorm:"column:created_at;type:timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT ''"` UpdatedAt time.Time `json:"updated_at" gorm:"column:updated_at;type:timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT ''"` } diff --git a/unipay/unipay.go b/unipay/unipay.go index 0930282b..ecd61965 100644 --- a/unipay/unipay.go +++ b/unipay/unipay.go @@ -30,6 +30,7 @@ type ReqOrderCreate struct { PaymentAddress string `json:"payment_address"` PremiumPercentage decimal.Decimal `json:"premium_percentage"` PremiumBase decimal.Decimal `json:"premium_base"` + PremiumAmount decimal.Decimal `json:"premium_amount"` } type RespOrderCreate struct { From 0d43d95d6a67b986c15a56068fd5a98f85d4d558 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Thu, 27 Jul 2023 16:39:45 +0800 Subject: [PATCH 04/14] feat: Support stripe --- http_server/handle/order_change.go | 3 ++- http_server/handle/order_register.go | 3 ++- http_server/handle/order_renew.go | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/http_server/handle/order_change.go b/http_server/handle/order_change.go index 32a47f85..57b0aff9 100644 --- a/http_server/handle/order_change.go +++ b/http_server/handle/order_change.go @@ -218,10 +218,11 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, } premiumPercentage := decimal.Zero premiumBase := decimal.Zero - premiumAmount := amountTotalPayToken + premiumAmount := decimal.Zero if req.PayTokenId == tables.TokenIdStripeUSD { premiumPercentage = config.Cfg.Stripe.PremiumPercentage premiumBase = config.Cfg.Stripe.PremiumBase + premiumAmount = amountTotalPayToken amountTotalPayToken = amountTotalPayToken.Mul(premiumPercentage.Add(decimal.NewFromInt(1))).Add(premiumBase.Mul(decimal.NewFromInt(100))) amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.IntPart()) premiumAmount = amountTotalPayToken.Sub(premiumAmount) diff --git a/http_server/handle/order_register.go b/http_server/handle/order_register.go index 57e004c1..1cdceec5 100644 --- a/http_server/handle/order_register.go +++ b/http_server/handle/order_register.go @@ -436,10 +436,11 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap } premiumPercentage := decimal.Zero premiumBase := decimal.Zero - premiumAmount := amountTotalPayToken + premiumAmount := decimal.Zero if req.PayTokenId == tables.TokenIdStripeUSD { premiumPercentage = config.Cfg.Stripe.PremiumPercentage premiumBase = config.Cfg.Stripe.PremiumBase + premiumAmount = amountTotalPayToken amountTotalPayToken = amountTotalPayToken.Mul(premiumPercentage.Add(decimal.NewFromInt(1))).Add(premiumBase.Mul(decimal.NewFromInt(100))) amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.IntPart()) premiumAmount = amountTotalPayToken.Sub(premiumAmount) diff --git a/http_server/handle/order_renew.go b/http_server/handle/order_renew.go index d78526a8..dabba51f 100644 --- a/http_server/handle/order_renew.go +++ b/http_server/handle/order_renew.go @@ -234,10 +234,11 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen } premiumPercentage := decimal.Zero premiumBase := decimal.Zero - premiumAmount := amountTotalPayToken + premiumAmount := decimal.Zero if req.PayTokenId == tables.TokenIdStripeUSD { premiumPercentage = config.Cfg.Stripe.PremiumPercentage premiumBase = config.Cfg.Stripe.PremiumBase + premiumAmount = amountTotalPayToken amountTotalPayToken = amountTotalPayToken.Mul(premiumPercentage.Add(decimal.NewFromInt(1))).Add(premiumBase.Mul(decimal.NewFromInt(100))) amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.IntPart()) premiumAmount = amountTotalPayToken.Sub(premiumAmount) From a4d3572efa5fe60b1aefdd3c8a66f2b7b57f6321 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Thu, 27 Jul 2023 18:08:54 +0800 Subject: [PATCH 05/14] feat: Support stripe --- dao/t_das_order_pay_info.go | 14 ++++++++++++++ http_server/handle/unipay_notice.go | 10 ++++++++-- tables/t_das_order_pay_info.go | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/dao/t_das_order_pay_info.go b/dao/t_das_order_pay_info.go index dca8560c..5aad0fa5 100644 --- a/dao/t_das_order_pay_info.go +++ b/dao/t_das_order_pay_info.go @@ -40,6 +40,20 @@ func (d *DbDao) UpdateUniPayRefundStatusToRefunded(payHash, orderId, refundHash }).Error } +func (d *DbDao) UpdatePayHashStatusToFailByDispute(payHash, orderId string) error { + return d.db.Transaction(func(tx *gorm.DB) error { + if err := tx.Model(tables.TableDasOrderPayInfo{}). + Where("`hash`=? AND order_id=? AND `status`=?", + payHash, orderId, tables.OrderTxStatusConfirm). + Updates(map[string]interface{}{ + "status": tables.OrderTxStatusDispute, + }).Error; err != nil { + return err + } + return nil + }) +} + func (d *DbDao) UpdatePayment(paymentInfo tables.TableDasOrderPayInfo) error { return d.db.Transaction(func(tx *gorm.DB) error { if err := tx.Model(tables.TableDasOrderInfo{}). diff --git a/http_server/handle/unipay_notice.go b/http_server/handle/unipay_notice.go index 255211df..325bdca0 100644 --- a/http_server/handle/unipay_notice.go +++ b/http_server/handle/unipay_notice.go @@ -16,8 +16,9 @@ import ( type EventType string const ( - EventTypeOrderPay EventType = "ORDER.PAY" - EventTypeOrderRefund EventType = "ORDER.REFUND" + EventTypeOrderPay EventType = "ORDER.PAY" + EventTypeOrderRefund EventType = "ORDER.REFUND" + EventTypePaymentDispute EventType = "PAYMENT.DISPUTE" ) type EventInfo struct { @@ -84,6 +85,11 @@ func (h *HttpHandle) doUniPayNotice(req *ReqUniPayNotice, apiResp *api_code.ApiR log.Error("UpdateUniPayRefundStatusToRefunded err: ", err.Error()) notify.SendLarkTextNotify(config.Cfg.Notify.LarkErrorKey, "UpdateUniPayRefundStatusToRefunded", err.Error()) } + case EventTypePaymentDispute: + if err := h.dbDao.UpdatePayHashStatusToFailByDispute(v.PayHash, v.OrderId); err != nil { + log.Error("UpdatePayHashStatusToFailByDispute err: ", err.Error()) + notify.SendLarkTextNotify(config.Cfg.Notify.LarkErrorKey, "UpdatePayHashStatusToFailByDispute", err.Error()) + } default: log.Error("EventType invalid:", v.EventType) } diff --git a/tables/t_das_order_pay_info.go b/tables/t_das_order_pay_info.go index 7a59f2fd..d41ba85d 100644 --- a/tables/t_das_order_pay_info.go +++ b/tables/t_das_order_pay_info.go @@ -47,6 +47,7 @@ const ( OrderTxStatusDefault OrderTxStatus = 0 OrderTxStatusConfirm OrderTxStatus = 1 OrderTxStatusRejected OrderTxStatus = 2 + OrderTxStatusDispute OrderTxStatus = 3 ) // unipay From 2372a1f3d9f73e5d58d6f88ed7d0d1ca20772a55 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Fri, 28 Jul 2023 18:00:35 +0800 Subject: [PATCH 06/14] feat: Support stripe --- http_server/handle/order_change.go | 1 + http_server/handle/order_register.go | 1 + http_server/handle/order_renew.go | 1 + unipay/unipay.go | 16 ++++++++++++++++ 4 files changed, 19 insertions(+) diff --git a/http_server/handle/order_change.go b/http_server/handle/order_change.go index 57b0aff9..d9bc2667 100644 --- a/http_server/handle/order_change.go +++ b/http_server/handle/order_change.go @@ -180,6 +180,7 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, apiResp.ApiRespErr(api_code.ApiCodeError500, "get order amount fail") return } + amountTotalPayToken = unipay.RoundAmount(amountTotalPayToken, req.PayTokenId) // inviterAccountId := common.Bytes2Hex(common.GetAccountIdByAccount(req.InviterAccount)) if _, ok := config.Cfg.InviterWhitelist[inviterAccountId]; ok { diff --git a/http_server/handle/order_register.go b/http_server/handle/order_register.go index 1cdceec5..89fcc59b 100644 --- a/http_server/handle/order_register.go +++ b/http_server/handle/order_register.go @@ -373,6 +373,7 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap apiResp.ApiRespErr(api_code.ApiCodeError500, "get order amount fail") return } + amountTotalPayToken = unipay.RoundAmount(amountTotalPayToken, req.PayTokenId) inviterAccountId := common.Bytes2Hex(common.GetAccountIdByAccount(req.InviterAccount)) if _, ok := config.Cfg.InviterWhitelist[inviterAccountId]; ok { diff --git a/http_server/handle/order_renew.go b/http_server/handle/order_renew.go index dabba51f..e1b64bfc 100644 --- a/http_server/handle/order_renew.go +++ b/http_server/handle/order_renew.go @@ -182,6 +182,7 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen apiResp.ApiRespErr(api_code.ApiCodeError500, "get order amount fail") return } + amountTotalPayToken = unipay.RoundAmount(amountTotalPayToken, req.PayTokenId) // accountId := common.Bytes2Hex(common.GetAccountIdByAccount(req.Account)) orderContent := tables.TableOrderContent{ diff --git a/unipay/unipay.go b/unipay/unipay.go index ecd61965..151afa34 100644 --- a/unipay/unipay.go +++ b/unipay/unipay.go @@ -116,3 +116,19 @@ type ToolUniPay struct { Wg *sync.WaitGroup DbDao *dao.DbDao } + +func RoundAmount(amount decimal.Decimal, tokenId tables.PayTokenId) decimal.Decimal { + switch tokenId { + case tables.TokenIdEth, tables.TokenIdBnb, tables.TokenIdMatic: + dec := decimal.New(1, 8) + amount = amount.Div(dec).Ceil().Mul(dec) + case tables.TokenIdDas, tables.TokenIdCkb, tables.TokenIdCkbInternal, tables.TokenIdDoge: + dec := decimal.New(1, 4) + amount = amount.Div(dec).Ceil().Mul(dec) + case tables.TokenIdTrx, tables.TokenIdErc20USDT, + tables.TokenIdBep20USDT, tables.TokenIdTrc20USDT: + dec := decimal.New(1, 3) + amount = amount.Div(dec).Ceil().Mul(dec) + } + return amount +} From 86c78b66807db59e7fcde3c2c16634dabfae3155 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Fri, 28 Jul 2023 19:02:06 +0800 Subject: [PATCH 07/14] feat: Support stripe --- http_server/handle/order_change.go | 2 +- http_server/handle/order_register.go | 2 +- http_server/handle/order_renew.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/http_server/handle/order_change.go b/http_server/handle/order_change.go index d9bc2667..d0027772 100644 --- a/http_server/handle/order_change.go +++ b/http_server/handle/order_change.go @@ -225,7 +225,7 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, premiumBase = config.Cfg.Stripe.PremiumBase premiumAmount = amountTotalPayToken amountTotalPayToken = amountTotalPayToken.Mul(premiumPercentage.Add(decimal.NewFromInt(1))).Add(premiumBase.Mul(decimal.NewFromInt(100))) - amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.IntPart()) + amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.Ceil().IntPart()) premiumAmount = amountTotalPayToken.Sub(premiumAmount) } res, err := unipay.CreateOrder(unipay.ReqOrderCreate{ diff --git a/http_server/handle/order_register.go b/http_server/handle/order_register.go index 89fcc59b..63f982ee 100644 --- a/http_server/handle/order_register.go +++ b/http_server/handle/order_register.go @@ -443,7 +443,7 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap premiumBase = config.Cfg.Stripe.PremiumBase premiumAmount = amountTotalPayToken amountTotalPayToken = amountTotalPayToken.Mul(premiumPercentage.Add(decimal.NewFromInt(1))).Add(premiumBase.Mul(decimal.NewFromInt(100))) - amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.IntPart()) + amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.Ceil().IntPart()) premiumAmount = amountTotalPayToken.Sub(premiumAmount) } res, err := unipay.CreateOrder(unipay.ReqOrderCreate{ diff --git a/http_server/handle/order_renew.go b/http_server/handle/order_renew.go index e1b64bfc..27cf0cf7 100644 --- a/http_server/handle/order_renew.go +++ b/http_server/handle/order_renew.go @@ -241,7 +241,7 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen premiumBase = config.Cfg.Stripe.PremiumBase premiumAmount = amountTotalPayToken amountTotalPayToken = amountTotalPayToken.Mul(premiumPercentage.Add(decimal.NewFromInt(1))).Add(premiumBase.Mul(decimal.NewFromInt(100))) - amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.IntPart()) + amountTotalPayToken = decimal.NewFromInt(amountTotalPayToken.Ceil().IntPart()) premiumAmount = amountTotalPayToken.Sub(premiumAmount) } res, err := unipay.CreateOrder(unipay.ReqOrderCreate{ From 4a445662dc7b7a91d31034b02ab3eba4f7106079 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Mon, 31 Jul 2023 14:18:32 +0800 Subject: [PATCH 08/14] feat: Support stripe --- dao/t_token_price_info.go | 2 +- example/stripe_test.go | 49 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 example/stripe_test.go diff --git a/dao/t_token_price_info.go b/dao/t_token_price_info.go index 96fc9acc..70f72f49 100644 --- a/dao/t_token_price_info.go +++ b/dao/t_token_price_info.go @@ -3,6 +3,6 @@ package dao import "das_register_server/tables" func (d *DbDao) GetTokenPriceList() (list []tables.TableTokenPriceInfo, err error) { - err = d.parserDb.Where("token_id NOT IN('bsc_bep20_usdt','eth_erc20_usdt','tron_trc20_usdt','stripe_usd')").Order("id DESC").Find(&list).Error + err = d.parserDb.Where("token_id NOT IN('bsc_bep20_usdt','eth_erc20_usdt','tron_trc20_usdt')").Order("id DESC").Find(&list).Error return } diff --git a/example/stripe_test.go b/example/stripe_test.go new file mode 100644 index 00000000..1f6c25a2 --- /dev/null +++ b/example/stripe_test.go @@ -0,0 +1,49 @@ +package example + +import ( + "das_register_server/http_server/handle" + "das_register_server/tables" + "fmt" + "github.com/dotbitHQ/das-lib/common" + "testing" +) + +func TestRegByStripe(t *testing.T) { + req := handle.ReqOrderRegister{ + ReqAccountSearch: handle.ReqAccountSearch{ + ChainType: common.ChainTypeEth, + Address: "0x15a33588908cF8Edb27D1AbE3852Bf287Abd3891", + Account: "20230731.bit", + AccountCharStr: []common.AccountCharSet{ + {CharSetName: common.AccountCharTypeDigit, Char: "2"}, + {CharSetName: common.AccountCharTypeDigit, Char: "0"}, + {CharSetName: common.AccountCharTypeDigit, Char: "2"}, + {CharSetName: common.AccountCharTypeDigit, Char: "3"}, + {CharSetName: common.AccountCharTypeDigit, Char: "0"}, + {CharSetName: common.AccountCharTypeDigit, Char: "7"}, + {CharSetName: common.AccountCharTypeDigit, Char: "3"}, + {CharSetName: common.AccountCharTypeDigit, Char: "1"}, + {CharSetName: common.AccountCharTypeEn, Char: "."}, + {CharSetName: common.AccountCharTypeEn, Char: "b"}, + {CharSetName: common.AccountCharTypeEn, Char: "i"}, + {CharSetName: common.AccountCharTypeEn, Char: "t"}, + }, + }, + ReqOrderRegisterBase: handle.ReqOrderRegisterBase{ + RegisterYears: 1, + InviterAccount: "", + ChannelAccount: "", + }, + PayChainType: 0, + PayAddress: "", + PayTokenId: tables.TokenIdStripeUSD, + PayType: "", + } + + url := TestUrl + "/account/order/register" + var data handle.RespOrderRegister + if err := doReq(url, req, &data); err != nil { + t.Fatal(err) + } + fmt.Println(data) +} From dc9fb9a7a2e8ec71ed67a12a5004b87dc86f79c3 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Mon, 31 Jul 2023 14:44:40 +0800 Subject: [PATCH 09/14] feat: Support stripe --- config/config.go | 9 ++++++--- http_server/handle/balance_pay.go | 3 ++- http_server/handle/order_change.go | 4 ++-- http_server/handle/order_detail.go | 3 ++- http_server/handle/order_register.go | 19 +++++++++++-------- http_server/handle/order_renew.go | 4 ++-- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/config/config.go b/config/config.go index b1bda73c..2e4e75e1 100644 --- a/config/config.go +++ b/config/config.go @@ -129,18 +129,21 @@ type DbMysql struct { func GetUnipayAddress(tokenId tables.PayTokenId) string { switch tokenId { - case tables.TokenIdEth: + case tables.TokenIdEth, tables.TokenIdErc20USDT: return Cfg.PayAddressMap["eth"] - case tables.TokenIdBnb: + case tables.TokenIdBnb, tables.TokenIdBep20USDT: return Cfg.PayAddressMap["bsc"] case tables.TokenIdMatic: return Cfg.PayAddressMap["polygon"] - case tables.TokenIdTrx: + case tables.TokenIdTrx, tables.TokenIdTrc20USDT: return Cfg.PayAddressMap["tron"] case tables.TokenIdCkb, tables.TokenIdDas: return Cfg.PayAddressMap["ckb"] case tables.TokenIdDoge: return Cfg.PayAddressMap["doge"] + case tables.TokenIdStripeUSD: + return "stripe" } + log.Error("GetUnipayAddress not supported:", tokenId) return "" } diff --git a/http_server/handle/balance_pay.go b/http_server/handle/balance_pay.go index a1fa1efe..a51252c8 100644 --- a/http_server/handle/balance_pay.go +++ b/http_server/handle/balance_pay.go @@ -129,7 +129,8 @@ func (h *HttpHandle) doBalancePay(req *ReqBalancePay, apiResp *api_code.ApiResp) // check pay address beneficiaryAddress := "" - if addr, ok := config.Cfg.PayAddressMap[order.PayTokenId.ToChainString()]; !ok { + addr := config.GetUnipayAddress(order.PayTokenId) + if addr == "" { apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("not supported [%s]", order.PayTokenId)) return nil } else { diff --git a/http_server/handle/order_change.go b/http_server/handle/order_change.go index d0027772..48a48630 100644 --- a/http_server/handle/order_change.go +++ b/http_server/handle/order_change.go @@ -180,7 +180,6 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, apiResp.ApiRespErr(api_code.ApiCodeError500, "get order amount fail") return } - amountTotalPayToken = unipay.RoundAmount(amountTotalPayToken, req.PayTokenId) // inviterAccountId := common.Bytes2Hex(common.GetAccountIdByAccount(req.InviterAccount)) if _, ok := config.Cfg.InviterWhitelist[inviterAccountId]; ok { @@ -315,7 +314,8 @@ func (h *HttpHandle) doNewOrder(req *ReqOrderChange, apiResp *api_code.ApiResp, resp.OrderId = order.OrderId resp.TokenId = req.PayTokenId resp.Amount = order.PayAmount - if addr, ok := config.Cfg.PayAddressMap[order.PayTokenId.ToChainString()]; !ok { + addr := config.GetUnipayAddress(order.PayTokenId) + if addr == "" { apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("not supported [%s]", order.PayTokenId)) return } else { diff --git a/http_server/handle/order_detail.go b/http_server/handle/order_detail.go index 3720c557..be5392ba 100644 --- a/http_server/handle/order_detail.go +++ b/http_server/handle/order_detail.go @@ -129,7 +129,8 @@ func (h *HttpHandle) doOrderDetail(req *ReqOrderDetail, apiResp *api_code.ApiRes resp.RegisterYears = contentData.RegisterYears resp.ChannelAccount = contentData.ChannelAccount } - if addr, ok := config.Cfg.PayAddressMap[order.PayTokenId.ToChainString()]; !ok { + addr := config.GetUnipayAddress(order.PayTokenId) + if addr == "" { apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("not supported [%s]", order.PayTokenId)) return nil } else { diff --git a/http_server/handle/order_register.go b/http_server/handle/order_register.go index 63f982ee..2059345a 100644 --- a/http_server/handle/order_register.go +++ b/http_server/handle/order_register.go @@ -373,7 +373,6 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap apiResp.ApiRespErr(api_code.ApiCodeError500, "get order amount fail") return } - amountTotalPayToken = unipay.RoundAmount(amountTotalPayToken, req.PayTokenId) inviterAccountId := common.Bytes2Hex(common.GetAccountIdByAccount(req.InviterAccount)) if _, ok := config.Cfg.InviterWhitelist[inviterAccountId]; ok { @@ -533,7 +532,8 @@ func (h *HttpHandle) doRegisterOrder(req *ReqOrderRegister, apiResp *api_code.Ap resp.TokenId = req.PayTokenId resp.Amount = order.PayAmount - if addr, ok := config.Cfg.PayAddressMap[order.PayTokenId.ToChainString()]; !ok { + addr := config.GetUnipayAddress(order.PayTokenId) + if addr == "" { apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("not supported [%s]", order.PayTokenId)) return } else { @@ -755,14 +755,17 @@ func (h *HttpHandle) getOrderAmount(accLen uint8, args, account, inviterAccount log.Info("getOrderAmount:", amountTotalUSD, amountTotalCKB, amountTotalPayToken) if payToken.TokenId == tables.TokenIdCkb { amountTotalPayToken = amountTotalCKB - } else if payToken.TokenId == tables.TokenIdMatic || payToken.TokenId == tables.TokenIdBnb || payToken.TokenId == tables.TokenIdEth { - log.Info("amountTotalPayToken:", amountTotalPayToken.String()) - decCeil := decimal.NewFromInt(1e6) - amountTotalPayToken = amountTotalPayToken.DivRound(decCeil, 6).Ceil().Mul(decCeil) - log.Info("amountTotalPayToken:", amountTotalPayToken.String()) - } else if payToken.TokenId == tables.TokenIdDoge && h.dasCore.NetType() != common.DasNetTypeMainNet { + } + //if payToken.TokenId == tables.TokenIdMatic || payToken.TokenId == tables.TokenIdBnb || payToken.TokenId == tables.TokenIdEth { + // log.Info("amountTotalPayToken:", amountTotalPayToken.String()) + // decCeil := decimal.NewFromInt(1e6) + // amountTotalPayToken = amountTotalPayToken.DivRound(decCeil, 6).Ceil().Mul(decCeil) + // log.Info("amountTotalPayToken:", amountTotalPayToken.String()) + //} + if payToken.TokenId == tables.TokenIdDoge && h.dasCore.NetType() != common.DasNetTypeMainNet { amountTotalPayToken = decimal.NewFromInt(rand.Int63n(10000000) + 100000000) } + amountTotalPayToken = unipay.RoundAmount(amountTotalPayToken, payToken.TokenId) return } func (h *HttpHandle) getCouponInfo(code string) (err error, info *RespCouponInfo) { diff --git a/http_server/handle/order_renew.go b/http_server/handle/order_renew.go index 27cf0cf7..aed9b99a 100644 --- a/http_server/handle/order_renew.go +++ b/http_server/handle/order_renew.go @@ -182,7 +182,6 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen apiResp.ApiRespErr(api_code.ApiCodeError500, "get order amount fail") return } - amountTotalPayToken = unipay.RoundAmount(amountTotalPayToken, req.PayTokenId) // accountId := common.Bytes2Hex(common.GetAccountIdByAccount(req.Account)) orderContent := tables.TableOrderContent{ @@ -326,7 +325,8 @@ func (h *HttpHandle) doRenewOrder(acc *tables.TableAccountInfo, req *ReqOrderRen resp.OrderId = order.OrderId resp.TokenId = req.PayTokenId resp.Amount = order.PayAmount - if addr, ok := config.Cfg.PayAddressMap[order.PayTokenId.ToChainString()]; !ok { + addr := config.GetUnipayAddress(order.PayTokenId) + if addr == "" { apiResp.ApiRespErr(api_code.ApiCodeError500, fmt.Sprintf("not supported [%s]", order.PayTokenId)) return } else { From 96128c686838741b0b1570b3d9e275bc47c1da4d Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Thu, 3 Aug 2023 16:01:50 +0800 Subject: [PATCH 10/14] feat: Support stripe --- API.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/API.md b/API.md index 561b0b92..d2638412 100644 --- a/API.md +++ b/API.md @@ -771,8 +771,10 @@ curl -X POST http://127.0.0.1:8120/v1/withdraw/list -d'{"chain_type":1,"address" "3": {}, // pre tx hash "4": {},// propose tx hash "5": {}// confirm propose tx hash - } - + }, + "open_timestamp": 0, // + "premium_percentage": "",// for usd premium + "premium_base": "" // for usd premium } } ``` From 6fadb8f54c5fed939ef2a4530d924adff6973c79 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Mon, 7 Aug 2023 14:44:27 +0800 Subject: [PATCH 11/14] feat: Support stripe --- API.md | 12 +++++++----- http_server/handle/account_detail.go | 5 +++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/API.md b/API.md index d2638412..a2c03946 100644 --- a/API.md +++ b/API.md @@ -319,7 +319,9 @@ curl -X POST http://127.0.0.1:8120/v1/account/mine -d'{"chain_type":1,"address": "status": 6, "account_price": "10", "base_amount": "3.89", - "confirm_proposal_hash": "0xec7bec47a4d3ad467253925a7e097f311e0738d625d55f8b3420cabaaa9b5201" + "confirm_proposal_hash": "0xec7bec47a4d3ad467253925a7e097f311e0738d625d55f8b3420cabaaa9b5201", + "premium_percentage": "",// for stripe usd premium + "premium_base": "" // for stripe usd premium } } ``` @@ -773,8 +775,8 @@ curl -X POST http://127.0.0.1:8120/v1/withdraw/list -d'{"chain_type":1,"address" "5": {}// confirm propose tx hash }, "open_timestamp": 0, // - "premium_percentage": "",// for usd premium - "premium_base": "" // for usd premium + "premium_percentage": "",// for stripe usd premium + "premium_base": "" // for stripe usd premium } } ``` @@ -1561,8 +1563,8 @@ curl -X POST http://127.0.0.1:8120/v1/balance/pay -d'{"evm_chain_id":97,"chain_t "token_id": "ckb_das", "receipt_address": "ckt1qyqvsej8jggu4hmr45g4h8d9pfkpd0fayfksz44t9q", "amount": "50502165739", - "code_url": "", - "pay_type": "" + "contract_address": "",// for usdt + "client_secret": ""// for stripe usd } } ``` diff --git a/http_server/handle/account_detail.go b/http_server/handle/account_detail.go index c3b9bc14..35f89668 100644 --- a/http_server/handle/account_detail.go +++ b/http_server/handle/account_detail.go @@ -2,6 +2,7 @@ package handle import ( "bytes" + "das_register_server/config" "das_register_server/http_server/api_code" "das_register_server/tables" "encoding/binary" @@ -39,6 +40,8 @@ type RespAccountDetail struct { RenewSubAccountPrice uint64 `json:"renew_sub_account_price"` Nonce uint64 `json:"nonce"` CustomScript string `json:"custom_script"` + PremiumPercentage decimal.Decimal `json:"premium_percentage"` + PremiumBase decimal.Decimal `json:"premium_base"` } func (h *HttpHandle) RpcAccountDetail(p json.RawMessage, apiResp *api_code.ApiResp) { @@ -145,6 +148,8 @@ func (h *HttpHandle) doAccountDetail(req *ReqAccountDetail, apiResp *api_code.Ap var resp RespAccountDetail resp.Account = req.Account resp.Status = tables.SearchStatusRegisterAble + resp.PremiumPercentage = config.Cfg.Stripe.PremiumPercentage + resp.PremiumBase = config.Cfg.Stripe.PremiumBase // acc accountId := common.Bytes2Hex(common.GetAccountIdByAccount(req.Account)) From 01a94b60129f12fe19f96008540030757f51d31a Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Mon, 7 Aug 2023 14:45:51 +0800 Subject: [PATCH 12/14] feat: Support stripe --- API.md | 4 +++- http_server/handle/config_info.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/API.md b/API.md index a2c03946..fc7a5207 100644 --- a/API.md +++ b/API.md @@ -165,7 +165,9 @@ curl -X POST http://127.0.0.1:8120/v1/token/list "transfer_throttle": 300, "income_cell_min_transfer_value": 11600000000, "premium": "0.1", - "timestamp_on_chain": 1647589995 + "timestamp_on_chain": 1647589995, + "premium_percentage": "",// for stripe usd premium + "premium_base": "" // for stripe usd premium } } ``` diff --git a/http_server/handle/config_info.go b/http_server/handle/config_info.go index a5f8a30d..18aab0da 100644 --- a/http_server/handle/config_info.go +++ b/http_server/handle/config_info.go @@ -29,6 +29,8 @@ type RespConfigInfo struct { IncomeCellMinTransferValue uint64 `json:"income_cell_min_transfer_value"` Premium decimal.Decimal `json:"premium" yaml:"premium"` TimestampOnChain int64 `json:"timestamp_on_chain"` + PremiumPercentage decimal.Decimal `json:"premium_percentage"` + PremiumBase decimal.Decimal `json:"premium_base"` } func (h *HttpHandle) RpcConfigInfo(p json.RawMessage, apiResp *api_code.ApiResp) { @@ -56,6 +58,8 @@ func (h *HttpHandle) ConfigInfo(ctx *gin.Context) { func (h *HttpHandle) doConfigInfo(apiResp *api_code.ApiResp) error { var resp RespConfigInfo + resp.PremiumPercentage = config.Cfg.Stripe.PremiumPercentage + resp.PremiumBase = config.Cfg.Stripe.PremiumBase if err := h.checkSystemUpgrade(apiResp); err != nil { return fmt.Errorf("checkSystemUpgrade err: %s", err.Error()) From e362cdf95c0fb75134c5daa7f76e56bf556e9826 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Mon, 7 Aug 2023 15:34:50 +0800 Subject: [PATCH 13/14] feat: Support stripe --- API.md | 4 +++- http_server/handle/order_detail.go | 28 +++++++++++++++++++++++----- unipay/unipay.go | 1 + 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/API.md b/API.md index fc7a5207..290c9464 100644 --- a/API.md +++ b/API.md @@ -860,7 +860,9 @@ curl -X POST http://127.0.0.1:8120/v1/account/registering/list -d'{"chain_type": "channel_account": "", // channel account of order "register_years": 1, // number of years of account registration "coin_type": "", // used to init account records - "cross_coin_type": "" // used to cross chain + "cross_coin_type": "", // used to cross chain + "contract_address": "",// for usdt + "client_secret": ""// for stripe usd } } ``` diff --git a/http_server/handle/order_detail.go b/http_server/handle/order_detail.go index be5392ba..e11a0932 100644 --- a/http_server/handle/order_detail.go +++ b/http_server/handle/order_detail.go @@ -4,6 +4,7 @@ import ( "das_register_server/config" "das_register_server/http_server/api_code" "das_register_server/tables" + "das_register_server/unipay" "encoding/json" "fmt" "github.com/dotbitHQ/das-lib/common" @@ -34,9 +35,11 @@ type RespOrderDetail struct { InviterAccount string `json:"inviter_account"` ChannelAccount string `json:"channel_account"` RegisterYears int `json:"register_years"` - CodeUrl string `json:"code_url"` // wx pay code - CoinType string `json:"coin_type"` - CrossCoinType string `json:"cross_coin_type"` + //CodeUrl string `json:"code_url"` // wx pay code + //CoinType string `json:"coin_type"` + CrossCoinType string `json:"cross_coin_type"` + ContractAddress string `json:"contract_address"` + ClientSecret string `json:"client_secret"` } func (h *HttpHandle) RpcOrderDetail(p json.RawMessage, apiResp *api_code.ApiResp) { @@ -116,9 +119,24 @@ func (h *HttpHandle) doOrderDetail(req *ReqOrderDetail, apiResp *api_code.ApiRes resp.PayAmount = order.PayAmount resp.Timestamp = order.Timestamp resp.Status = order.PayStatus - resp.CoinType = order.CoinType + //resp.CoinType = order.CoinType resp.CrossCoinType = order.CrossCoinType + switch order.PayTokenId { + case tables.TokenIdStripeUSD, tables.TokenIdTrc20USDT, + tables.TokenIdBep20USDT, tables.TokenIdErc20USDT: + unipayRes, err := unipay.GetOrderInfo(unipay.ReqOrderInfo{ + BusinessId: unipay.BusinessIdDasRegisterSvr, + OrderId: order.OrderId, + }) + if err != nil { + apiResp.ApiRespErr(api_code.ApiCodeError500, "Failed to call unipay.GetOrderInfo") + return fmt.Errorf("unipay.GetOrderInfo err: %s[%s]", err.Error(), order.OrderId) + } + resp.ContractAddress = unipayRes.ContractAddress + resp.ClientSecret = unipayRes.ClientSecret + } + if req.Action == common.DasActionApplyRegister { var contentData tables.TableOrderContent if err := json.Unmarshal([]byte(order.Content), &contentData); err != nil { @@ -136,7 +154,7 @@ func (h *HttpHandle) doOrderDetail(req *ReqOrderDetail, apiResp *api_code.ApiRes } else { resp.ReceiptAddress = addr } - resp.CodeUrl = "" + //resp.CodeUrl = "" apiResp.ApiRespOK(resp) return nil diff --git a/unipay/unipay.go b/unipay/unipay.go index 151afa34..7583e17f 100644 --- a/unipay/unipay.go +++ b/unipay/unipay.go @@ -101,6 +101,7 @@ type RespOrderInfo struct { OrderId string `json:"order_id"` PaymentAddress string `json:"payment_address"` ContractAddress string `json:"contract_address"` + ClientSecret string `json:"client_secret"` } func GetOrderInfo(req ReqOrderInfo) (resp RespOrderInfo, err error) { From 42f2ddd1d112eabd4a07ea7fec3ba9022f116c77 Mon Sep 17 00:00:00 2001 From: scorpiotzh <835598264@qq.com> Date: Tue, 8 Aug 2023 10:55:30 +0800 Subject: [PATCH 14/14] feat: Support stripe --- notify/notify_order.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/notify/notify_order.go b/notify/notify_order.go index a883db46..6fdb11ba 100644 --- a/notify/notify_order.go +++ b/notify/notify_order.go @@ -39,6 +39,8 @@ func SendLarkOrderNotify(p *SendLarkOrderNotifyParam) { amount = amount.DivRound(decimal.New(1, 2), 2) case tables.TokenIdDoge: amount = amount.DivRound(decimal.New(1, 8), 8) + case tables.TokenIdStripeUSD: + amount = amount.DivRound(decimal.New(1, 2), 2) } msg = fmt.Sprintf(msg, p.Account, p.OrderId, address, p.PayTokenId, amount.String(), time.Now().Format("2006-01-02 15:04:05")) SendLarkTextNotify(p.Key, p.Action, msg)