payment

package
v1.9.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: AGPL-3.0 Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	StatusCreated   = "created"
	StatusPending   = "pending"
	StatusSucceeded = "succeeded"
	StatusFailed    = "failed"
	StatusCanceled  = "canceled"
	StatusExpired   = "expired"
)
View Source
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

func CallbackBase(configured string, r *http.Request) string

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

func NormalizeStatus(raw string) string

NormalizeStatus maps provider words onto the ledger state machine.

func ParsePluginPayload

func ParsePluginPayload(result interface{}) (map[string]interface{}, error)

ParsePluginPayload accepts a plugin Execute result and returns a map.

func ProviderBrowserURL added in v1.9.12

func ProviderBrowserURL(raw string) string

ProviderBrowserURL is a provider redirect the shopper's browser may open.

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(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 ReviewArgs added in v1.9.12

func ReviewArgs(tx *models.PaymentTransaction, notice string) map[string]interface{}

ReviewArgs is the public checkout page request. It never includes the shop return URL.

func ReviewURL added in v1.9.12

func ReviewURL(base, provider, projectID, transactionID string) string

ReviewURL is the public page on the engine host. The provider is not called yet.

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

func WantsResultHTML(accept string) bool

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
	// ValueA is copied onto the provider request as a label. The host does not unlock from it.
	ValueA 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
	// DeferProvider writes the ledger row and skips the plugin. Proceed starts it.
	DeferProvider bool
}

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
	ValueA          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.

func (*Service) Proceed added in v1.9.12

Proceed starts the provider for a prepared row. A row that already has a provider link is returned unchanged.

func (*Service) RenderReview added in v1.9.12

func (s *Service) RenderReview(ctx context.Context, provider string, tx *models.PaymentTransaction, notice string) (string, error)

RenderReview asks the provider plugin for the public checkout page.

func (*Service) Verify

func (s *Service) Verify(ctx context.Context, tx *models.PaymentTransaction, raw map[string]interface{}) (*models.PaymentTransaction, error)

Verify asks the plugin for the authoritative status of an existing transaction.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL