pilvytis

package
v0.0.0-...-c97221a Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const AppTopicOrderUpdated = "order_updated"

AppTopicOrderUpdated is an topic when the payment order is updated.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API is object which exposes pilvytis API.

func NewAPI

func NewAPI(hc *requests.HTTPClient, url string, signer identity.SignerFactory, lp locationProvider, cc addressProvider) *API

NewAPI returns a new API instance.

func (*API) GatewayClientCallback

func (a *API) GatewayClientCallback(id identity.Identity, gateway string, payload any) error

GatewayClientCallback triggers a payment callback from the client-side. We will query the payment provider to verify the payment.

func (*API) GetMystExchangeRate

func (a *API) GetMystExchangeRate() (map[string]float64, error)

GetMystExchangeRate returns the exchange rate for myst to other currencies.

func (*API) GetMystExchangeRateFor

func (a *API) GetMystExchangeRateFor(curr string) (float64, error)

GetMystExchangeRateFor returns the exchange rate for myst to for a given currency currencies.

func (*API) GetPaymentGatewayOrder

func (a *API) GetPaymentGatewayOrder(id identity.Identity, oid string) (*GatewayOrderResponse, error)

GetPaymentGatewayOrder returns a payment order by ID from the API service that belongs to a given identity.

func (*API) GetPaymentGatewayOrderInvoice

func (a *API) GetPaymentGatewayOrderInvoice(id identity.Identity, oid string) ([]byte, error)

GetPaymentGatewayOrderInvoice returns an invoice for a payment order by ID from the API service that belongs to a given identity.

func (*API) GetPaymentGatewayOrders

func (a *API) GetPaymentGatewayOrders(id identity.Identity) ([]GatewayOrderResponse, error)

GetPaymentGatewayOrders returns a list of payment orders from the API service made by a given identity.

func (*API) GetPaymentGateways

func (a *API) GetPaymentGateways(optionsCurrency exchange.Currency) ([]GatewaysResponse, error)

GetPaymentGateways returns a slice of supported gateways.

func (*API) GetRegistrationPaymentStatus

func (a *API) GetRegistrationPaymentStatus(id identity.Identity) (*RegistrationPaymentResponse, error)

GetRegistrationPaymentStatus returns whether a registration payment order has been paid by a given identity

type AppEventOrderUpdated

type AppEventOrderUpdated struct {
	OrderSummary
}

AppEventOrderUpdated is the event payload for AppTopicOrderUpdated topic.

type CompletionProvider

type CompletionProvider interface {
	Incomplete() bool
	Status() string
	Paid() bool
}

CompletionProvider is a temporary interface to make any order work with the tracker. TODO: Remove after legacy payments are removed.

type GatewayOrderRequest

type GatewayOrderRequest struct {
	Identity    identity.Identity
	Gateway     string
	MystAmount  string
	AmountUSD   string
	PayCurrency string
	Country     string
	State       string
	ProjectID   string
	CallerData  json.RawMessage
}

GatewayOrderRequest for creating payment gateway order

type GatewayOrderResponse

type GatewayOrderResponse struct {
	ID     string             `json:"id"`
	Status PaymentOrderStatus `json:"status"`

	Identity       string `json:"identity"`
	ChainID        int64  `json:"chain_id"`
	ChannelAddress string `json:"channel_address"`

	GatewayName string `json:"gateway_name"`

	ReceiveMYST string `json:"receive_myst"`
	PayAmount   string `json:"pay_amount"`
	PayCurrency string `json:"pay_currency"`

	Country string `json:"country"`
	State   string `json:"state"`

	Currency      string `json:"currency"`
	ItemsSubTotal string `json:"items_sub_total"`
	TaxRate       string `json:"tax_rate"`
	TaxSubTotal   string `json:"tax_sub_total"`
	OrderTotal    string `json:"order_total"`

	PublicGatewayData json.RawMessage `json:"public_gateway_data"`
}

GatewayOrderResponse is a response for a payment order.

type GatewaysResponse

type GatewaysResponse struct {
	Name         string              `json:"name"`
	OrderOptions PaymentOrderOptions `json:"order_options"`
	Currencies   []string            `json:"currencies"`
}

GatewaysResponse holds data about payment gateways.

type OrderIssuer

type OrderIssuer struct {
	// contains filtered or unexported fields
}

OrderIssuer combines the pilvytis API and order tracker. Only the order issuer can issue new payment orders.

func NewOrderIssuer

func NewOrderIssuer(api *API, tracker *StatusTracker) *OrderIssuer

NewOrderIssuer returns a new order issuer.

func (*OrderIssuer) CreatePaymentGatewayOrder

func (o *OrderIssuer) CreatePaymentGatewayOrder(cgo GatewayOrderRequest) (*GatewayOrderResponse, error)

CreatePaymentGatewayOrder will create a new payment order and send a notification to start tracking it.

type OrderSummary

type OrderSummary struct {
	ID              string
	IdentityAddress string
	Status          CompletionProvider
	PayAmount       string
	PayCurrency     string
}

OrderSummary is a subset of an OrderResponse stored by the StatusTracker.

func (OrderSummary) String

func (o OrderSummary) String() string

type PaymentOrderOptions

type PaymentOrderOptions struct {
	Minimum   float64   `json:"minimum"`
	Suggested []float64 `json:"suggested"`
}

PaymentOrderOptions represents pilvytis payment order options

type PaymentOrderStatus

type PaymentOrderStatus string

PaymentOrderStatus defines a status for a payment order.

const (
	// PaymentOrderStatusInitial defines a status for any payment orders not sent to the
	// payment service provider.
	PaymentOrderStatusInitial PaymentOrderStatus = "initial"
	// PaymentOrderStatusNew defines a status for any payment orders sent to the
	// payment service provider.
	PaymentOrderStatusNew PaymentOrderStatus = "new"
	// PaymentOrderStatusPaid defines a status for any payment orders paid and processed by the
	// payment service provider.
	PaymentOrderStatusPaid PaymentOrderStatus = "paid"
	// PaymentOrderStatusFailed defines a status for any payment orders sent to the
	// payment service provider which have failed.
	PaymentOrderStatusFailed PaymentOrderStatus = "failed"
)

func (PaymentOrderStatus) Incomplete

func (p PaymentOrderStatus) Incomplete() bool

Incomplete tells if the order is incomplete and its status needs to be tracked for updates.

func (PaymentOrderStatus) Paid

func (p PaymentOrderStatus) Paid() bool

Paid tells if the order has been paid for.

func (PaymentOrderStatus) Status

func (p PaymentOrderStatus) Status() string

Status returns a current status. Its part of StatusProvider interface.

type RegistrationPaymentResponse

type RegistrationPaymentResponse struct {
	Paid bool `json:"paid"`
}

RegistrationPaymentResponse is a response for the status of a registration payment.

type StatusTracker

type StatusTracker struct {
	// contains filtered or unexported fields
}

StatusTracker tracks payment order status.

func NewStatusTracker

func NewStatusTracker(api orderProvider, identityProvider identityProvider, eventBus eventbus.Publisher, updateInterval time.Duration) *StatusTracker

NewStatusTracker constructs a StatusTracker.

func (*StatusTracker) Stop

func (t *StatusTracker) Stop()

Stop stops the status tracker

func (*StatusTracker) SubscribeAsync

func (t *StatusTracker) SubscribeAsync(bus eventbus.Subscriber) error

SubscribeAsync subscribes to event to listen for unlock events.

func (*StatusTracker) Track

func (t *StatusTracker) Track()

Track will block and start tracking orders.

func (*StatusTracker) UpdateOrdersFor

func (t *StatusTracker) UpdateOrdersFor(id identity.Identity)

UpdateOrdersFor sends a notification to the main running thread to sync orders for the given identity.

Jump to

Keyboard shortcuts

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