Documentation
¶
Overview ¶
Package qfpayslim provides a client to interact with QFPay API. Docs: https://sdk.qfapi.com/
Index ¶
- Constants
- type Client
- func (c *Client) CloseSyssn(ctx context.Context, syssn string, cents int) (*Request, error)
- func (c *Client) GenerateSign(payload url.Values) string
- func (c *Client) MakePayment(ctx context.Context, payType, outTradeNo, goodsName string, cents int, ...) (*Request, error)
- func (c *Client) NewRequest(ctx context.Context, method, url string, reqBody interface{}) (*Request, error)
- func (c *Client) Query(ctx context.Context, outTradeNo ...string) ([]QueryResponse, error)
- func (c *Client) QuerySyssn(ctx context.Context, syssn ...string) ([]QueryResponse, error)
- func (c *Client) Refund(ctx context.Context, syssn string, outTradeNo string, cents int) (*RefundResponse, error)
- type QFError
- type QueryResponse
- type RefundResponse
- type Request
Constants ¶
const ( PayTypeAlipayQRCode = "800101" // Alipay Merchant Presented QR Code Payment in store (MPM) (Overseas Merchants) PayTypeWechatPayQRCode = "800201" // WeChat Merchant Presented QR Code Payment (MPM) (Overseas & HK Merchants) PayTypePayMeQRCode = "805801" // PayMe Merchant Presented QR Code Payment in store (MPM) (HK Merchants) PayTypeFPSQRCode = "802001" // FPS Merchant Presented QR Code Payment (MPM) (HK Merchants) PayTypeAlipayAPP = "801510" // Alipay In-App Payment (HK Merchants) PayTypeAlipayWAP = "801512" // Alipay Online WAP Payment (HK Merchants) )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
Prefix string // https://openapi-hk.qfapi.com or https://test-openapi-hk.qfapi.com
AppCode string // 32-character string
Key string // 32-character string
Debug bool // show request and response body
}
Client struct is used to interact with QFPay API.
func (*Client) CloseSyssn ¶ added in v1.0.3
CloseSyssn creates a close order request by syssn.
func (*Client) GenerateSign ¶
GenerateSign generates a signature for authenticating API requests.
func (*Client) MakePayment ¶
func (c *Client) MakePayment(ctx context.Context, payType, outTradeNo, goodsName string, cents int, extra map[string]string) (*Request, error)
MakePayment creates a payment request to the QFPay API. It accepts payment type, transaction number, item name, and amount in cents.
func (*Client) NewRequest ¶
func (c *Client) NewRequest(ctx context.Context, method, url string, reqBody interface{}) (*Request, error)
NewRequest creates a new HTTP request with context, method, URL, and body. If the request body is already an `io.Reader`, it is used as-is. Otherwise, the request body is serialized into JSON format.
func (*Client) Query ¶
Query sends a request to inquire about past payment transactions. Multiple transaction numbers can be queried in a single request by passing them as separate arguments.
func (*Client) QuerySyssn ¶ added in v1.0.2
QuerySyssn sends a request to inquire about past payment transactions by syssn.
type QFError ¶
type QFError struct {
Code string `json:"respcd"`
Err string `json:"resperr"`
Messsage string `json:"respmsg"`
}
QFError represents an API error response from QFPay.
type QueryResponse ¶
type QueryResponse struct {
Cancel string `json:"cancel"` // Cancellation or refund indicator
Cardcd string `json:"cardcd"` // Card number
Cardtp string `json:"cardtp"` // Unknown
Chnlsn string `json:"chnlsn"` // Wallet/Channel transaction number
Chnlsn2 string `json:"chnlsn2"` // Additional transaction number added to the order
Clisn string `json:"clisn"` // Unknown
Errmsg string `json:"errmsg"` // Payment status message
GoodsDetail string `json:"goods_detail"` // Product details
GoodsInfo string `json:"goods_info"` // Product description
GoodsName string `json:"goods_name"` // Product name
OrderType string `json:"order_type"` // Order type (payment / refund)
OutTradeNo string `json:"out_trade_no"` // API order number
PayType string `json:"pay_type"` // Payment type
Paydtm string `json:"paydtm"` // Payment time of the transaction
Respcd string `json:"respcd"` // Payment status
Sysdtm string `json:"sysdtm"` // System transaction time
Syssn string `json:"syssn"` // QFPay transaction number
Txamt string `json:"txamt"` // Transaction amount
Txcurrcd string `json:"txcurrcd"` // Transaction currency
Txdtm string `json:"txdtm"` // Request transaction time
Udid string `json:"udid"` // Unique transaction device ID
Userid string `json:"userid"` // User ID
}
QueryResponse holds the information returned from QFPay API for a payment request. Fields included match the JSON response properties returned from the API.
func (QueryResponse) Paid ¶
func (res QueryResponse) Paid() bool
type RefundResponse ¶ added in v1.0.4
type RefundResponse struct {
Syssn string `json:"syssn"` // Refund Transaction ID referring to the newly created refund transaction
OrigSyssn string `json:"orig_syssn"` // Original Transaction ID, previous transaction ID referring to the original transaction that has been refunded
Txamt string `json:"txamt"` // Amount of the refund. Unit in cents (i.e. 100 = $1)
Sysdtm string `json:"sysdtm"` // System transaction time. Format: YYYY-MM-DD hh:mm:ss
Respcd string `json:"respcd"` // Return code, 0000-Request successful. 1143/1145 - merchants are required to continue to query the refund transaction result.
Resperr string `json:"resperr"` // Response message
CashFee string `json:"cash_fee"` // Actual payment amount by user = transaction amount - discounts
CashFeeType string `json:"cash_fee_type"` // Actual payment currency e.g. CNY
CashRefundFee string `json:"cash_refund_fee"` // Actual refund amount
CashRefundFeeType string `json:"cash_refund_fee_type"` // Actual refund currency e.g. CNY
}
RefundResponse holds the information returned from QFPay API for a refund request.
func (RefundResponse) Refunded ¶ added in v1.0.4
func (res RefundResponse) Refunded() bool
Refunded returns true if the refund request was successful.
type Request ¶
func (*Request) Do ¶
Do sends the HTTP request associated with the Request object. If successful, it unmarshals the returned data into the specified destination(s). The destination can be a struct to hold the unmarshalled JSON response, or a set of pointers that point to variables to store pieces of data identified by corresponding JSON keys.
If the 'dest' slice contains more than one value, they are expected to come in pairs with a pointer to a variable followed by the associated JSON key string.
If the 'dest' slice contains only one element, it should be a pointer to a struct or a []byte where the entire response can be stored.
It handles QFPay-specific error responses and returns a nil error on successful requests.
If Debug is enabled on the Client, the function will log HTTP request and response details.