Documentation
¶
Index ¶
- Constants
- Variables
- func VerifyWebhookSignature(payload []byte, signature string, ipnSecret string) bool
- type APIError
- type Client
- func (c *Client) CheckHealth(ctx context.Context) (map[string]interface{}, error)
- func (c *Client) CreateInvoice(ctx context.Context, req CreateInvoiceRequest) (*CreateInvoiceResponse, error)
- func (c *Client) GetInvoice(ctx context.Context, invoiceID string) (*GetInvoiceResponse, error)
- func (c *Client) ListInvoices(ctx context.Context, query ListInvoicesQuery) (*ListInvoicesResponse, error)
- type ClientOption
- type CreateInvoiceRequest
- type CreateInvoiceResponse
- type GetInvoiceResponse
- type Invoice
- type ListInvoicesQuery
- type ListInvoicesResponse
- type PaymentRecord
- type WebhookEvent
Constants ¶
const ( StatusWaiting = "WAITING" StatusPaid = "PAID" StatusExpired = "EXPIRED" StatusCanceled = "CANCELED" )
Invoice status constants matching PostgreSQL GatewayInvoiceStatus enum.
const ( TypePayment = "PAYMENT" TypeDonation = "DONATION" TypeSubscription = "SUBSCRIPTION" )
Invoice type constants matching PostgreSQL GatewayInvoiceType enum.
const ( SettlementModeNonCustodial = "NON_CUSTODIAL" SettlementModeCustodial = "CUSTODIAL" )
Settlement mode constants matching PostgreSQL GatewaySettlementMode enum.
const ( PaymentMethodDeposit = "DEPOSIT" PaymentMethodWallet = "WALLET" )
Payment method constants matching PostgreSQL GatewayPaymentMethod enum.
const ( PaymentStatusSettling = "SETTLING" PaymentStatusSettled = "SETTLED" PaymentStatusFailed = "FAILED" )
Payment status constants matching PostgreSQL GatewayPaymentStatus enum.
const ( EventPaymentPaid = "payment.paid" EventPaymentFinished = "payment.finished" EventPaymentConfirming = "payment.confirming" EventPaymentFailed = "payment.failed" EventInvoiceCanceled = "invoice.canceled" )
Webhook event constants sent via Instant Payment Notifications (IPN).
const DefaultBaseURL = "https://api.kkhay.com"
DefaultBaseURL is the production API endpoint.
const Version = "1.0.4"
Version of the K Khay Go SDK.
Variables ¶
var ( // ErrInvalidSignature is returned when the webhook HMAC signature does not match. ErrInvalidSignature = errors.New("kkhay: invalid webhook signature") )
Functions ¶
Types ¶
type APIError ¶
type APIError struct {
Status int `json:"status"`
Message string `json:"message"`
Code string `json:"code,omitempty"`
Details interface{} `json:"details,omitempty"`
}
APIError represents an error response returned by the K Khay API.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the official Go HTTP client for K Khay Payment Gateway.
func NewClient ¶
func NewClient(apiKey string, opts ...ClientOption) (*Client, error)
NewClient constructs a new K Khay API client.
func (*Client) CheckHealth ¶
CheckHealth queries API health status.
func (*Client) CreateInvoice ¶
func (c *Client) CreateInvoice(ctx context.Context, req CreateInvoiceRequest) (*CreateInvoiceResponse, error)
CreateInvoice creates a new sovereign crypto payment invoice.
func (*Client) GetInvoice ¶
GetInvoice retrieves an existing invoice by UUID.
func (*Client) ListInvoices ¶
func (c *Client) ListInvoices(ctx context.Context, query ListInvoicesQuery) (*ListInvoicesResponse, error)
ListInvoices queries and paginates gateway invoices.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a Client instance.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
WithHTTPClient sets a custom http.Client.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
WithTimeout sets a custom request timeout.
type CreateInvoiceRequest ¶
type CreateInvoiceRequest struct {
Amount float64 `json:"amount,omitempty"`
Currency string `json:"currency,omitempty"`
PriceAmount float64 `json:"priceAmount,omitempty"`
PriceCurrency string `json:"priceCurrency,omitempty"`
PayNetwork string `json:"payNetwork"`
PayToken string `json:"payToken"`
SettlementAsset string `json:"settlementAsset,omitempty"`
Type string `json:"type,omitempty"`
OrderID string `json:"orderId,omitempty"`
Title string `json:"title,omitempty"`
CustomerName string `json:"customerName,omitempty"`
CustomerEmail string `json:"customerEmail,omitempty"`
RedirectURL string `json:"redirectUrl,omitempty"`
CancelURL string `json:"cancelUrl,omitempty"`
IPNCallbackURL string `json:"ipnCallbackUrl,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
CreateInvoiceRequest parameters for generating a new crypto payment invoice.
type CreateInvoiceResponse ¶
CreateInvoiceResponse contains the created invoice and hosted checkout URL.
type GetInvoiceResponse ¶
type GetInvoiceResponse struct {
OK bool `json:"ok"`
Invoice Invoice `json:"invoice"`
Payments []PaymentRecord `json:"payments"`
}
GetInvoiceResponse contains the requested invoice and transaction records.
type Invoice ¶
type Invoice struct {
ID string `json:"id"`
GatewayID string `json:"gatewayId"`
Type string `json:"type"`
OrderID *string `json:"orderId"`
Title *string `json:"title"`
Amount float64 `json:"amount"`
Currency string `json:"currency"`
PriceAmount float64 `json:"priceAmount"`
PriceCurrency string `json:"priceCurrency"`
SettlementAsset *string `json:"settlementAsset"`
PayAmount *string `json:"payAmount"`
PayToken *string `json:"payToken"`
PayNetwork *string `json:"payNetwork"`
LockedRate *string `json:"lockedRate"`
DepositAddress string `json:"depositAddress"`
DerivationIndex *int `json:"derivationIndex,omitempty"`
PayoutAddress string `json:"payoutAddress"`
Status string `json:"status"`
FeeAmount string `json:"feeAmount"`
NetAmount string `json:"netAmount"`
CustomerName *string `json:"customerName"`
CustomerEmail *string `json:"customerEmail"`
RedirectURL *string `json:"redirectUrl"`
CancelURL *string `json:"cancelUrl"`
IPNCallbackURL *string `json:"ipnCallbackUrl"`
PaymentMethod *string `json:"paymentMethod"`
SettlementMode *string `json:"settlementMode"`
HostedURL string `json:"hostedUrl"`
Metadata map[string]interface{} `json:"metadata"`
ExpiresAt string `json:"expiresAt"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
Invoice represents a K Khay sovereign payment invoice record.
type ListInvoicesQuery ¶
type ListInvoicesQuery struct {
Page int `json:"page,omitempty"`
Limit int `json:"limit,omitempty"`
Status string `json:"status,omitempty"`
Type string `json:"type,omitempty"`
Search string `json:"search,omitempty"`
}
ListInvoicesQuery parameters for pagination and filtering.
type ListInvoicesResponse ¶
type ListInvoicesResponse struct {
OK bool `json:"ok"`
Items []Invoice `json:"items"`
TotalCount int `json:"totalCount"`
TotalPages int `json:"totalPages"`
CurrentPage int `json:"currentPage"`
Limit int `json:"limit"`
}
ListInvoicesResponse paginated list of gateway invoices.
type PaymentRecord ¶
type PaymentRecord struct {
ID string `json:"id"`
InvoiceID string `json:"invoiceId"`
TxHash string `json:"txHash"`
FromAddress *string `json:"fromAddress"`
AmountReceived string `json:"amountReceived"`
Confirmations int `json:"confirmations"`
Status string `json:"status"`
ForwardedTxHash *string `json:"forwardedTxHash"`
ForwardedAt *string `json:"forwardedAt"`
Token *string `json:"token,omitempty"`
Network *string `json:"network,omitempty"`
OrderID *string `json:"orderId,omitempty"`
Title *string `json:"title,omitempty"`
CreatedAt string `json:"createdAt"`
}
PaymentRecord details on-chain transaction hashes, confirmations, and settlement status.
type WebhookEvent ¶
type WebhookEvent struct {
Event string `json:"event"`
InvoiceID string `json:"invoice_id"`
GatewayID string `json:"gateway_id,omitempty"`
InvoiceType string `json:"invoice_type,omitempty"`
OrderID *string `json:"order_id"`
Amount float64 `json:"amount,omitempty"`
Currency string `json:"currency,omitempty"`
PriceAmount float64 `json:"price_amount"`
PriceCurrency string `json:"price_currency"`
PayAmount string `json:"pay_amount"`
PayToken string `json:"pay_token"`
PayNetwork string `json:"pay_network"`
DepositAddress string `json:"deposit_address"`
TxHash *string `json:"tx_hash"`
Status string `json:"status"`
Timestamp string `json:"timestamp"`
}
WebhookEvent payload sent via IPN.
func ParseWebhookEvent ¶
func ParseWebhookEvent(rawBody []byte, signature string, ipnSecret string) (*WebhookEvent, error)
ParseWebhookEvent validates signature and parses the raw JSON body into WebhookEvent.