qfpayslim

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 16 Imported by: 0

README

qfpayslim

Usage:

qfpay := qfpayslim.Client{
    Prefix:  "https://openapi-hk.qfapi.com",
    AppCode: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    Key:     "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    // Debug:   true,
}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
req, err := qfpay.MakePayment(ctx, qfpayslim.PayTypePayMeQRCode, "TradeNo", "ProductName", 100)
if err != nil {
    return err
}
var qrcode, qfpaytxid string
if err := req.Do(&qrcode, "qrcode", &qfpaytxid, "syssn"); err != nil {
    return err
}


responses, err := qfpay.Query(ctx, "TradeNo", "TradeNo2", ...)
if err != nil {
    return err
}

Documentation

Overview

Package qfpayslim provides a client to interact with QFPay API. Docs: https://sdk.qfapi.com/

Index

Constants

View Source
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

func (c *Client) GenerateSign(payload url.Values) string

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.

func (*Client) Query

func (c *Client) Query(ctx context.Context, outTradeNo ...string) ([]QueryResponse, error)

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.

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.

func (QFError) Error

func (e QFError) Error() string

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

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

func (*Request) Do

func (req *Request) Do(dest ...interface{}) error

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.

Jump to

Keyboard shortcuts

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