Documentation
¶
Index ¶
- Constants
- func CallbackBase(configured string, r *http.Request) string
- func NormalizeStatus(raw string) string
- func ParsePluginPayload(result interface{}) (map[string]interface{}, error)
- func RedirectURL(tx *models.PaymentTransaction) string
- func RenderResultPage(tx *models.PaymentTransaction) string
- func ReturnLink(tx *models.PaymentTransaction) string
- func SetOnSettled(fn SettledFunc)
- func WantsResultHTML(accept string) bool
- type CheckoutInput
- type CheckoutRequest
- type ExecFunc
- type NormalizedResult
- type Service
- func (s *Service) ApplyVerification(ctx context.Context, tx *models.PaymentTransaction, result NormalizedResult) (*models.PaymentTransaction, error)
- func (s *Service) BeginCheckout(ctx context.Context, in CheckoutInput) (*models.PaymentTransaction, error)
- func (s *Service) IngestProviderEvent(ctx context.Context, projectID, providerID string, raw map[string]interface{}) (*models.PaymentTransaction, error)
- func (s *Service) Verify(ctx context.Context, tx *models.PaymentTransaction, raw map[string]interface{}) (*models.PaymentTransaction, error)
- type SettledFunc
Constants ¶
const ( StatusCreated = "created" StatusPending = "pending" StatusSucceeded = "succeeded" StatusFailed = "failed" StatusCanceled = "canceled" StatusExpired = "expired" )
const PaymentReturnExtraKey = "payment_return_url"
PaymentReturnExtraKey is the client_runtime extra that holds the app return URL.
Variables ¶
This section is empty.
Functions ¶
func CallbackBase ¶
CallbackBase is the origin EPS and Stripe send the browser back to. A configured PUBLIC_API_URL wins. Otherwise the origin is the API host the client already called.
func NormalizeStatus ¶
NormalizeStatus maps provider words onto the ledger state machine.
func ParsePluginPayload ¶
ParsePluginPayload accepts a plugin Execute result and returns a map.
func RedirectURL ¶
func RedirectURL(tx *models.PaymentTransaction) string
RedirectURL reads the redirect saved on the transaction metadata.
func RenderResultPage ¶
func RenderResultPage(tx *models.PaymentTransaction) string
RenderResultPage shows the ledger status. It does not call a plugin.
func ReturnLink ¶
func ReturnLink(tx *models.PaymentTransaction) string
ReturnLink is the stored app URL with transaction_id and status appended. A missing or rejected URL returns empty. The result page omits the button.
func SetOnSettled ¶
func SetOnSettled(fn SettledFunc)
SetOnSettled registers the process-wide fulfillment hook. Pro uses this to apply tenant plans without the open-core package importing Pro.
func WantsResultHTML ¶
WantsResultHTML is true when the caller prefers text/html over application/json. An empty Accept header stays JSON. Webhooks do not use this.
Types ¶
type CheckoutInput ¶
type CheckoutInput struct {
ProjectID string
UserID string
CustomerRef string
Provider string
Flow string
ProductKey string
ExpectedAmount string
Currency string
IdempotencyKey string
MetadataJSON string
// ClientPlatform is android, ios, or web. ReturnURL is copied from the
// project client runtime by the caller. Neither value is sent to the plugin.
ClientPlatform string
ReturnURL string
}
CheckoutInput starts a hosted payment. Amount is server-derived. Clients do not supply it.
type CheckoutRequest ¶
type CheckoutRequest struct {
TransactionID string
ClientReference string
Flow string
ProductKey string
ServerAmount string
ServerCurrency string
SuccessURL string
FailURL string
CancelURL string
ProjectID string
CustomerRef string
}
CheckoutRequest is what the host sends to a plugin initialize operation.
func (CheckoutRequest) Args ¶
func (r CheckoutRequest) Args() map[string]interface{}
type ExecFunc ¶
type ExecFunc func(ctx context.Context, pluginID, operation string, args map[string]interface{}, reconcile bool) (map[string]interface{}, error)
ExecFunc runs one declared plugin operation. reconcile=true skips project-activation refusal so an already created transaction can still be verified.
type NormalizedResult ¶
type NormalizedResult struct {
Status string
ProviderStatus string
Amount string
Currency string
ProviderSessionID string
ProviderPaymentID string
ProviderSubscriptionID string
ProviderCustomerID string
SubscriptionStatus string
CurrentPeriodStart string
CurrentPeriodEnd string
CancelAtPeriodEnd bool
EventID string
FinancialEntity string
TransactionDate string
ErrorCode string
ErrorMessage string
ClientReference string
TransactionID string
}
NormalizedResult is the provider-neutral verify/webhook envelope.
func ResultFromMap ¶
func ResultFromMap(payload map[string]interface{}, requireStatus bool) (NormalizedResult, error)
ResultFromMap reads a normalized envelope. Unknown status is an error when required.
type Service ¶
type Service struct {
Store interfaces.PaymentStore
Exec ExecFunc
PublicAPIURL string
Now func() time.Time
OnSettled SettledFunc
}
Service is the provider-neutral hosted checkout orchestrator.
func (*Service) ApplyVerification ¶
func (s *Service) ApplyVerification(ctx context.Context, tx *models.PaymentTransaction, result NormalizedResult) (*models.PaymentTransaction, error)
ApplyVerification settles one transaction from a plugin verify/webhook result.
func (*Service) BeginCheckout ¶
func (s *Service) BeginCheckout(ctx context.Context, in CheckoutInput) (*models.PaymentTransaction, error)
BeginCheckout persists a row before the plugin talks to the provider.
func (*Service) IngestProviderEvent ¶
func (s *Service) IngestProviderEvent(ctx context.Context, projectID, providerID string, raw map[string]interface{}) (*models.PaymentTransaction, error)
IngestProviderEvent verifies a provider webhook that does not carry the merchant reference in the URL.
type SettledFunc ¶
type SettledFunc func(ctx context.Context, before, after *models.PaymentTransaction) error
SettledFunc runs after a durable status change. Hook failure must not roll back provider success; the caller retries fulfillment separately. A non-nil error is returned to the webhook so the provider can retry when the event id was not recorded yet.