Documentation ¶
Overview ¶
Package qfpayslim provides a client to interact with QFPay API. Docs: https://sdk.qfapi.com/
Index ¶
- Constants
- type Client
- 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)
- type QFError
- type QueryResponse
- 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) 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) (*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.
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 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.