wechat

package
v0.0.0-...-2c9f6af Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package wechat implements payment.Provider for WeChat Pay v3 NATIVE. The PayURL call creates a NATIVE order and returns the code_url as a "qr" PayDirective that the frontend renders as a QR code for the user to scan. Async notifications are JSON-signed; the platform certificate is fetched lazily (every 6h) to verify the signature, then the resource is decrypted with the APIv3 key. Credentials are read lazily from SystemConfig (wechat.* keys) through the injected ConfigSource.

Index

Constants

Platform is the canonical identifier stored on Order.Platform.

Variables

This section is empty.

Functions

func NewProvider

func NewProvider(getConfig payment.ConfigSource) (payment.Provider, error)

NewProvider builds a wechat Provider. The wechat client is created lazily on first use and cached.

func Register

func Register(r *payment.Registry)

Register wires the wechat Provider into the given Registry under its platform name. Call this once at startup after NewRegistry.

Types

type Config

type Config struct {
	AppID      string
	MchID      string
	APIV3Key   string
	SerialNo   string
	PrivateKey string
	NotifyURL  string
}

Config holds wechat credentials read from SystemConfig (wechat.* keys).

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider is the wechat implementation of payment.Provider.

func (*Provider) IsConfigured

func (p *Provider) IsConfigured() bool

IsConfigured implements payment.ConfigStatusProvider.

func (*Provider) Mode

func (p *Provider) Mode() string

Mode implements payment.Provider. WeChat Pay uses a NATIVE QR code.

func (*Provider) PayURL

func (p *Provider) PayURL(order *model.Order, subject string) (*payment.PayDirective, error)

PayURL implements payment.Provider. It creates a NATIVE order and returns the code_url wrapped as a QR PayDirective.

func (*Provider) Platform

func (p *Provider) Platform() string

Platform implements payment.Provider.

func (*Provider) VerifyNotify

func (p *Provider) VerifyNotify(ctx context.Context, r *http.Request) (outTradeNo, tradeNo string, paid bool, err error)

VerifyNotify implements payment.Provider. WeChat posts a JSON body signed with its platform private key; we verify the signature with the platform public cert, then AES-decrypt the resource with the APIv3 key.

Jump to

Keyboard shortcuts

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