fix: amount
This commit is contained in:
@@ -269,7 +269,8 @@ func (ctl *posts) Buy(ctx fiber.Ctx, id int64, user *model.Users) (*wechat.JSAPI
|
||||
Expire(30 * time.Minute).
|
||||
Description(post.Title).
|
||||
OutTradeNo(order.OrderNo).
|
||||
Payer(user.OpenID)
|
||||
Payer(user.OpenID).
|
||||
CNYAmount(post.Price * int64(post.Discount) / 100)
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("wepay.V3TransactionJsapi err: %v", err)
|
||||
|
||||
@@ -185,12 +185,18 @@ func (b *BodyMap) OutTradeNo(outTradeNo string) *BodyMap {
|
||||
}
|
||||
|
||||
// Amount
|
||||
func (b *BodyMap) Amount(total int, currency string) *BodyMap {
|
||||
func (b *BodyMap) Amount(total int64, currency CURRENCY) *BodyMap {
|
||||
return b.SetBodyMap("amount", func(bm gopay.BodyMap) {
|
||||
bm.Set("total", total).Set("currency", currency)
|
||||
bm.
|
||||
Set("total", total).
|
||||
Set("currency", currency.String())
|
||||
})
|
||||
}
|
||||
|
||||
func (b *BodyMap) CNYAmount(total int64) *BodyMap {
|
||||
return b.Amount(total, CNY)
|
||||
}
|
||||
|
||||
// Payer
|
||||
func (b *BodyMap) Payer(spOpenId string) *BodyMap {
|
||||
return b.SetBodyMap("payer", func(bm gopay.BodyMap) {
|
||||
@@ -202,3 +208,15 @@ func (b *BodyMap) Payer(spOpenId string) *BodyMap {
|
||||
func (b *BodyMap) SubMchId(subMchId string) *BodyMap {
|
||||
return b.Set("sub_mchid", subMchId)
|
||||
}
|
||||
|
||||
type CURRENCY string
|
||||
|
||||
func (c CURRENCY) String() string {
|
||||
return string(c)
|
||||
}
|
||||
|
||||
const (
|
||||
CNY CURRENCY = "CNY"
|
||||
USD CURRENCY = "USD"
|
||||
EUR CURRENCY = "EUR"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user