Documentation
¶
Index ¶
- Variables
- func ApplyTax(conf ini.File, inv *model.Invoice, addr *model.BillingAddress)
- func ChargeRenewalPayment(ctx context.Context, sub *model.BillingSubscription, ...) (model.PaymentIntent, error)
- func CreatePaymentIntent(ctx context.Context, sub *model.BillingSubscription, ...) (model.PaymentIntent, error)
- func CreateSetupIntent(ctx context.Context, sub *model.BillingSubscription) (model.SetupIntent, error)
- func DeletePaymentMethod(ctx context.Context, method *model.PaymentMethod) error
- func DownloadInvoice(ctx context.Context, invoice *model.Invoice) (io.ReadCloser, error)
- func FinalizeCancellation(ctx context.Context, tx *sql.Tx, user *model.User, ...) error
- func ForContext(ctx context.Context, currency model.Currency) *client.API
- func GenerateInvoice(ctx context.Context, w io.Writer, invoice *model.Invoice) error
- func Get(conf ini.File, currency model.Currency, key string) (string, bool)
- func GetPaymentIntent(ctx context.Context, sub *model.BillingSubscription) (model.PaymentIntent, error)
- func GetSetupIntent(ctx context.Context, sub *model.BillingSubscription, intentID string) (model.SetupIntent, error)
- func Init(conf ini.File)
- func InvoiceFor(ctx context.Context, sub *model.BillingSubscription, ...) (*model.Invoice, error)
- func IsEnabled(conf ini.File) bool
- func IsProhibitedCountry(ctx context.Context, c country.Country) bool
- func Middleware(conf ini.File) func(next http.Handler) http.Handler
- func RequireEnabled(ctx context.Context) error
- func UpdateCustomerEmail(ctx context.Context, user *model.User) error
- func UploadInvoice(ctx context.Context, invoice *model.Invoice) error
- func ValidateSubscription(ctx context.Context, tx *sql.Tx, user *model.User, ...) error
- type TemplateContext
- type TemplateDiscount
- type TemplateProduct
Constants ¶
This section is empty.
Variables ¶
var (
ErrCancelled = fmt.Errorf("billing subscription cancelled")
)
var TaxRateCountry = map[string]decimal.Decimal{ "AT": decimal.RequireFromString("20"), "BE": decimal.RequireFromString("21"), "BG": decimal.RequireFromString("20"), "CY": decimal.RequireFromString("19"), "CZ": decimal.RequireFromString("21"), "DE": decimal.RequireFromString("19"), "DK": decimal.RequireFromString("25"), "EE": decimal.RequireFromString("22"), "EL": decimal.RequireFromString("24"), "ES": decimal.RequireFromString("21"), "FI": decimal.RequireFromString("22.5"), "FR": decimal.RequireFromString("20"), "HR": decimal.RequireFromString("25"), "HU": decimal.RequireFromString("27"), "IE": decimal.RequireFromString("23"), "IT": decimal.RequireFromString("22"), "LT": decimal.RequireFromString("21"), "LU": decimal.RequireFromString("17"), "LV": decimal.RequireFromString("21"), "MT": decimal.RequireFromString("18"), "NL": decimal.RequireFromString("21"), "PL": decimal.RequireFromString("23"), "PT": decimal.RequireFromString("23"), "RO": decimal.RequireFromString("19"), "SE": decimal.RequireFromString("25"), "SI": decimal.RequireFromString("22"), "SK": decimal.RequireFromString("23"), }
Functions ¶
func ChargeRenewalPayment ¶
func ChargeRenewalPayment( ctx context.Context, sub *model.BillingSubscription, addr *model.BillingAddress, method *model.PaymentMethod, ) (model.PaymentIntent, error)
Creates and immediately confirms an off-session (i.e. non-interactive) Stripe payment intent to charge the user's subscription renewal fee.
func CreatePaymentIntent ¶
func CreatePaymentIntent( ctx context.Context, sub *model.BillingSubscription, addr *model.BillingAddress, idempotencyKey *string, ) (model.PaymentIntent, error)
Creates an on-session Stripe payment intent (i.e. one the user will pay for interactively) for the given billing subscription.
func CreateSetupIntent ¶
func CreateSetupIntent( ctx context.Context, sub *model.BillingSubscription, ) (model.SetupIntent, error)
func DeletePaymentMethod ¶
func DeletePaymentMethod( ctx context.Context, method *model.PaymentMethod, ) error
Removes a payment method from a customer's account at the payment processor.
func DownloadInvoice ¶
func FinalizeCancellation ¶
func FinalizeCancellation( ctx context.Context, tx *sql.Tx, user *model.User, sub *model.BillingSubscription, ) error
Finalizes a cancelled subscription whose service term is completed by setting the user to a non-paying account.
The subscription may be nil to convert a subsidized user to non-paying.
func ForContext ¶
Returns the Stripe client associated with a currency on this context.
func GenerateInvoice ¶
Generates a PDF from a model.Invoice.
func Get ¶
Retrieves an item from the billing configuration. Uses a currency-specific config option if relevant, or falls back to the general billing configuration if not.
func GetPaymentIntent ¶
func GetPaymentIntent( ctx context.Context, sub *model.BillingSubscription, ) (model.PaymentIntent, error)
Retrieves a payment intent from its ID.
func GetSetupIntent ¶
func GetSetupIntent( ctx context.Context, sub *model.BillingSubscription, intentID string, ) (model.SetupIntent, error)
func InvoiceFor ¶
func InvoiceFor( ctx context.Context, sub *model.BillingSubscription, addr *model.BillingAddress, ) (*model.Invoice, error)
Calculates the payment details for a given billing subscription and returns an incomplete invoice record with all of the monetary values set accordingly (e.g. tax rate), to facilitate calculating the amount to charge the user.
func IsProhibitedCountry ¶
Returns true if the given country code is not allowed to receive paid services.
func RequireEnabled ¶
Returns an error if billing is not enabled in this configuration.
func UpdateCustomerEmail ¶
Updates the email address on record at payment processor for each of this user's customer accounts.
Returns `nil` if success. Returns a error message if contains failure.
func UploadInvoice ¶
Uploads an invoice to S3.
func ValidateSubscription ¶
func ValidateSubscription( ctx context.Context, tx *sql.Tx, user *model.User, sub *model.BillingSubscription, intent model.PaymentIntent, ) error
Validate a subscription after a payment intent has been processed to update the subscription based on the payment outcome, issuing an invoice/receipt and setting the user payment status appropriately, etc.
Types ¶
type TemplateContext ¶
type TemplateContext struct {
Invoice *model.Invoice
User *model.User
Address *model.BillingAddress
Products []TemplateProduct
Discounts []TemplateDiscount
Sample bool
}