payment

package
v1.1.2-0...-e53d5f3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package payment 微信支付

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandlePaidNotify

func HandlePaidNotify(res http.ResponseWriter, req *http.Request, fuck func(PaidNotify) (bool, string)) error

HandlePaidNotify 处理支付结果通知

func HandleRefundedNotify

func HandleRefundedNotify(res http.ResponseWriter, req *http.Request, key string, fuck func(RefundedNotify) (bool, string)) error

HandleRefundedNotify 处理退款结果通知 key: 微信支付 KEY

Types

type Order

type Order struct {
	// 必填 ...
	AppID      string `xml:"appid"`        // 小程序ID
	MchID      string `xml:"mch_id"`       // 商户号
	TotalFee   int    `xml:"total_fee"`    // 标价金额
	NotifyURL  string `xml:"notify_url"`   // 异步接收微信支付结果通知的回调地址,通知url必须为外网可访问的url,不能携带参数。
	OpenID     string `xml:"openid"`       // 下单用户ID
	Body       string `xml:"body"`         // 商品描述
	OutTradeNo string `xml:"out_trade_no"` // 商户订单号

	// 选填 ...
	DeviceInfo string    `xml:"device_info"`                //设备号
	IP         string    `xml:"spbill_create_ip,omitempty"` // 终端IP
	NoCredit   bool      `xml:"-"`                          // 上传此参数 no_credit 可限制用户不能使用信用卡支付
	StartedAt  time.Time `xml:"-"`                          // 交易起始时间 格式为yyyyMMddHHmmss
	ExpiredAt  time.Time `xml:"-"`                          // 交易结束时间 订单失效时间 格式为yyyyMMddHHmmss
	Tag        string    `xml:"goods_tag,omitempty"`        // 订单优惠标记,使用代金券或立减优惠功能时需要的参数,
	Detail     string    `xml:"detail,omitempty"`           // 商品详情
	Attach     string    `xml:"attach,omitempty"`           // 附加数据
}

Order 商户统一订单

func (Order) Unify

func (o Order) Unify(key string) (pres PaidResponse, err error)

Unify 统一下单

@key payment secret key

type PaidNotify

type PaidNotify struct {
	AppID         string  `xml:"appid"`               // 小程序ID
	MchID         string  `xml:"mch_id"`              // 商户号
	DeviceInfo    string  `xml:"device_info"`         //设备号
	TotalFee      int     `xml:"total_fee"`           // 标价金额
	NonceStr      string  `xml:"nonce_str"`           // 随机字符串
	Sign          string  `xml:"sign"`                // 签名
	SignType      string  `xml:"sign_type,omitempty"` // 签名类型: 目前支持HMAC-SHA256和MD5,默认为MD5
	OpenID        string  `xml:"openid"`
	TradeType     string  `xml:"trade_type"`                     // 交易类型 JSAPI
	Bank          string  `xml:"bank_type"`                      // 银行类型,采用字符串类型的银行标识
	Settlement    float64 `xml:"settlement_total_fee,omitempty"` // 应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额。
	FeeType       string  `xml:"fee_type,omitempty"`             // 货币种类: 符合ISO4217标准的三位字母代码,默认人民币: CNY
	CashFee       float64 `xml:"cash_fee"`                       // 现金支付金额订单的现金支付金额
	CashFeeType   string  `xml:"cash_fee_type,omitempty"`        // 现金支付货币类型: 符合ISO4217标准的三位字母代码,默认人民币: CNY
	CouponFee     float64 `xml:"coupon_fee,omitempty"`           // 总代金券金额: 代金券金额<=订单金额,订单金额-代金券金额=现金支付金额
	CouponCount   int     `xml:"coupon_count,omitempty"`         // 代金券使用数量
	TransactionID string  `xml:"transaction_id"`                 // 微信支付订单号
	Attach        string  `xml:"attach,omitempty"`               // 商家数据包,原样返回
	// 商户系统内部订单号: 要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。
	OutTradeNo string `xml:"out_trade_no"`
	// 支付完成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010
	Timeend string `xml:"time_end"`
}

PaidNotify 支付结果返回数据

type PaidResponse

type PaidResponse struct {
	AppID    string `xml:"appid"` // 小程序ID
	MchID    string `xml:"mch_id"`
	PrePayID string `xml:"prepay_id"`
	Sign     string `xml:"sign"`
	NonceStr string `xml:"nonce_str"`
}

PaidResponse 支付返回面向用户的集合

type Params

type Params struct {
	Timestamp string `json:"timeStamp"`
	NonceStr  string `json:"nonceStr"`
	SignType  string `json:"signType"`
	PaySign   string `json:"paySign"`
	Package   string `json:"package"`
}

Params 前端调用支付必须的参数 注意返回后得大小写格式不能变动

func GetParams

func GetParams(appID, key, nonceStr, prepayID string) (p Params, err error)

GetParams 获取支付参数

@appID 小程序 APPID @key 微信支付密钥 @nonceStr 统一下单得到的 nonceStr @prepayID 统一下单得到的 prepayID

type RefundedNotify

type RefundedNotify struct {
	AppID         string // 小程序ID
	MchID         string // 商户号
	NonceStr      string // 随机字符串
	TransactionID string `xml:"transaction_id"` // 微信支付订单号
	// 商户系统内部订单号: 要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。
	OutTradeNo  string  `xml:"out_trade_no"`
	RefundID    string  `xml:"refund_id"`     // 微信退款单号
	OutRefundNo string  `xml:"out_refund_no"` // 商户退款单号
	TotalFee    float64 `xml:"total_fee"`     // 标价金额
	// 当该订单有使用非充值券时,返回此字段。
	// 应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额。
	Settlement float64 `xml:"settlement_total_fee,omitempty"`
	RefundFee  float64 `xml:"refund_fee"` // 退款总金额,单位为分
	// 退款金额
	// 退款金额=申请退款金额-非充值代金券退款金额,退款金额<=申请退款金额
	SettlementRefund float64 `xml:"settlement_refund_fee"`
	// 退款状态
	// SUCCESS 退款成功 | CHANGE 退款异常 | REFUNDCLOSE 退款关闭
	RefundStatus string `xml:"refund_status"`
	// 退款成功时间
	// 资金退款至用户帐号的时间,格式2017-12-15 09:46:01
	SuccessTime string `xml:"success_time,omitempty"`
	// 退款入账账户:取当前退款单的退款入账方
	// 1)退回银行卡:  {银行名称}{卡类型}{卡尾号}
	// 2)退回支付用户零钱: 支付用户零钱
	// 3)退还商户: 商户基本账户 商户结算银行账户
	// 4)退回支付用户零钱通: 支付用户零钱通
	ReceiveAccount string `xml:"refund_recv_accout"`
	// 退款资金来源
	// REFUND_SOURCE_RECHARGE_FUNDS 可用余额退款/基本账户
	// REFUND_SOURCE_UNSETTLED_FUNDS 未结算资金退款
	RefundAccount string `xml:"refund_account"`
	// 退款发起来源
	// API接口
	// VENDOR_PLATFORM商户平台
	Source string `xml:"refund_request_source"`
}

RefundedNotify 解密后的退款通知消息体

type RefundedResponse

type RefundedResponse struct {
	AppID         string `xml:"appid"`
	MchID         string `xml:"mch_id"`
	TransactionID string `xml:"transaction_id"` // 微信订单号: 微信生成的订单号,在支付通知中有返回。和商户订单号二选一
	OutTradeNo    string `xml:"out_trade_no"`   // 商户订单号: 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。 和微信订单号二选一
	OutRefundNo   string `xml:"out_refund_no"`  // 商户退款单号: 商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
	// 微信退款单号
	RefundID string `xml:"refund_id"`
	// 退款总金额,单位为分,可以做部分退款
	RefundFee int `xml:"refund_fee"`
	// 应结退款金额
	// 去掉非充值代金券退款金额后的退款金额,退款金额=申请退款金额-非充值代金券退款金额,退款金额<=申请退款金额
	SettlementRefundFee int `xml:"settlement_refund_fee"`
	// 标价金额
	// 订单总金额,单位为分,只能为整数
	TotalFee int `xml:"total_fee"`
	// 应结订单金额
	// 去掉非充值代金券金额后的订单总金额,应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额。
	SettlementTotalFee int `xml:"settlement_total_fee"`
	// 标价币种
	// FeeType            int `xml:"fee_type"`
	// 现金支付金额
	CashFee       int    `xml:"cash_fee"`
	CashRefundFee int    `xml:"cash_refund_fee"`
	Sign          string `xml:"sign"`
	NonceStr      string `xml:"nonce_str"`
}

RefundedResponse 请求退款返回数据

type Refunder

type Refunder struct {
	// 必填 ...
	AppID         string `xml:"appid"`  // 小程序ID
	MchID         string `xml:"mch_id"` // 商户号
	TotalFee      int    `xml:"total_fee"`
	RefundFee     int    `xml:"refund_fee"`               // 退款金额: 退款总金额,订单总金额,单位为分,只能为整数
	TransactionID string `xml:"transaction_id,omitempty"` // 微信订单号: 微信生成的订单号,在支付通知中有返回。和商户订单号二选一
	OutTradeNo    string `xml:"out_trade_no,omitempty"`   // 商户订单号: 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。 和微信订单号二选一
	OutRefundNo   string `xml:"out_refund_no"`            // 商户退款单号: 商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。

	// 选填 ...
	// RefundFeeType string `xml:"refund_fee_type,omitempty"` // 货币种类: 货币类型,符合ISO 4217标准的三位字母代码,默认人民币: CNY
	RefundDesc string `xml:"refund_desc,omitempty"` // 退款原因: 若商户传入,会在下发给用户的退款消息中体现退款原因

	// 退款结果通知url: 异步接收微信支付退款结果通知的回调地址
	// 通知 URL 必须为外网可访问且不允许带参数
	// 如果参数中传了notify_url,则商户平台上配置的回调地址将不会生效。
	NotifyURL string `xml:"notify_url,omitempty"`
}

Refunder 退款表单数据

func (Refunder) Refund

func (r Refunder) Refund(key, certPath, keyPath string) (rres RefundedResponse, err error)

Refund 发起退款请求

type TransferInfo

type TransferInfo struct {
	AppID      string `xml:"appid"`
	MchID      string `xml:"mch_id"`           // 商户号
	OutTradeNo string `xml:"partner_trade_no"` // 商户订单号
}

TransferInfo params to get transfer info

func (TransferInfo) GetInfo

func (t TransferInfo) GetInfo(key string, certPath, keyPath string) (res TransferInfoResponse, err error)

GetInfo 转账信息

type TransferInfoResponse

type TransferInfoResponse struct {
	TransferTime time.Time
	// contains filtered or unexported fields
}

TransferInfoResponse 转账返回数据

type TransferResponse

type TransferResponse struct {
	Datetime time.Time
	// contains filtered or unexported fields
}

TransferResponse 转账返回数据

type Transferer

type Transferer struct {
	// required
	AppID      string `xml:"mch_appid"`
	MchID      string `xml:"mchid"`            // 商户号
	OutTradeNo string `xml:"partner_trade_no"` // 商户订单号
	ToUser     string `xml:"openid"`
	Amount     int    `xml:"amount"`
	// 企业付款描述信息
	Desc string `xml:"desc"`

	// optional
	IP string `xml:"spbill_create_ip,omitempty"`
	// 校验用户姓名选项
	CheckName bool   `xml:"-"`
	Device    string `xml:"device_info,omitempty"`
	// 收款用户真实姓名
	// 如果check_name设置为FORCE_CHECK,则必填用户真实姓名
	RealName string `xml:"re_user_name,omitempty"`
}

Transferer transfer params

func (Transferer) Transfer

func (t Transferer) Transfer(key string, certPath, keyPath string) (res TransferResponse, err error)

Transfer 转账到微信用户零钱

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL