payment

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AliPayConfig

type AliPayConfig struct {
	AppID           string `json:"app_id"`
	PrivateKey      string `json:"private_key"`
	AlipayPublicKey string `json:"alipay_public_key"`
	BaseURL         string `json:"base_url,omitempty"`
}

AliPayConfig contains AliPay-specific configuration.

type BillingConfig

type BillingConfig struct {
	// DefaultGateway is the gateway used when user does not specify one.
	DefaultGateway string `json:"default_gateway,omitempty"`

	// Gateways is a map of gateway ID to its configuration.
	// Supported IDs: "stripe", "alipay", "manual"
	Gateways map[string]GatewayConfig `json:"gateways,omitempty"`
}

BillingConfig defines the billing configuration loaded from config.json.

Example config.json (multi-gateway, flat format):

{
  "billing": {
    "default_gateway": "stripe",
    "gateways": {
      "stripe":  { "enabled": true, "api_key": "sk_live_xxx", "webhook_secret": "whsec_xxx", "currency": "usd" },
      "alipay":  { "enabled": true, "app_id": "...", "private_key": "...", "alipay_public_key": "..." },
      "manual":  { "enabled": true }
    }
  }
}

func (*BillingConfig) EffectiveDefaultGateway

func (c *BillingConfig) EffectiveDefaultGateway() string

EffectiveDefaultGateway returns the default gateway ID.

func (*BillingConfig) GatewayConfigs

func (c *BillingConfig) GatewayConfigs() map[string]*GatewayConfig

GatewayConfigs returns the enabled gateway configs as a flat map. It merges the legacy single-gateway format into the new map format for uniform handling.

func (*BillingConfig) Validate

func (c *BillingConfig) Validate() error

Validate validates the billing config and returns an error if invalid.

type GatewayConfig

type GatewayConfig struct {
	// Common
	Enabled *bool  `json:"enabled,omitempty"`  // default true if absent
	BaseURL string `json:"base_url,omitempty"` // override the default API base URL

	// Stripe — flat fields (preferred)
	APIKey        string `json:"api_key,omitempty"`
	WebhookSecret string `json:"webhook_secret,omitempty"`
	Currency      string `json:"currency,omitempty"`

	// AliPay — flat fields (preferred)
	AppID           string `json:"app_id,omitempty"`
	PrivateKey      string `json:"private_key,omitempty"`
	AlipayPublicKey string `json:"alipay_public_key,omitempty"`
}

GatewayConfig is a tagged union for each gateway's configuration. It supports two formats: flat (api_key, app_id etc. at top level) and nested (stripe:, alipay:, manual: sub-structs). Flat takes precedence if both are present. The BaseURL field overrides the default API endpoint for all gateways.

func (*GatewayConfig) AliPayConfig

func (g *GatewayConfig) AliPayConfig() *AliPayConfig

AliPayConfig returns the AliPay configuration, preferring flat fields over nested.

func (*GatewayConfig) IsEnabled

func (g *GatewayConfig) IsEnabled() bool

IsEnabled returns whether the gateway is enabled (default true if Enabled is nil).

func (*GatewayConfig) StripeConfig

func (g *GatewayConfig) StripeConfig() *StripeConfig

StripeConfig returns the Stripe configuration, preferring flat fields over nested.

type ManualConfig

type ManualConfig struct{}

ManualConfig contains Manual gateway configuration (currently no fields needed).

type StripeConfig

type StripeConfig struct {
	APIKey        string `json:"api_key"`
	WebhookSecret string `json:"webhook_secret"`
	Currency      string `json:"currency,omitempty"`
	BaseURL       string `json:"base_url,omitempty"`
}

StripeConfig contains Stripe-specific configuration.

Jump to

Keyboard shortcuts

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