项目作者: du5

项目描述 :
Mugglepay SDK for Go
高级语言: Go
项目地址: git://github.com/du5/mugglepay.git
创建时间: 2021-01-09T08:03:22Z
项目社区:https://github.com/du5/mugglepay

开源协议:BSD 3-Clause "New" or "Revised" License

下载


mugglepay

安装

  1. go get github.com/du5/mugglepay@latest

引用

  1. import "github.com/du5/mugglepay"

创建订单

  1. func CreateOrder(c *gin.Context) {
  2. mgp := mugglepay.NewMugglepay("BitpayxApplicationKey")
  3. // host := "https://www.example.com"
  4. // 如需法币支付则必须设置正确的回调地址
  5. // mgp.CallBackUrl = host + "/payment/notify"
  6. // mgp.CancelUrl = host + "/user/code/return?merchantTradeNo="
  7. // mgp.SuccessUrl = host + "/user/code/return?merchantTradeNo="
  8. serverOrder, _ := mgp.CreateOrder(&mugglepay.Order{
  9. MerchantOrderId: orderId,
  10. PriceAmount: money,
  11. // PriceCurrency: "USD",
  12. // PayCurrency: "ALIPAY",
  13. // PayCurrency: "WECHAT",
  14. PayCurrency: "",
  15. PriceCurrency: "CNY",
  16. Title: "订单标题",
  17. Description: "订单描述",
  18. })
  19. // 支付宝/微信扫码链接,该函数仅 PayCurrency 为 ALIPAY/WECHAT 时可返回地址
  20. // 其他情况下均返回加密货币地址
  21. // aliqr := sorder.Invoice.GetUrl()
  22. c.Redirect(http.StatusFound, serverOrder.PaymentUrl)
  23. }

支付回调校验

  1. func Notify(c *gin.Context) {
  2. body, _ := c.GetRawData()
  3. var callback mugglepay.Callback
  4. if err := json.Unmarshal(body, &callback); err == nil {
  5. mgp := mugglepay.NewMugglepay("BitpayxApplicationKey")
  6. if mgp.VerifyOrder(&callback) {
  7. // code ...
  8. c.JSON(200, gin.H{"status": 200})
  9. return
  10. }
  11. }
  12. c.JSON(200, gin.H{"status": 400})
  13. }

修改支付方式

  1. mgp := mugglepay.NewMugglepay("BitpayxApplicationKey")
  2. sorder, _ := mgp.CheckOut(ServerOrderId, "P2P_BTC")
  3. // 应付金额
  4. money := sorder.Invoice.PayAmount
  5. // 法币支付链接
  6. // aliqr := sorder.Invoice.GetAlipayUrl()
  7. // 虚拟货币交易地址
  8. address := sorder.Invoice.Address
  9. // 虚拟货币交易备注
  10. memo := sorder.Invoice.Memo