pg

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 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

Overview

Package pg is the Payment Gateway v1 HTTP client, authenticated with a broker-minted product credential.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DataInto

func DataInto[T any](r *Response) (T, error)

DataInto decodes a single-resource PG response's "data" into T (order detail).

Types

type CheckoutParams

type CheckoutParams struct {
	Operation     string // PURCHASE | VERIFY
	PaymentMethod string // BANK_TRANSFER | CARD | NAPAS_BANK_TRANSFER (optional)
	OrderAmount   string
	Currency      string // VND
	InvoiceNumber string
	Description   string
	CustomerID    string
	SuccessURL    string
	ErrorURL      string
	CancelURL     string
}

CheckoutParams are the checkout/init fields; merchant comes from the credential.

type Client

type Client struct {
	MaxRetries int

	// CheckoutURL is the hosted-checkout host, separate from the REST API host.
	CheckoutURL string

	// Logf, if set, reports progress such as a 429 retry.
	Logf func(format string, args ...any)
	// contains filtered or unexported fields
}

Client calls the Payment Gateway v1 REST API over HTTP.

func NewClient

func NewClient(baseURL string, creds credentialSource) *Client

NewClient returns a PG client for baseURL, minting its Basic credential from creds.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, query url.Values) (*Response, error)

Get sends GET path and returns the parsed response.

func (*Client) InitCheckout

func (c *Client) InitCheckout(ctx context.Context, p CheckoutParams) (string, error)

InitCheckout POSTs a signed checkout/init and returns the payment page URL (the 302 Location). Only the signature is sent, never the secret. Field order must match PaymentGatewayFeature::signFields.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body any) (*Response, error)

Post sends POST path with an optional JSON body and returns the response.

type Meta

type Meta struct {
	PerPage     int  `json:"per_page"`
	Total       int  `json:"total"`
	HasMore     bool `json:"has_more"`
	CurrentPage int  `json:"current_page"`
	PageCount   int  `json:"page_count"`
}

Meta is a PG list response's paging block.

func ListInto

func ListInto[T any](r *Response) ([]T, *Meta, error)

ListInto decodes a PG list response's "data" into []T and returns its meta (nil when the response carries none).

type Response

type Response struct {
	Raw     json.RawMessage
	Data    json.RawMessage
	Meta    *Meta
	Message string
}

Response is a PG v1 success body. Some endpoints skip the "data" wrapper, so Raw keeps the whole body.

func (*Response) Into

func (r *Response) Into(v any) error

Into unmarshals the whole response body into v.

Jump to

Keyboard shortcuts

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