Documentation
¶
Overview ¶
Package billing holds pricing rules and billing settings (docs/billing.md). Money is always an integer in the currency's smallest unit (IDR has none: 1 = Rp1).
Index ¶
- Variables
- func Format(amount int64, currency string) string
- func NextDue(t time.Time, cycle string) time.Time
- func PrevDue(next time.Time, cycle string) time.Time
- func Prorate(oldAmount, newAmount int64, start, end, now time.Time) int64
- type Coupon
- type InvoiceDetails
- type Option
- type PayPalSettings
- type Plan
- type Quote
- type Settings
- type StripeSettings
Constants ¶
This section is empty.
Variables ¶
var CycleMonths = map[string]int{"monthly": 1, "quarterly": 3, "semiannually": 6, "yearly": 12, "biennially": 24, "triennially": 36}
CycleMonths is the length of a cycle.
var Cycles = []string{"monthly", "quarterly", "yearly"}
Cycles a customer can pay for. Cycles are offered in the store; CycleMonths also knows the longer cycles imported subscriptions may use.
var PayPalCurrencies = map[string]bool{ "USD": true, "EUR": true, "GBP": true, "AUD": true, "CAD": true, "SGD": true, "JPY": true, "MYR": true, "PHP": true, "THB": true, "HKD": true, "NZD": true, "CHF": true, }
PayPalCurrencies are the currencies PayPal accepts (IDR is not one of them).
ZeroDecimal currencies have no minor unit in Ammonode's amounts (amount 1 = one whole unit).
Functions ¶
func NextDue ¶
NextDue adds one cycle to t (calendar months, so the 31st becomes the last day of short months).
Types ¶
type Coupon ¶
type Coupon struct {
Kind string // percent | fixed
Value int64 // 1-100 for percent, an amount for fixed
Recurring bool // also applies to every renewal
}
Coupon is a discount code.
type InvoiceDetails ¶
type InvoiceDetails struct {
CompanyName string `json:"company_name"`
Address string `json:"address"` // multi-line
TaxID string `json:"tax_id"`
}
InvoiceDetails is the seller block and footer printed on invoices.
type PayPalSettings ¶
type PayPalSettings struct {
Enabled bool `json:"enabled"`
ClientID string `json:"client_id"`
Secret string `json:"secret"`
Sandbox bool `json:"sandbox"`
WebhookID string `json:"webhook_id"`
}
PayPalSettings configures PayPal Checkout (Orders v2).
type Quote ¶
type Quote struct {
Recurring int64 `json:"recurring"` // per cycle (after a recurring coupon)
SetupFee int64 `json:"setup_fee"`
FirstTotal int64 `json:"first_total"` // first invoice, after the coupon
Discount int64 `json:"discount"` // coupon discount on the first invoice
MemoryMB int `json:"memory_mb"`
CPUPercent int `json:"cpu_percent"`
DiskMB int `json:"disk_mb"`
}
Quote is the price and resources of a configuration for a cycle.
func ApplyCoupon ¶
ApplyCoupon discounts the cycle price (not the setup fee) on the first invoice, and on renewals too when the coupon is recurring.
type Settings ¶
type Settings struct {
Currency string `json:"currency"`
Discounts map[string]int `json:"discounts"` // cycle -> percent off
RenewDaysBefore int `json:"renew_days_before"`
SuspendAfterDays int `json:"suspend_after_days"`
TerminateAfterDays int `json:"terminate_after_days"`
AllowRegistration bool `json:"allow_registration"`
Stripe StripeSettings `json:"stripe"`
PayPal PayPalSettings `json:"paypal"`
Invoice InvoiceDetails `json:"invoice"`
}
Settings are the panel's billing settings (stored as JSON under the "billing" key).
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings are used until an admin saves their own.
type StripeSettings ¶
type StripeSettings struct {
Enabled bool `json:"enabled"`
SecretKey string `json:"secret_key"`
WebhookSecret string `json:"webhook_secret"`
}
StripeSettings configures Stripe Checkout.