Documentation
¶
Index ¶
- type Client
- func (client *Client) CreateOrder(ctx context.Context, req CreateOrderRequest) (*CreateOrderResponse, error)
- func (client *Client) JSAPIPayParams(appId, prepayId string) *JSAPIPayParams
- func (client *Client) MustSetCertificate(certPEM, keyPem string)
- func (client *Client) QueryOrder(ctx context.Context, req QueryOrderRequest) (*QueryOrderResponse, error)
- func (client *Client) QueryRefundOrder(ctx context.Context, req QueryRefundOrderRequest) (*QueryRefundOrderResponse, error)
- func (client *Client) RefundOrder(ctx context.Context, req RefundOrderRequest) (*RefundOrderResponse, error)
- func (client *Client) SetCertificate(certPEM, keyPem string) error
- func (client *Client) Transfer(ctx context.Context, req TransferRequest) (*TransferResponse, error)
- func (client *Client) TransferQuery(ctx context.Context, req TransferQueryRequest) (*TransferQueryResponse, error)
- func (client *Client) TransferV3(ctx context.Context, req V3TransferRequests) (*V3TransferResponse, error)
- type CreateOrderRequest
- type CreateOrderResponse
- type JSAPIPayParams
- type JsonResponse
- type JsonResponseError
- type QueryOrderRequest
- type QueryOrderResponse
- type QueryRefundOrderRequest
- type QueryRefundOrderResponse
- type RefundOrderRequest
- type RefundOrderResponse
- type Response
- type ResponseError
- type TransferQueryRequest
- type TransferQueryResponse
- type TransferRequest
- type TransferResponse
- type Utc8Time
- type V3TransferRequest
- type V3TransferRequests
- type V3TransferResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { MchId string Key string Debug bool TLSClientConfig *tls.Config // contains filtered or unexported fields }
func (*Client) CreateOrder ¶ added in v1.1.0
func (client *Client) CreateOrder(ctx context.Context, req CreateOrderRequest) (*CreateOrderResponse, error)
CreateOrder initiates payment.
func (*Client) JSAPIPayParams ¶ added in v1.1.1
func (client *Client) JSAPIPayParams(appId, prepayId string) *JSAPIPayParams
Generate pay params for JSAPI.
func (*Client) MustSetCertificate ¶ added in v1.1.1
MustSetCertificate is like SetCertificate but panics if operation fails.
func (*Client) QueryOrder ¶ added in v1.1.0
func (client *Client) QueryOrder(ctx context.Context, req QueryOrderRequest) (*QueryOrderResponse, error)
QueryOrder gets information of an order by Transaction ID or Trade No.
func (*Client) QueryRefundOrder ¶ added in v1.2.0
func (client *Client) QueryRefundOrder(ctx context.Context, req QueryRefundOrderRequest) (*QueryRefundOrderResponse, error)
QueryRefundOrder gets information of a refund order by Transaction ID or Trade No.
func (*Client) RefundOrder ¶ added in v1.2.0
func (client *Client) RefundOrder(ctx context.Context, req RefundOrderRequest) (*RefundOrderResponse, error)
RefundOrder initiates refund. Need to set certificate (client.SetCertificate) first.
func (*Client) SetCertificate ¶
Set certificate (apiclient_cert.pem, string starts with -----BEGIN CERTIFICATE-----) and private key (apiclient_key.pem, string starts with -----BEGIN PRIVATE KEY-----). If you have different certificate format, set client's TLSClientConfig property directly.
If you have p12 file (apiclient_cert.p12), you can use following command to get certificate and private key:
openssl pkcs12 -in apiclient_cert.p12 -nodes
func (*Client) Transfer ¶
func (client *Client) Transfer(ctx context.Context, req TransferRequest) (*TransferResponse, error)
Transfer money to user. Docs: https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2
func (*Client) TransferQuery ¶
func (client *Client) TransferQuery(ctx context.Context, req TransferQueryRequest) (*TransferQueryResponse, error)
Query existing transaction. Docs: https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_3
func (*Client) TransferV3 ¶ added in v1.2.1
func (client *Client) TransferV3(ctx context.Context, req V3TransferRequests) (*V3TransferResponse, error)
Transfer money to user. Docs: https://pay.weixin.qq.com/docs/merchant/apis/batch-transfer-to-balance/transfer-batch/initiate-batch-transfer.html
type CreateOrderRequest ¶ added in v1.1.0
type CreateOrderRequest struct { AppId string // required DeviceInfo string // optional SignType string // optional, either MD5 (default) or HMAC-SHA256 Body string // required, max length is 127 Detail string // optional, max length is 6000 Attach string // optional, max length is 127 OutTradeNo string // required, max length is 32, min length is 6 FeeType string // optional, defaults to CNY TotalFee int // required, in cents SpbillCreateIp string // required, user's ip address TimeStart string // optional, UTC+8 time format: 20060102150405 TimeExpire string // optional, UTC+8 time format: 20060102150405 GoodsTag string // optional, max length is 32 NotifyURL string // required, max length is 256 TradeType string // required, can be JSAPI, NATIVE, APP ProductId string // required if TradeType == NATIVE, max length is 32 LimitPay string // optional, set to no_credit to disallow credit cards OpenId string // required if TradeType == JSAPI Receipt string // optional, set to Y to enable receipt ProfitSharing string // optional, either Y or N (default) SceneInfo string // optional }
type CreateOrderResponse ¶ added in v1.1.0
type CreateOrderResponse struct { Response AppId string `xml:"mch_appid,omitempty"` MchId string `xml:"mchid,omitempty"` DeviceInfo string `xml:"device_info,omitempty"` TradeType string `xml:"trade_type"` PrepayId string `xml:"prepay_id"` CodeUrl string `xml:"code_url"` }
func (CreateOrderResponse) AsError ¶ added in v1.1.0
func (r CreateOrderResponse) AsError() error
type JSAPIPayParams ¶ added in v1.1.1
type JsonResponse ¶ added in v1.2.1
type JsonResponse struct { Code string `json:"code,omitempty"` Message string `json:"message,omitempty"` }
func (JsonResponse) Success ¶ added in v1.2.1
func (r JsonResponse) Success() bool
type JsonResponseError ¶ added in v1.2.1
type JsonResponseError JsonResponse
func (JsonResponseError) Error ¶ added in v1.2.1
func (r JsonResponseError) Error() string
type QueryOrderRequest ¶ added in v1.1.0
type QueryOrderResponse ¶ added in v1.1.0
type QueryOrderResponse struct { Response AppId string `xml:"appid,omitempty"` MchId string `xml:"mch_id,omitempty"` DeviceInfo string `xml:"device_info,omitempty"` OpenId string `xml:"openid"` IsSubscribe string `xml:"is_subscribe"` TradeType string `xml:"trade_type"` TradeState string `xml:"trade_state"` BankType string `xml:"bank_type"` TotalFee int `xml:"total_fee"` SettlementTotalFee int `xml:"settlement_total_fee"` FeeType string `xml:"fee_type"` CashFee int `xml:"cash_fee"` CashFeeType string `xml:"cash_fee_type"` CouponFee int `xml:"coupon_fee"` CouponCount int `xml:"coupon_count"` TransactionId string `xml:"transaction_id"` OutTradeNo string `xml:"out_trade_no"` Attach string `xml:"attach"` TimeEnd string `xml:"time_end"` TradeStateDesc string `xml:"trade_state_desc"` }
func (QueryOrderResponse) AsError ¶ added in v1.1.0
func (r QueryOrderResponse) AsError() error
func (QueryOrderResponse) Paid ¶ added in v1.1.1
func (r QueryOrderResponse) Paid() bool
Check if order is successfully paid.
type QueryRefundOrderRequest ¶ added in v1.2.0
type QueryRefundOrderResponse ¶ added in v1.2.0
type QueryRefundOrderResponse struct { Response AppId string `xml:"appid"` MchId string `xml:"mch_id"` TotalRefundCount int `xml:"total_refund_count"` TransactionId string `xml:"transaction_id"` OutTradeNo string `xml:"out_trade_no"` TotalFee int `xml:"total_fee"` SettlementTotalFee int `xml:"settlement_total_fee"` FeeType string `xml:"fee_type,omitempty"` CashFee int `xml:"cash_fee"` RefundCount int `xml:"refund_count"` OutRefundNo0 string `xml:"out_refund_no_0"` RefundId0 string `xml:"refund_id_0"` RefundChannel0 string `xml:"refund_channel_0"` RefundFee0 int `xml:"refund_fee_0"` RefundFee int `xml:"refund_fee"` CouponRefundFee int `xml:"coupon_refund_fee"` SettlementRefundFee0 int `xml:"settlement_refund_fee_0"` RefundStatus0 string `xml:"refund_status_0"` RefundAccount0 string `xml:"refund_account_0"` RefundRecvAccout0 string `xml:"refund_recv_accout_0"` RefundSuccessTime0 string `xml:"refund_success_time_0"` CashRefundFee int `xml:"cash_refund_fee"` }
func (QueryRefundOrderResponse) AsError ¶ added in v1.2.0
func (r QueryRefundOrderResponse) AsError() error
func (QueryRefundOrderResponse) Refunded ¶ added in v1.2.0
func (r QueryRefundOrderResponse) Refunded() bool
Check if order is successfully refunded.
type RefundOrderRequest ¶ added in v1.2.0
type RefundOrderRequest struct { AppId string // required SignType string // optional, either MD5 (default) or HMAC-SHA256 TransactionId string // either TransactionId or OutTradeNo is required OutTradeNo string OutRefundNo string // required, max length is 64 TotalFee int // required, in cents RefundFee int // required, in cents RefundFeeType string // optional, defaults to CNY RefundDesc string // optional RefundAccount string // optional NotifyURL string // optional }
type RefundOrderResponse ¶ added in v1.2.0
type RefundOrderResponse struct { Response AppId string `xml:"appid,omitempty"` MchId string `xml:"mch_id,omitempty"` TransactionId string `xml:"transaction_id"` OutTradeNo string `xml:"out_trade_no"` 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 string `xml:"fee_type"` CashFee int `xml:"cash_fee"` CashFeeType string `xml:"cash_fee_type"` CashRefundFee int `xml:"cash_refund_fee"` }
func (RefundOrderResponse) AsError ¶ added in v1.2.0
func (r RefundOrderResponse) AsError() error
type Response ¶
type Response struct { ReturnCode string `xml:"return_code"` ReturnMsg string `xml:"return_msg"` NonceStr string `xml:"nonce_str,omitempty"` Sign string `xml:"sign,omitempty"` ResultCode string `xml:"result_code,omitempty"` ErrCode string `xml:"err_code,omitempty"` ErrCodeDes string `xml:"err_code_des,omitempty"` }
type ResponseError ¶
type ResponseError Response
func (ResponseError) Error ¶
func (r ResponseError) Error() string
type TransferQueryRequest ¶
TransferQueryRequest is used in TransferQuery() function.
type TransferQueryResponse ¶
type TransferQueryResponse struct { Response AppId string `xml:"appid,omitempty"` MchId string `xml:"mch_id,omitempty"` DetailId string `xml:"detail_id,omitempty"` Status string `xml:"status,omitempty"` Reason string `xml:"reason,omitempty"` OpenId string `xml:"openid,omitempty"` TransferName string `xml:"transfer_name,omitempty"` PartnerTradeNo string `xml:"partner_trade_no"` PaymentAmount int `xml:"payment_amount"` TransferTime *Utc8Time `xml:"transfer_time"` PaymentTime *Utc8Time `xml:"payment_time"` Desc string `xml:"desc"` }
func (TransferQueryResponse) AsError ¶
func (r TransferQueryResponse) AsError() error
type TransferRequest ¶
type TransferRequest struct { AppId string // required OpenId string // required DeviceInfo string // optional PartnerTradeNo string // required CheckName string // optional, either NO_CHECK (default) or FORCE_CHECK ReUserName string // required if CheckName is FORCE_CHECK Amount int // required, must not lower than 100 (1.00 yuan) Desc string // required SpbillCreateIp string // optional, user's IP address }
TransferRequest is used in Transfer() function.
type TransferResponse ¶
type TransferResponse struct { Response AppId string `xml:"mch_appid,omitempty"` MchId string `xml:"mchid,omitempty"` DeviceInfo string `xml:"device_info,omitempty"` PartnerTradeNo string `xml:"partner_trade_no"` PaymentNo string `xml:"payment_no"` PaymentTime *Utc8Time `xml:"payment_time"` }
func (TransferResponse) AsError ¶
func (r TransferResponse) AsError() error
type Utc8Time ¶
func (Utc8Time) MarshalJSON ¶ added in v1.0.1
func (*Utc8Time) UnmarshalJSON ¶ added in v1.0.1
func (*Utc8Time) UnmarshalXML ¶
type V3TransferRequest ¶ added in v1.2.1
type V3TransferRequests ¶ added in v1.2.1
type V3TransferRequests struct { AppId string // required OutBatchNo string // required BatchName string // required BatchRemark string // required TransferSceneId string // optional NotifyUrl string // optional Transfers []V3TransferRequest // required }
V3TransferRequests is used in TransferV3() function.
type V3TransferResponse ¶ added in v1.2.1
type V3TransferResponse struct { JsonResponse OutBatchNo string `json:"out_batch_no"` BatchId string `json:"batch_id"` CreateTime time.Time `json:"create_time"` BatchStatus string `json:"batch_status"` }
func (V3TransferResponse) AsError ¶ added in v1.2.1
func (r V3TransferResponse) AsError() error