payment

package
v4.0.0-alpha.7 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package payment 提供可插拔的支付网关注册表。 新增支付方式只需实现 Gateway 接口并在 init() 中 Register, 无需修改回调分发等核心代码(对标 XBoard 的插件式支付扩展)。

Index

Constants

View Source
const (
	StatusPaid    = "paid"
	StatusFailed  = "failed"
	StatusPending = "pending"
)

标准化支付状态常量。

Variables

This section is empty.

Functions

func Register

func Register(g Gateway)

Register 注册一个支付网关插件。通常在网关实现文件的 init() 中调用。 重复注册同一 type 会 panic,以便在启动期暴露配置错误。

func Types

func Types() []string

Types 返回所有已注册的网关类型,按字母序排列(便于测试和展示)。

Types

type CallbackContext

type CallbackContext struct {
	RawBody []byte      // 原始请求体
	Headers http.Header // 请求头(验签常用)
	Query   url.Values  // 查询参数(部分网关把结果放这里)
	Config  string      // 网关配置 JSON(含密钥等),由调用方从 DB 读取
}

CallbackContext 封装一次支付回调的全部输入,供网关验签与解析。

type CallbackResult

type CallbackResult struct {
	TradeNo        string // 商户订单号
	GatewayTradeNo string // 第三方订单号
	Amount         *float64
	Status         string // paid / failed / pending
	Raw            string // 原始回调数据,落库备查
}

CallbackResult 是网关验签并解析后的标准化结果。

type Gateway

type Gateway interface {
	// Type 返回网关类型标识(如 "epay"、"alipay"),与路由 :type 对应。
	Type() string
	// VerifyCallback 校验回调真实性并解析出标准化结果。
	// 验签失败必须返回 error,调用方据此拒绝(fail-closed)。
	VerifyCallback(ctx *CallbackContext) (*CallbackResult, error)
}

Gateway 是所有支付网关插件需实现的接口。

func Get

func Get(gatewayType string) (Gateway, bool)

Get 按类型返回已注册的网关,第二个返回值表示是否存在。

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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