Documentation
¶
Overview ¶
Package virtual implements an in-memory gateway for development and tests.
It talks to nobody: payments live in a map, the payer is sent straight back to the callback URL, and the whole purchase/verify/refund cycle behaves like a real provider. Point your staging configuration at "virtual" and the rest of your code does not change.
Index ¶
- Constants
- func WithDecline(enabled bool) core.Option
- func WithFailingVerify(enabled bool) core.Option
- func WithRedirectURL(redirectURL string) core.Option
- type Gateway
- func (g *Gateway) Capabilities() core.Capabilities
- func (g *Gateway) Inquiry(_ context.Context, req core.InquiryRequest) (core.InquiryResponse, error)
- func (g *Gateway) Name() core.Name
- func (g *Gateway) ParseCallback(r *http.Request) (core.Callback, error)
- func (g *Gateway) Purchase(_ context.Context, req core.PurchaseRequest) (core.PurchaseResponse, error)
- func (g *Gateway) Refund(_ context.Context, req core.RefundRequest) (core.RefundResponse, error)
- func (g *Gateway) Verify(_ context.Context, req core.VerifyRequest) (core.VerifyResponse, error)
Constants ¶
const ( // TokenParam carries the payment token. TokenParam = "payvand_token" // StatusParam carries "OK" or "NOK". StatusParam = "payvand_status" )
Callback parameters the virtual gateway returns the payer with.
const CardNumber = "603799******1234"
CardNumber is the masked PAN reported by every virtual payment.
const Name core.Name = "virtual"
Name is the registry name of this gateway.
Variables ¶
This section is empty.
Functions ¶
func WithDecline ¶
WithDecline makes every payment come back declined.
func WithFailingVerify ¶
WithFailingVerify makes Gateway.Verify fail, so the caller's recovery path can be tested.
func WithRedirectURL ¶
WithRedirectURL sends the payer to a page of your own instead of straight back to the callback URL, which is useful when you want to render a fake bank page in development.
Types ¶
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway is the in-memory implementation of core.Gateway.
func (*Gateway) Capabilities ¶
func (g *Gateway) Capabilities() core.Capabilities
Capabilities reports what the virtual gateway offers, which is everything.
func (*Gateway) Inquiry ¶
func (g *Gateway) Inquiry(_ context.Context, req core.InquiryRequest) (core.InquiryResponse, error)
Inquiry reports the state of a recorded payment.
func (*Gateway) ParseCallback ¶
ParseCallback reads the parameters the virtual redirect carries.
func (*Gateway) Purchase ¶
func (g *Gateway) Purchase(_ context.Context, req core.PurchaseRequest) (core.PurchaseResponse, error)
Purchase records a payment and returns a redirect back to the callback URL.
func (*Gateway) Refund ¶
func (g *Gateway) Refund(_ context.Context, req core.RefundRequest) (core.RefundResponse, error)
Refund reverses a settled payment.
func (*Gateway) Verify ¶
func (g *Gateway) Verify(_ context.Context, req core.VerifyRequest) (core.VerifyResponse, error)
Verify settles a recorded payment.