Skip to content

Commit

Permalink
Merge branch 'stripe'
Browse files Browse the repository at this point in the history
# Conflicts:
#	http_server/handle/account_detail.go
  • Loading branch information
scorpiotzh committed Aug 16, 2023
2 parents 7a60c31 + 42f2ddd commit 4f143d9
Show file tree
Hide file tree
Showing 21 changed files with 345 additions and 112 deletions.
22 changes: 15 additions & 7 deletions API.md
Expand Up @@ -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
}
}
```
Expand Down Expand Up @@ -319,7 +321,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
}
}
```
Expand Down Expand Up @@ -771,8 +775,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 stripe usd premium
"premium_base": "" // for stripe usd premium
}
}
```
Expand Down Expand Up @@ -854,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
}
}
```
Expand Down Expand Up @@ -1559,8 +1567,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
}
}
```
Expand Down
13 changes: 10 additions & 3 deletions config/config.go
Expand Up @@ -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 {
Expand All @@ -125,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 ""
}
14 changes: 14 additions & 0 deletions dao/t_das_order_info.go
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions dao/t_das_order_pay_info.go
Expand Up @@ -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{}).
Expand Down
2 changes: 1 addition & 1 deletion dao/t_token_price_info.go
Expand Up @@ -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
}
49 changes: 49 additions & 0 deletions 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)
}
5 changes: 2 additions & 3 deletions go.mod
Expand Up @@ -3,7 +3,7 @@ module das_register_server
go 1.17

require (
github.com/dotbitHQ/das-lib v1.0.2-0.20230816015355-2dea1da4af7b
github.com/dotbitHQ/das-lib v1.0.2-0.20230816015623-b291d5c47f78
github.com/ethereum/go-ethereum v1.10.26
github.com/fsnotify/fsnotify v1.5.4
github.com/gin-gonic/gin v1.7.7
Expand All @@ -13,7 +13,7 @@ require (
github.com/parnurzeal/gorequest v0.2.16
github.com/robfig/cron/v3 v3.0.1
github.com/scorpiotzh/mylog v1.0.10
github.com/scorpiotzh/toolib v1.1.6-0.20230210123015-9770bc1afe72
github.com/scorpiotzh/toolib v1.1.6
github.com/shopspring/decimal v1.3.1
github.com/urfave/cli/v2 v2.10.2
gorm.io/gorm v1.23.6
Expand Down Expand Up @@ -42,7 +42,6 @@ require (
github.com/gogf/gf/v2 v2.3.3 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/jinzhu/gorm v1.9.16 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.4 // indirect
github.com/json-iterator/go v1.1.9 // indirect
Expand Down

0 comments on commit 4f143d9

Please sign in to comment.