GithubHelp home page GithubHelp logo

mugglepay-go-sdk's Introduction

mugglepay

安装

go get github.com/du5/[email protected]

引用

import "github.com/du5/mugglepay"

创建订单

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

支付回调校验

func Notify(c *gin.Context) {
	body, _ := c.GetRawData()
	var callback mugglepay.Callback
	if err := json.Unmarshal(body, &callback); err == nil {
        mgp := mugglepay.NewMugglepay("BitpayxApplicationKey")
        if mgp.VerifyOrder(&callback) {
            // code ... 
            c.JSON(200, gin.H{"status": 200})
            return
        }
    }
    c.JSON(200, gin.H{"status": 400})
}

修改支付方式

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

mugglepay-go-sdk's People

Contributors

du5 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.