fix: amount

This commit is contained in:
Rogee
2025-05-06 16:23:45 +08:00
parent d2ec6db671
commit 5fafdd9d69
2 changed files with 22 additions and 3 deletions

View File

@@ -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)

View File

@@ -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"
)