alipay

package
v1.15.22 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTradeNotExist = errors.New("alipay trade does not exist")

ErrTradeNotExist reports that the gateway holds no trade for the order. A face-to-face trade is created only when the buyer scans the QR code, so a missing trade proves no money was collected for the order.

Functions

This section is empty.

Types

type Client

type Client struct {
	Config
	// contains filtered or unexported fields
}

func NewClient

func NewClient(c Config) *Client

func (*Client) CloseTrade added in v1.15.20

func (c *Client) CloseTrade(ctx context.Context, orderNo string) error

CloseTrade voids an unpaid trade at the gateway so its QR code can no longer collect money. Closing a trade the gateway never created reports ErrTradeNotExist, and the gateway rejects closing a trade that was already paid, so a success here proves no payment can arrive afterwards.

func (*Client) DecodeNotification

func (c *Client) DecodeNotification(form url.Values) (*Notification, error)

func (*Client) PreCreateTrade

func (c *Client) PreCreateTrade(ctx context.Context, order Order) (string, error)

func (*Client) QueryTrade

func (c *Client) QueryTrade(ctx context.Context, orderNo string) (*Trade, error)

type Config

type Config struct {
	AppId       string
	PrivateKey  string
	PublicKey   string
	InvoiceName string
	NotifyURL   string
	Sandbox     bool
	// Gateway overrides the sandbox gateway URL; Alipay has retired sandbox
	// hosts before, and tests point it at a local fake gateway. Ignored in
	// production, where only the official gateway may receive credentials.
	Gateway string
}

type Notification

type Notification struct {
	OrderNo string
	Amount  int64
	Status  Status
	TradeNo string
	AppId   string
}

type Order

type Order struct {
	OrderNo string
	Amount  int64
}

type Status

type Status string
const (
	Success  Status = "TRADE_SUCCESS"
	Pending  Status = "WAIT_BUYER_PAY"
	Closed   Status = "TRADE_CLOSED"
	Finished Status = "TRADE_FINISHED"
	Error    Status = "TRADE_ERROR"
)

func (Status) Paid added in v1.15.20

func (s Status) Paid() bool

Paid reports whether the status proves the buyer's money was collected; TRADE_FINISHED is the terminal paid state after the refund window closes.

type Trade added in v1.15.20

type Trade struct {
	OrderNo string
	TradeNo string
	Amount  int64
	Status  Status
}

Trade is the gateway's authoritative view of an order as returned by the alipay.trade.query endpoint. Amount is populated only for paid trades.

Jump to

Keyboard shortcuts

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