Documentation
¶
Overview ¶
Package cryptomus implements the Cryptomus crypto-payment gateway protocol: invoice creation, invoice lookup and webhook signature verification. https://doc.cryptomus.com/
Index ¶
Constants ¶
const ( StatusPaid = "paid" StatusPaidOver = "paid_over" StatusWrongAmount = "wrong_amount" StatusLocked = "locked" )
Payment statuses documented by Cryptomus. paid_over means the payer sent more than the invoice amount; the invoice itself is still settled in full. wrong_amount is a final state in which the payer sent less than the invoice amount, and locked is a final state in which received funds were frozen by the AML program: both hold money without covering the order.
const (
DefaultBaseURL = "https://api.cryptomus.com"
)
Variables ¶
This section is empty.
Functions ¶
func FormatMoney ¶
FormatMoney renders a minor-unit amount as the two-decimal string the gateway expects.
func IsNotFound ¶
IsNotFound reports that the gateway answered "no such payment". Callers use it to distinguish "invoice never existed" from transport failures.
func PaidStatus ¶
PaidStatus reports whether an invoice status represents a completed payment.
func ParseMoney ¶
ParseMoney converts a gateway decimal amount to integer minor units. The gateway may report fiat amounts with up to eight decimal places; only trailing zeros beyond two decimals are tolerated, anything else cannot be represented in minor units and is rejected.
Types ¶
type Client ¶
type Client struct {
Config
// contains filtered or unexported fields
}
func (*Client) CreateInvoice ¶
CreateInvoice creates a hosted-checkout invoice for the order.
func (*Client) GetInvoice ¶
GetInvoice fetches the invoice by gateway UUID or, when uuid is empty, by the merchant order number.
func (*Client) VerifyNotificationSign ¶
VerifyNotificationSign authenticates a webhook payload. Cryptomus signs the JSON body with the sign member removed: md5(base64(json) + api_key). The remaining bytes must stay untouched, so the sign member is stripped from the raw payload instead of re-encoding it.
type Invoice ¶
type Invoice struct {
UUID string `json:"uuid"`
OrderNo string `json:"order_id"`
Amount string `json:"amount"`
Currency string `json:"currency"`
PayerCurrency string `json:"payer_currency"`
PaymentAmount string `json:"payment_amount"`
URL string `json:"url"`
ExpiredAt int64 `json:"expired_at"`
Status string `json:"status"`
PaymentStatus string `json:"payment_status"`
IsFinal bool `json:"is_final"`
}
Invoice is the gateway's view of a payment. The info endpoint reports the settlement state in payment_status while the create endpoint uses status; Paid accepts either so callers do not depend on which endpoint produced it.
type Notification ¶
type Notification struct {
Type string `json:"type"`
UUID string `json:"uuid"`
OrderNo string `json:"order_id"`
Amount string `json:"amount"`
PaymentAmount string `json:"payment_amount"`
Currency string `json:"currency"`
PayerCurrency string `json:"payer_currency"`
Network string `json:"network"`
TxID string `json:"txid"`
IsFinal bool `json:"is_final"`
Status string `json:"status"`
Sign string `json:"sign"`
}
Notification is the webhook payload for invoice payments.
func ParseNotification ¶
func ParseNotification(body []byte) (*Notification, error)
ParseNotification decodes a webhook payload without verifying it.