Giter Site home page Giter Site logo

gpay's Introduction

gpay

golang payment for alipay, wechatpay

Alipay, Wechatpay Golang Client

AlipayClient Api

  • GetOrderString
  • GetOrderQrCode
  • ReturnVerify
  • NotifyVerify

import (
    "time"
)
import (
    "github.com/sanxia/gpay/alipay"
)

var alipayClient *alipay.AlipayClient

func init(){
    appId := "you app id"
    appPrivate := "you app single line private"
    alipayPublicKey := "alipay single line public"
    alipayClient = alipay.NewAlipayClient(appId, appPrivate, alipayPublicKey)
}

func AlipayOrder() (string, error){
    outTradeNo := "test-1234567890"
    subject := "mall produce test123"
    body := "mall product info test123"
    amount := 0.01
    creationDate := time.Now()
    orderString, err := alipayClient.GetOrderString(
        outTradeNo,
        subject,
        body,
        amount,
        creationDate)

    return orderString, nil
}

func AlipayQrOrder() (string, error){
    outTradeNo := "test-1234567890"
    subject := "mall produce test123"
    body := "mall product info test123"
    amount := 0.01
    orderQrCode, err := alipayClient.GetOrderQrCode(
        outTradeNo,
        subject,
        body,
        amount)

    return orderQrCode, nil
}

WechatpayClient Api

  • UnifiedOrder

import (
    "time"
)
import (
    "github.com/sanxia/gpay/wechatpay"
)

var wechatpayClient *wechatpay.WechatpayClient

func init(){
    appId := "you app id"
    partnerId := "you partner id"
    apiSecret := "you api secret"
    wechatpayClient = wechatpay.NewWechatpayClient(appId, partnerId, apiSecret)
}

func WechatpayUnifiedOrder() (*wechatpay.UnifiedOrderResponse, error){
    outTradeNo := "test-1234567890"
    body := "mall product info test123"
    amount := 1
    ip := "127.0.0.1"

    goodsDetail := &wechatpay.UnifiedOrderDetailItem{
        GoodsId: "test123",
        GoodsName: "test product",
        Quantity: 1,
        Price: amount,
    }
    unifiedOrderDetail := &wechatpay
    .UnifiedOrderDetail{
        GoodsDetail: []*UnifiedOrderDetailItem{
            goodsDetail
        },
    }

    return wechatpayClient.UnifiedOrder(
        outTradeNo,
        body,
        amount,
        ip,
        unifiedOrderDetail)
}

gpay's People

Contributors

sanxia 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.