Documentation
¶
Index ¶
- Constants
- Variables
- type Adapter
- type App
- func (a App) DeleteCustomerData(ctx context.Context, input app.DeleteAppInstanceCustomerDataInput) error
- func (a App) DeleteStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) error
- func (a App) FinalizeStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) (*billing.FinalizeStandardInvoiceResult, error)
- func (a App) GetCustomerData(ctx context.Context, input app.GetAppInstanceCustomerDataInput) (app.CustomerData, error)
- func (a App) GetEventAppData() (app.EventAppData, error)
- func (a App) UpdateAppConfig(ctx context.Context, input app.AppConfigUpdate) error
- func (a App) UpsertCustomerData(ctx context.Context, input app.UpsertAppInstanceCustomerDataInput) error
- func (a App) UpsertStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) (*billing.UpsertStandardInvoiceResult, error)
- func (a App) Validate() error
- func (a App) ValidateCustomer(ctx context.Context, customer *customer.Customer, ...) error
- func (a App) ValidateCustomerByID(ctx context.Context, customerID customer.CustomerID, ...) error
- func (a App) ValidateStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) error
- type AppBase
- type AppCheckoutSessionEvent
- type AppData
- type AppFactoryService
- type AppStripeAdapter
- type BillingService
- type Configuration
- type CreateAppStripeInput
- type CreateCheckoutSessionInput
- type CreateCheckoutSessionOutput
- type CreateStripeCustomerInput
- type CreateStripeCustomerOutput
- type CreateStripePortalSessionInput
- type CustomerData
- type CustomerService
- type DeleteStripeAppDataInput
- type DeleteStripeCustomerDataInput
- type GetAppInput
- type GetStripeAppDataInput
- type GetStripeCustomerDataInput
- type GetStripeInvoiceInput
- type GetSupplierContactInput
- type GetWebhookSecretInput
- type GetWebhookSecretOutput
- type HandleInvoiceSentEventInput
- type HandleInvoiceStateTransitionInput
- type HandleSetupIntentSucceededInput
- type HandleSetupIntentSucceededOutput
- type Meta
- type Service
- type SetCustomerDefaultPaymentMethodInput
- type SetCustomerDefaultPaymentMethodOutput
- type StripeAppService
- type StripeCalculator
- func (c StripeCalculator) FormatAmount(amount alpacadecimal.Decimal) string
- func (c StripeCalculator) FormatQuantity(quantity alpacadecimal.Decimal) string
- func (c StripeCalculator) IsInteger(amount alpacadecimal.Decimal) bool
- func (c StripeCalculator) RoundToAmount(amount alpacadecimal.Decimal) int64
- type StripeInvoiceLineOperationParams
- type StripePortalSession
- type UpdateAPIKeyAdapterInput
- type UpdateAPIKeyInput
- type UpsertStripeCustomerDataInput
- type ValidationErrorsInput
Constants ¶
const ( AppEventSubsystem metadata.EventSubsystem = "app.stripe" AppCheckoutSessionEventName metadata.EventName = "app.stripe.checkout_session.created" )
const ( APIKeySecretKey = "stripe_api_key" WebhookSecretKey = "stripe_webhook_secret" )
Variables ¶
var ( StripeMarketplaceListing = app.MarketplaceListing{ Type: app.AppTypeStripe, Name: "Stripe", Description: "Send invoices, calculate tax and collect payments.", Capabilities: []app.Capability{ StripeCollectPaymentCapability, StripeCalculateTaxCapability, StripeInvoiceCustomerCapability, }, InstallMethods: []app.InstallMethod{ app.InstallMethodAPIKey, }, } StripeCollectPaymentCapability = app.Capability{ Type: app.CapabilityTypeCollectPayments, Key: "stripe_collect_payment", Name: "Payment", Description: "Process payments", } StripeCalculateTaxCapability = app.Capability{ Type: app.CapabilityTypeCalculateTax, Key: "stripe_calculate_tax", Name: "Calculate Tax", Description: "Calculate tax for a payment", } StripeInvoiceCustomerCapability = app.Capability{ Type: app.CapabilityTypeInvoiceCustomers, Key: "stripe_invoice_customer", Name: "Invoice Customer", Description: "Invoice a customer", } )
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter interface {
AppStripeAdapter
entutils.TxCreator
}
type App ¶
type App struct {
Meta
Logger *slog.Logger `json:"-"`
AppService app.Service `json:"-"`
BillingService billing.Service `json:"-"`
StripeAppClientFactory stripeclient.StripeAppClientFactory `json:"-"`
StripeAppService Service `json:"-"`
SecretService secret.Service `json:"-"`
}
App represents an installed Stripe app
func (App) DeleteCustomerData ¶
func (a App) DeleteCustomerData(ctx context.Context, input app.DeleteAppInstanceCustomerDataInput) error
DeleteCustomerData deletes the customer data for the app
func (App) DeleteStandardInvoice ¶
DeleteStandardInvoice deletes the invoice for the app
func (App) FinalizeStandardInvoice ¶
func (a App) FinalizeStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) (*billing.FinalizeStandardInvoiceResult, error)
FinalizeStandardInvoice finalizes the invoice for the app
func (App) GetCustomerData ¶
func (a App) GetCustomerData(ctx context.Context, input app.GetAppInstanceCustomerDataInput) (app.CustomerData, error)
GetCustomerData gets the customer data for the app
func (App) GetEventAppData ¶
func (a App) GetEventAppData() (app.EventAppData, error)
func (App) UpdateAppConfig ¶
func (App) UpsertCustomerData ¶
func (a App) UpsertCustomerData(ctx context.Context, input app.UpsertAppInstanceCustomerDataInput) error
UpsertCustomerData upserts the customer data for the app
func (App) UpsertStandardInvoice ¶
func (a App) UpsertStandardInvoice(ctx context.Context, invoice billing.StandardInvoice) (*billing.UpsertStandardInvoiceResult, error)
UpsertStandardInvoice upserts the invoice for the app Upsert is idempotent and can be used to create or update an invoice. In case of failure the upsert should be retried.
TODO: should we split invoice create and lines adds to make retries more robust? Currently if the create fails between the create and add lines we can end up with an invoice without lines.
func (App) ValidateCustomer ¶
func (a App) ValidateCustomer(ctx context.Context, customer *customer.Customer, capabilities []app.CapabilityType) error
ValidateCustomer validates if the app can run for the given customer
func (App) ValidateCustomerByID ¶
func (a App) ValidateCustomerByID(ctx context.Context, customerID customer.CustomerID, capabilities []app.CapabilityType) error
ValidateCustomerByID validates if the app can run for the given customer ID
func (App) ValidateStandardInvoice ¶
ValidateStandardInvoice validates the invoice for the app
type AppCheckoutSessionEvent ¶
type AppCheckoutSessionEvent struct {
SessionID string `json:"sessionId"`
Namespace string `json:"namespace"`
AppID string `json:"appId"`
CustomerID string `json:"customerId"`
UserID *string `json:"userId,omitempty"`
}
AppCheckoutSessionEvent is an event that is emitted when a checkout session is created
func NewAppCheckoutSessionEvent ¶
func NewAppCheckoutSessionEvent(ctx context.Context, namespace string, sessionID string, appID string, customerID string) AppCheckoutSessionEvent
NewAppCheckoutSessionEvent creates a new checkout session event
func (AppCheckoutSessionEvent) EventMetadata ¶
func (e AppCheckoutSessionEvent) EventMetadata() metadata.EventMetadata
func (AppCheckoutSessionEvent) EventName ¶
func (e AppCheckoutSessionEvent) EventName() string
func (AppCheckoutSessionEvent) Validate ¶
func (e AppCheckoutSessionEvent) Validate() error
type AppData ¶
type AppData struct {
StripeAccountID string `json:"stripeAccountId"`
Livemode bool `json:"livemode"`
APIKey secretentity.SecretID `json:"-"`
MaskedAPIKey string `json:"maskedApiKey"`
StripeWebhookID string `json:"stripeWebhookId"`
WebhookSecret secretentity.SecretID `json:"-"`
}
AppData represents the Stripe associated data for the app
type AppFactoryService ¶
type AppFactoryService interface {
// App Factory methods
NewApp(ctx context.Context, appBase app.AppBase) (app.App, error)
InstallAppWithAPIKey(ctx context.Context, input app.AppFactoryInstallAppWithAPIKeyInput) (app.App, error)
UninstallApp(ctx context.Context, input app.UninstallAppInput) error
}
AppFactoryService contains methods to interface with app subsystem
type AppStripeAdapter ¶
type AppStripeAdapter interface {
GetStripeClientFactory() client.StripeClientFactory
GetStripeAppClientFactory() client.StripeAppClientFactory
UpdateAPIKey(ctx context.Context, input UpdateAPIKeyAdapterInput) error
CreateCheckoutSession(ctx context.Context, input CreateCheckoutSessionInput) (CreateCheckoutSessionOutput, error)
GetWebhookSecret(ctx context.Context, input GetWebhookSecretInput) (GetWebhookSecretOutput, error)
// App
CreateStripeApp(ctx context.Context, input CreateAppStripeInput) (AppBase, error)
GetStripeAppData(ctx context.Context, input GetStripeAppDataInput) (AppData, error)
DeleteStripeAppData(ctx context.Context, input DeleteStripeAppDataInput) error
// Billing
GetSupplierContact(ctx context.Context, input GetSupplierContactInput) (billing.SupplierContact, error)
GetStripeInvoice(ctx context.Context, input GetStripeInvoiceInput) (*stripe.Invoice, error)
// Customer
GetStripeCustomerData(ctx context.Context, input GetStripeCustomerDataInput) (CustomerData, error)
UpsertStripeCustomerData(ctx context.Context, input UpsertStripeCustomerDataInput) error
DeleteStripeCustomerData(ctx context.Context, input DeleteStripeCustomerDataInput) error
SetCustomerDefaultPaymentMethod(ctx context.Context, input SetCustomerDefaultPaymentMethodInput) (SetCustomerDefaultPaymentMethodOutput, error)
// Portal
CreatePortalSession(ctx context.Context, input CreateStripePortalSessionInput) (StripePortalSession, error)
}
type BillingService ¶
type BillingService interface {
GetSupplierContact(ctx context.Context, input GetSupplierContactInput) (billing.SupplierContact, error)
// Invoice webhook handlers
HandleInvoiceStateTransition(ctx context.Context, input HandleInvoiceStateTransitionInput) error
HandleInvoiceSentEvent(ctx context.Context, input HandleInvoiceSentEventInput) error
}
BillingService contains methods for managing billing subsystem (invoices)
type Configuration ¶
type Configuration struct {
SecretAPIKey *string
}
func (Configuration) Validate ¶
func (c Configuration) Validate() error
type CreateAppStripeInput ¶
type CreateAppStripeInput struct {
app.CreateAppInput
StripeAccountID string
Livemode bool
APIKey secretentity.SecretID
MaskedAPIKey string
StripeWebhookID string
WebhookSecret secretentity.SecretID
}
func (CreateAppStripeInput) Validate ¶
func (i CreateAppStripeInput) Validate() error
type CreateCheckoutSessionInput ¶
type CreateCheckoutSessionInput struct {
Namespace string
AppID app.AppID
CreateCustomerInput *customer.CreateCustomerInput
CustomerID *customer.CustomerID
StripeCustomerID *string
Options api.CreateStripeCheckoutSessionRequestOptions
}
func (CreateCheckoutSessionInput) Validate ¶
func (i CreateCheckoutSessionInput) Validate() error
type CreateCheckoutSessionOutput ¶
type CreateCheckoutSessionOutput struct {
AppID app.AppID
CustomerID customer.CustomerID
StripeCustomerID string
client.StripeCheckoutSession
}
func (CreateCheckoutSessionOutput) Validate ¶
func (o CreateCheckoutSessionOutput) Validate() error
type CreateStripeCustomerInput ¶
type CreateStripeCustomerInput struct {
AppID app.AppID
CustomerID customer.CustomerID
Name *string
Email *string
}
func (CreateStripeCustomerInput) Validate ¶
func (i CreateStripeCustomerInput) Validate() error
type CreateStripeCustomerOutput ¶
type CreateStripeCustomerOutput struct {
StripeCustomerID string
}
func (CreateStripeCustomerOutput) Validate ¶
func (o CreateStripeCustomerOutput) Validate() error
type CreateStripePortalSessionInput ¶
type CreateStripePortalSessionInput struct {
AppID app.AppID
CustomerID customer.CustomerID
Locale *string
ConfigurationID *string
ReturnURL *string
}
CreateStripePortalSessionInput is the input for creating a stripe customer portal session.
func (CreateStripePortalSessionInput) Validate ¶
func (i CreateStripePortalSessionInput) Validate() error
Validate validates the input for creating a stripe customer portal session.
type CustomerData ¶
func (CustomerData) Validate ¶
func (d CustomerData) Validate() error
type CustomerService ¶
type CustomerService interface {
GetStripeCustomerData(ctx context.Context, input GetStripeCustomerDataInput) (CustomerData, error)
UpsertStripeCustomerData(ctx context.Context, input UpsertStripeCustomerDataInput) error
DeleteStripeCustomerData(ctx context.Context, input DeleteStripeCustomerDataInput) error
HandleSetupIntentSucceeded(ctx context.Context, input HandleSetupIntentSucceededInput) (HandleSetupIntentSucceededOutput, error)
CreateCheckoutSession(ctx context.Context, input CreateCheckoutSessionInput) (CreateCheckoutSessionOutput, error)
CreatePortalSession(ctx context.Context, input CreateStripePortalSessionInput) (StripePortalSession, error)
}
CustomerService contains methods for managing customer data
type DeleteStripeAppDataInput ¶
func (DeleteStripeAppDataInput) Validate ¶
func (i DeleteStripeAppDataInput) Validate() error
type DeleteStripeCustomerDataInput ¶
type DeleteStripeCustomerDataInput struct {
AppID *app.AppID
CustomerID *customer.CustomerID
}
func (DeleteStripeCustomerDataInput) Validate ¶
func (i DeleteStripeCustomerDataInput) Validate() error
type GetAppInput ¶
type GetStripeAppDataInput ¶
func (GetStripeAppDataInput) Validate ¶
func (i GetStripeAppDataInput) Validate() error
type GetStripeCustomerDataInput ¶
type GetStripeCustomerDataInput struct {
AppID app.AppID
CustomerID customer.CustomerID
}
func (GetStripeCustomerDataInput) Validate ¶
func (i GetStripeCustomerDataInput) Validate() error
type GetStripeInvoiceInput ¶
func (GetStripeInvoiceInput) Validate ¶
func (i GetStripeInvoiceInput) Validate() error
type GetSupplierContactInput ¶
GetSupplierContactInput to get the default supplier
func (GetSupplierContactInput) Validate ¶
func (i GetSupplierContactInput) Validate() error
type GetWebhookSecretInput ¶
type GetWebhookSecretInput struct {
AppID string
}
func (GetWebhookSecretInput) Validate ¶
func (i GetWebhookSecretInput) Validate() error
type GetWebhookSecretOutput ¶
type GetWebhookSecretOutput = secretentity.Secret
type HandleInvoiceSentEventInput ¶
func (HandleInvoiceSentEventInput) Validate ¶
func (i HandleInvoiceSentEventInput) Validate() error
type HandleInvoiceStateTransitionInput ¶
type HandleInvoiceStateTransitionInput struct {
AppID app.AppID
Invoice stripe.Invoice
// Trigger is the state machine trigger that will be used to transition the invoice
Trigger billing.InvoiceTrigger
// TargetStatus specifies the expected status of the invoice after the transition, needed to filter
// for duplicate events as the state machine doesn't allow transition into the same state
TargetStatuses []billing.StandardInvoiceStatus
// IgnoreInvoiceInStatus is a list of invoice statuses. If the invoice is in this status we ignore the event
// this allows to filter for out of order events.
IgnoreInvoiceInStatus []billing.StandardInvoiceStatusMatcher
// ShouldTriggerOnEvent gets the *current* stripe invoice and returns true if the state machine should be triggered
// useful for filtering late events based on the current state (optional)
ShouldTriggerOnEvent func(*stripe.Invoice) (bool, error)
// Validation errors
// GetValidationErrors is invoked with the current stripe invoice and returns the validation errors if any
GetValidationErrors func(*stripe.Invoice) (*ValidationErrorsInput, error)
}
func (HandleInvoiceStateTransitionInput) Validate ¶
func (i HandleInvoiceStateTransitionInput) Validate() error
type HandleSetupIntentSucceededInput ¶
type HandleSetupIntentSucceededInput struct {
SetCustomerDefaultPaymentMethodInput
PaymentIntentMetadata map[string]string
}
func (HandleSetupIntentSucceededInput) Validate ¶
func (i HandleSetupIntentSucceededInput) Validate() error
type HandleSetupIntentSucceededOutput ¶
type HandleSetupIntentSucceededOutput struct {
CustomerID customer.CustomerID
}
type Service ¶
type Service interface {
AppFactoryService
StripeAppService
CustomerService
BillingService
}
type SetCustomerDefaultPaymentMethodInput ¶
type SetCustomerDefaultPaymentMethodInput struct {
AppID app.AppID
StripeCustomerID string
PaymentMethodID string
}
func (SetCustomerDefaultPaymentMethodInput) Validate ¶
func (i SetCustomerDefaultPaymentMethodInput) Validate() error
type SetCustomerDefaultPaymentMethodOutput ¶
type SetCustomerDefaultPaymentMethodOutput struct {
CustomerID customer.CustomerID
}
type StripeAppService ¶
type StripeAppService interface {
UpdateAPIKey(ctx context.Context, input UpdateAPIKeyInput) error
GetStripeAppData(ctx context.Context, input GetStripeAppDataInput) (AppData, error)
GetWebhookSecret(ctx context.Context, input GetWebhookSecretInput) (GetWebhookSecretOutput, error)
}
StripeAppService contains methods for managing stripe app
type StripeCalculator ¶
type StripeCalculator struct {
// contains filtered or unexported fields
}
StripeCalculator provides a currency calculator object.
func NewStripeCalculator ¶
func NewStripeCalculator(currency currencyx.Code) (StripeCalculator, error)
NewStripeCalculator creates a new StripeCalculator.
func (StripeCalculator) FormatAmount ¶
func (c StripeCalculator) FormatAmount(amount alpacadecimal.Decimal) string
FormatAmount formats the amount
func (StripeCalculator) FormatQuantity ¶
func (c StripeCalculator) FormatQuantity(quantity alpacadecimal.Decimal) string
FormatQuantity formats the quantity to two decimal places. This should be only used to display the quantity not for calculations.
func (StripeCalculator) IsInteger ¶
func (c StripeCalculator) IsInteger(amount alpacadecimal.Decimal) bool
IsInteger checks if the amount is an integer in the Stripe currency.
func (StripeCalculator) RoundToAmount ¶
func (c StripeCalculator) RoundToAmount(amount alpacadecimal.Decimal) int64
RoundToAmount rounds the amount to the precision of the Stripe currency in Stripe amount.
type StripeInvoiceLineOperationParams ¶
type StripeInvoiceLineOperationParams interface {
stripe.InvoiceItemParams | stripeclient.StripeInvoiceItemWithID
}
type StripePortalSession ¶
type StripePortalSession struct {
// The ID of the customer portal session.
// See: https://docs.stripe.com/api/customer_portal/sessions/object#portal_session_object-id
ID string
// Configuration Configuration used to customize the customer portal.
// See: https://docs.stripe.com/api/customer_portal/sessions/object#portal_session_object-configuration
Configuration *stripe.BillingPortalConfiguration
CreatedAt time.Time
StripeCustomerID string
// Livemode Livemode.
Livemode bool
// Locale Status.
// The IETF language tag of the locale customer portal is displayed in.
// See: https://docs.stripe.com/api/customer_portal/sessions/object#portal_session_object-locale
Locale string
// ReturnUrl Return URL.
// See: https://docs.stripe.com/api/customer_portal/sessions/object#portal_session_object-return_url
ReturnURL string
// The URL to redirect the customer to after they have completed
// their requested actions.
URL string
}
StripePortalSession is the response from the Stripe API for a customer portal session.
type UpdateAPIKeyAdapterInput ¶
type UpdateAPIKeyAdapterInput struct {
UpdateAPIKeyInput
MaskedAPIKey string
}
func (UpdateAPIKeyAdapterInput) Validate ¶
func (i UpdateAPIKeyAdapterInput) Validate() error
type UpdateAPIKeyInput ¶
func (UpdateAPIKeyInput) Validate ¶
func (i UpdateAPIKeyInput) Validate() error
type UpsertStripeCustomerDataInput ¶
type UpsertStripeCustomerDataInput struct {
AppID app.AppID
CustomerID customer.CustomerID
StripeCustomerID string
StripeDefaultPaymentMethodID *string
}
func (UpsertStripeCustomerDataInput) Validate ¶
func (i UpsertStripeCustomerDataInput) Validate() error
type ValidationErrorsInput ¶
type ValidationErrorsInput struct {
Op billing.StandardInvoiceOperation
Errors []*stripe.Error
}