Documentation
¶
Overview ¶
Package billingtest provides the billing module's behaviour-test harness: the real repository store over a private SQLite database and a miniredis instance, with seeding helpers for the rows order flows read. Only tests import it.
Index ¶
- func AlipayConfig(t testing.TB, appID, gatewayURL string) string
- func AlipayKey(t testing.TB) *rsa.PrivateKey
- func AlipayKeys(t testing.TB) (private, public string)
- func AlipaySign(t testing.TB, content string) string
- func UserContext(u *user.User) context.Context
- type AlipayAnswer
- type EPayV2
- type FakeAlipay
- type FakeStripe
- func (f *FakeStripe) Canceled() []string
- func (f *FakeStripe) Created() int
- func (f *FakeStripe) Customers() int
- func (f *FakeStripe) Keys() map[string]string
- func (f *FakeStripe) Seed(id string, amount int64, currency, status, orderNo, method string)
- func (f *FakeStripe) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (f *FakeStripe) SetStatus(id, status string)
- func (f *FakeStripe) Status(id string) string
- func (f *FakeStripe) Webhooks() map[string]string
- type Harness
- func (h *Harness) BalanceLogs(userID int64) []logEntity.Balance
- func (h *Harness) Coupon(code string, adjust ...func(*coupon.Coupon)) *coupon.Coupon
- func (h *Harness) Events(orderNo string) []order.Event
- func (h *Harness) GiftLogs(userID int64) []logEntity.Gift
- func (h *Harness) Logs(kind logEntity.Type, objectID int64) []*logEntity.SystemLog
- func (h *Harness) Order(o *order.Order) *order.Order
- func (h *Harness) Orders(userID int64) []*order.Order
- func (h *Harness) Payment(platform, config string, adjust ...func(*payment.Payment)) *payment.Payment
- func (h *Harness) Plan(unitPrice int64, adjust ...func(*subscribe.Subscribe)) *subscribe.Subscribe
- func (h *Harness) ReloadCoupon(code string) *coupon.Coupon
- func (h *Harness) ReloadOrder(orderNo string) *order.Order
- func (h *Harness) ReloadPlan(id int64) *subscribe.Subscribe
- func (h *Harness) ReloadWallet(userID int64) wallet.Wallet
- func (h *Harness) User(adjust ...func(*user.User)) *user.User
- func (h *Harness) UserSubscription(userID int64, plan *subscribe.Subscribe, adjust ...func(*usersub.Subscribe)) *usersub.Subscribe
- func (h *Harness) Wallet(userID, balance, gift int64)
- type Queue
- type UserCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AlipayConfig ¶
AlipayConfig is a face-to-face payment configuration of appID whose sandbox gateway is gatewayURL.
func AlipayKey ¶
func AlipayKey(t testing.TB) *rsa.PrivateKey
AlipayKey is the RSA key pair every Alipay test shares as both the merchant and the gateway key; it only exists so the SDK's signing and verification succeed.
func AlipayKeys ¶
AlipayKeys returns AlipayKey encoded as the payment configuration stores it: the PKCS#1 private key and the PKIX public key, base64.
func AlipaySign ¶
AlipaySign signs content as the gateway does: RSA-SHA256, base64.
Types ¶
type AlipayAnswer ¶
AlipayAnswer is the gateway's answer to one call: the business JSON, and whether it carries the gateway signature. Unsigned answers mimic gateway business failures.
type EPayV2 ¶ added in v1.21.1
EPayV2 is a local HTTPS peer with independent merchant/platform RSA keys. Requests and replies use a small independent signer to catch SDK drift.
type FakeAlipay ¶
type FakeAlipay struct {
// URL is the gateway address to configure.
URL string
// contains filtered or unexported fields
}
FakeAlipay impersonates the Alipay OpenAPI gateway. Respond receives the method, its per-method call number and the request's business content.
func NewFakeAlipay ¶
func NewFakeAlipay(t testing.TB, respond func(method string, call int, biz map[string]any) AlipayAnswer) *FakeAlipay
NewFakeAlipay starts a fake gateway for the test.
func (*FakeAlipay) Calls ¶
func (g *FakeAlipay) Calls(method string) int
Calls counts the calls of method.
func (*FakeAlipay) LastBiz ¶
func (g *FakeAlipay) LastBiz(method string) map[string]any
LastBiz is the business content of the last call of method.
func (*FakeAlipay) ServeHTTP ¶
func (g *FakeAlipay) ServeHTTP(w http.ResponseWriter, r *http.Request)
type FakeStripe ¶
type FakeStripe struct {
// Backends routes a Stripe client to the fake.
Backends *stripe.Backends
// contains filtered or unexported fields
}
FakeStripe is an in-process Stripe API answering the customer, ephemeral key, PaymentIntent and webhook endpoint calls billing makes. It records which secret key created each intent, so tests can prove that clients never borrow each other's key.
func NewFakeStripe ¶
func NewFakeStripe(t testing.TB) *FakeStripe
NewFakeStripe starts a fake Stripe API for the test.
func (*FakeStripe) Canceled ¶
func (f *FakeStripe) Canceled() []string
Canceled lists the cancelled intents in order.
func (*FakeStripe) Created ¶
func (f *FakeStripe) Created() int
Created counts the intents created through the API.
func (*FakeStripe) Customers ¶
func (f *FakeStripe) Customers() int
Customers counts the customers created.
func (*FakeStripe) Keys ¶
func (f *FakeStripe) Keys() map[string]string
Keys maps each order number to the secret key that created its intent.
func (*FakeStripe) Seed ¶
func (f *FakeStripe) Seed(id string, amount int64, currency, status, orderNo, method string)
Seed stores an existing PaymentIntent of orderNo.
func (*FakeStripe) ServeHTTP ¶
func (f *FakeStripe) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*FakeStripe) SetStatus ¶
func (f *FakeStripe) SetStatus(id, status string)
SetStatus changes the status of intent id.
func (*FakeStripe) Status ¶
func (f *FakeStripe) Status(id string) string
Status reports the status of intent id.
func (*FakeStripe) Webhooks ¶
func (f *FakeStripe) Webhooks() map[string]string
Webhooks maps each registered endpoint id to its URL.
type Harness ¶
type Harness struct {
DB *gorm.DB
Redis *redis.Client
Store *repository.GormStore
// contains filtered or unexported fields
}
Harness is a real repository store over a private in-memory database.
func New ¶
New opens a fresh database with the billing tables and the subscription (plans, user subscriptions, entitlement periods), identity and platform tables the order flows touch.
func (*Harness) BalanceLogs ¶
BalanceLogs decodes the balance ledger of userID.
func (*Harness) Payment ¶
func (h *Harness) Payment(platform, config string, adjust ...func(*payment.Payment)) *payment.Payment
Payment seeds an enabled payment method of platform with a configuration.
func (*Harness) ReloadCoupon ¶
ReloadCoupon reads the coupon back.
func (*Harness) ReloadOrder ¶
ReloadOrder reads the order back from the database.
func (*Harness) ReloadPlan ¶
ReloadPlan reads the plan back.
func (*Harness) ReloadWallet ¶
ReloadWallet reads the wallet of userID; a missing row reads as zero.
type Queue ¶
Queue records the order lifecycle tasks the flows schedule.