qfpayslim

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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) CloseSyssn added in v1.0.3

func (c *Client) CloseSyssn(ctx context.Context, syssn string, cents int) (*Request, error)

CloseSyssn creates a close order request by syssn.

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, 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

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.

func (*Client) QuerySyssn added in v1.0.2

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

QuerySyssn sends a request to inquire about past payment transactions by syssn.

func (*Client) Refund added in v1.0.4

func (c *Client) Refund(ctx context.Context, syssn string, outTradeNo string, cents int) (*RefundResponse, error)

Refund creates a refund request to the QFPay API. It accepts the transaction number, the refund trade number, and the amount in cents.

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

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