payment

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestRootKeysURL = "https://payments.developers.google.com/paymentmethodtoken/test/keys.json"
	ProdRootKeysURL = "https://payments.developers.google.com/paymentmethodtoken/keys.json"
)

常量定义

Variables

This section is empty.

Functions

This section is empty.

Types

type BillingAddress

type BillingAddress struct {
	Name               string `json:"name,omitempty"`
	Address1           string `json:"address1,omitempty"`
	Address2           string `json:"address2,omitempty"`
	Address3           string `json:"address3,omitempty"`
	Locality           string `json:"locality,omitempty"`
	AdministrativeArea string `json:"administrativeArea,omitempty"`
	CountryCode        string `json:"countryCode,omitempty"`
	PostalCode         string `json:"postalCode,omitempty"`
	PhoneNumber        string `json:"phoneNumber,omitempty"`
}

BillingAddress 账单地址

type CardDetails

type CardDetails struct {
	// PAN信息
	PAN             string `json:"pan,omitempty"`
	ExpirationMonth int    `json:"expirationMonth,omitempty"`
	ExpirationYear  int    `json:"expirationYear,omitempty"`

	// 持卡人信息
	CardholderName string `json:"cardholderName,omitempty"`

	// 账单地址
	BillingAddress *BillingAddress `json:"billingAddress,omitempty"`

	// 其他信息
	CardClass   string `json:"cardClass,omitempty"`
	CardDetails string `json:"cardDetails,omitempty"`
}

CardDetails 卡片详情

type Client

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

Client Google Pay客户端

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient 创建新的客户端

func (*Client) Close

func (c *Client) Close() error

Close 关闭客户端

func (*Client) DecryptPaymentToken

func (c *Client) DecryptPaymentToken(ctx context.Context, encryptedToken string) (*PaymentToken, error)

DecryptPaymentToken 解密支付Token

func (*Client) GetPaymentMethodInfo

func (c *Client) GetPaymentMethodInfo(ctx context.Context, token *PaymentToken) (*PaymentMethodInfo, error)

GetPaymentMethodInfo 获取支付方法信息

func (*Client) Health

func (c *Client) Health(ctx context.Context) error

Health 健康检查

func (*Client) ValidatePaymentToken

func (c *Client) ValidatePaymentToken(ctx context.Context, token *PaymentToken) error

ValidatePaymentToken 验证支付Token

type Config

type Config struct {
	// 环境配置
	Environment Environment `json:"environment"`

	// 商户配置
	MerchantID   string `json:"merchant_id"`
	MerchantName string `json:"merchant_name"`

	// 密钥配置
	PrivateKeyPath string `json:"private_key_path"`
	PrivateKeyData []byte `json:"-"` // 不序列化敏感数据

	// 网络配置
	Timeout    time.Duration `json:"timeout"`
	MaxRetries int           `json:"max_retries"`

	// 缓存配置
	CacheEnabled bool          `json:"cache_enabled"`
	CacheTTL     time.Duration `json:"cache_ttl"`

	// 日志配置
	LogLevel       logs.LogLevel `json:"log_level"`
	EnableDebugLog bool          `json:"enable_debug_log"`
}

Config Google Pay配置

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig 默认配置

func (*Config) Validate

func (c *Config) Validate() error

Validate 验证配置

type EncryptedToken

type EncryptedToken struct {
	ProtocolVersion string        `json:"protocolVersion"`
	Signature       string        `json:"signature"`
	SignedMessage   SignedMessage `json:"signedMessage"`
}

EncryptedToken 加密Token结构

type Environment

type Environment string

Environment 环境类型

const (
	EnvironmentSandbox    Environment = "sandbox"
	EnvironmentProduction Environment = "production"
)

type KeyManager

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

KeyManager 密钥管理器

func NewKeyManager

func NewKeyManager(config *Config, logger logs.Logger) (*KeyManager, error)

NewKeyManager 创建密钥管理器

func (*KeyManager) Close

func (km *KeyManager) Close() error

Close 关闭密钥管理器

func (*KeyManager) GetPrivateKey

func (km *KeyManager) GetPrivateKey() *ecdsa.PrivateKey

GetPrivateKey 获取私钥

func (*KeyManager) GetRootKey

func (km *KeyManager) GetRootKey(keyID string) (*ecdsa.PublicKey, error)

GetRootKey 获取根密钥

func (*KeyManager) Health

func (km *KeyManager) Health(ctx context.Context) error

Health 健康检查

func (*KeyManager) RefreshRootKeys

func (km *KeyManager) RefreshRootKeys(ctx context.Context) error

RefreshRootKeys 刷新根密钥

type PaymentMethodInfo

type PaymentMethodInfo struct {
	Type        string      `json:"type"`
	Description string      `json:"description"`
	Network     string      `json:"network"`
	Details     CardDetails `json:"details"`
}

PaymentMethodInfo 支付方法信息

type PaymentToken

type PaymentToken struct {
	// 基本信息
	MessageID                string `json:"messageId"`
	MessageExpiration        string `json:"messageExpiration"`
	PaymentMethod            string `json:"paymentMethod"`
	PaymentMethodType        string `json:"paymentMethodType"`
	PaymentMethodDescription string `json:"paymentMethodDescription"`

	// 网络信息
	PaymentNetwork string `json:"paymentNetwork,omitempty"`

	// 卡片信息
	PaymentMethodDetails CardDetails `json:"paymentMethodDetails"`

	// 3DS信息
	AuthenticationMethod string `json:"authenticationMethod,omitempty"`
	CryptogramType       string `json:"cryptogramType,omitempty"`
	Cryptogram           string `json:"cryptogram,omitempty"`
	EciIndicator         string `json:"eciIndicator,omitempty"`

	// 内部字段
	ExpiresAt   time.Time `json:"-"`
	DecryptedAt time.Time `json:"-"`
}

PaymentToken 支付Token结构

func (*PaymentToken) GetCardBrand

func (pt *PaymentToken) GetCardBrand() string

GetCardBrand 获取卡品牌

func (*PaymentToken) GetCardLast4

func (pt *PaymentToken) GetCardLast4() string

GetCardLast4 获取卡号后4位

func (*PaymentToken) IsExpired

func (pt *PaymentToken) IsExpired() bool

IsExpired 检查Token是否过期

func (*PaymentToken) MarshalJSON

func (pt *PaymentToken) MarshalJSON() ([]byte, error)

MarshalJSON 自定义JSON序列化

func (*PaymentToken) UnmarshalJSON

func (pt *PaymentToken) UnmarshalJSON(data []byte) error

UnmarshalJSON 自定义JSON反序列化

type SignedMessage

type SignedMessage struct {
	EncryptedMessage   string `json:"encryptedMessage"`
	EphemeralPublicKey string `json:"ephemeralPublicKey"`
	Tag                string `json:"tag"`
	KeyID              string `json:"keyId,omitempty"`
	Signature          string `json:"signature,omitempty"`
}

SignedMessage 签名消息结构

type TokenHandler

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

TokenHandler Token处理器

func NewTokenHandler

func NewTokenHandler(config *Config, keyManager *KeyManager, logger logs.Logger) (*TokenHandler, error)

NewTokenHandler 创建Token处理器

func (*TokenHandler) DecryptToken

func (th *TokenHandler) DecryptToken(ctx context.Context, encryptedTokenStr string) (*PaymentToken, error)

DecryptToken 解密Token

func (*TokenHandler) Health

func (th *TokenHandler) Health(ctx context.Context) error

Health 健康检查

func (*TokenHandler) ValidateSignature

func (th *TokenHandler) ValidateSignature(ctx context.Context, token *PaymentToken) error

ValidateSignature 验证Token签名

type TokenProtocol

type TokenProtocol string

TokenProtocol Token协议类型

const (
	EcV1 TokenProtocol = "ECv1"
	EcV2 TokenProtocol = "ECv2"
)

func (TokenProtocol) IsValid

func (t TokenProtocol) IsValid() bool

IsValid 验证协议版本是否有效

func (TokenProtocol) String

func (t TokenProtocol) String() string

String 实现Stringer接口

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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