epay

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModeSubmit uses EPay's browser-facing submit.php endpoint.
	ModeSubmit = "submit"
	// ModeMAPI uses EPay's server-to-server mapi.php endpoint.
	ModeMAPI = "mapi"
)

Variables

View Source
var ErrQueryNotSupported = errors.New("gateway does not support order query API")

ErrQueryNotSupported is returned when the payment gateway implements neither the standard EPay order query API nor the EasyPay-compatible fallback API (e.g., both return HTTP 404).

Functions

func FormatMoney added in v1.14.0

func FormatMoney(amount float64) string

FormatMoney returns the exact two-decimal amount sent to an EPay-compatible gateway. It intentionally preserves the historical truncation behaviour.

func ParseMoney added in v1.14.0

func ParseMoney(value string) (int64, error)

ParseMoney converts a non-negative decimal amount to its integer minor unit. It rejects floats, exponents and values with more than two decimal places.

Types

type Client

type Client struct {
	Pid  string
	Url  string
	Key  string
	Type string
	Mode string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(pid, url, key string, Type string, mode ...string) *Client

NewClient creates an EPay client. The optional mode keeps existing callers on submit mode while allowing payment configurations to opt into mapi.

func (*Client) CreatePayUrl

func (c *Client) CreatePayUrl(order Order) string

CreatePayUrl is retained for source compatibility.

func (*Client) CreatePayment added in v1.14.20

func (c *Client) CreatePayment(ctx context.Context, order Order) (*PaymentResult, error)

CreatePayment starts a payment using the configured mode. Submit mode keeps the legacy browser redirect; mapi sends a form-encoded POST from this server.

func (*Client) QueryOrder added in v1.14.0

func (c *Client) QueryOrder(orderNo string) (*QueryResult, error)

QueryOrder obtains payment details directly from the gateway. It first uses the standard EPay api.php protocol. When that endpoint is absent, it falls back to a known EasyPay-compatible POST protocol that exposes only status.

func (*Client) QueryOrderStatus

func (c *Client) QueryOrderStatus(orderNo string) bool

QueryOrderStatus is kept for callers that only need a status boolean.

func (*Client) VerifySign

func (c *Client) VerifySign(params map[string]string) bool

type Order

type Order struct {
	Name      string
	OrderNo   string
	Amount    float64
	SignType  string
	NotifyUrl string
	ReturnUrl string
	ClientIP  string
	Device    string
}

type PaymentResult added in v1.14.20

type PaymentResult struct {
	Type    string
	URL     string
	TradeNo string
}

PaymentResult is the transport-neutral result of starting an EPay payment. Type is "url" for a browser redirect and "qr" when the caller should render URL as a QR code.

type QueryResult added in v1.14.0

type QueryResult struct {
	MerchantID string
	TradeNo    string
	OrderNo    string
	Type       string
	Money      string
	Paid       bool
	Message    string
	// StatusOnly reports that the gateway query API returned only a payment
	// status. Callers must not treat omitted payment details as verified.
	StatusOnly bool
}

Jump to

Keyboard shortcuts

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