nakopay

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 17 Imported by: 0

README

nakopay-go

Official NakoPay SDK for Go.

go get git.nakopay.com/code/sdk-go

Quick start

package main

import (
    "context"
    "fmt"
    "os"

    "git.nakopay.com/code/sdk-go"
)

func main() {
    client := nakopay.New(os.Getenv("NAKOPAY_SECRET_KEY"))

    inv, err := client.Invoices.Create(context.Background(), &nakopay.InvoiceCreateParams{
        Amount:        "19.99",
        Currency:      "USD",
        Coin:          "BTC",
        Description:   "Pro plan",
        CustomerEmail: "alex@acme.com",
    }, nakopay.WithIdempotencyKey("ord_1042"))
    if err != nil {
        panic(err)
    }
    fmt.Println(inv.ID, inv.CheckoutURL)
}

Features

  • Pinned to API version 2025-04-20
  • Auto-retry on 429 / 5xx with exponential backoff + jitter
  • Auto-generated Idempotency-Key for every POST (override with WithIdempotencyKey)
  • Webhook signature verifier: nakopay.ConstructEvent(payload, sigHeader, secret)
  • Typed APIError with Code, Type, Message, RequestID, Param

Webhooks

event, err := nakopay.ConstructEvent(rawBody, r.Header.Get("X-NakoPay-Signature"), os.Getenv("NAKOPAY_WEBHOOK_SECRET"))
if err != nil {
    http.Error(w, err.Error(), 400)
    return
}
if event.Type == "invoice.paid" {
    // fulfill
}

License

MIT - see LICENSE.

Documentation

Overview

Package nakopay is the official Go SDK for the NakoPay API.

Create a client with nakopay.New(apiKey) and call resources via the returned *Client (e.g. client.Invoices.Create).

All money values are decimal strings; do not use float64.

Index

Constants

View Source
const DefaultAPIVersion = "2025-04-20"

DefaultAPIVersion is the API contract this SDK is pinned to.

View Source
const DefaultBaseURL = "https://api.nakopay.com/v1"

DefaultBaseURL is the production NakoPay API root.

View Source
const DefaultWebhookTolerance = 5 * time.Minute

DefaultWebhookTolerance is the +/- window allowed between the signed timestamp and the verifier's local clock. Default is 5 minutes.

View Source
const Version = "0.2.0"

Version of this SDK.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Code       string `json:"code"`
	Type       string `json:"type,omitempty"`
	Message    string `json:"message"`
	Param      string `json:"param,omitempty"`
	DocURL     string `json:"doc_url,omitempty"`
	RequestID  string `json:"request_id,omitempty"`
	StatusCode int    `json:"-"`
}

APIError is returned for any non-2xx response from the NakoPay API.

func (*APIError) Error

func (e *APIError) Error() string

Error implements error.

func (*APIError) IsAuthentication

func (e *APIError) IsAuthentication() bool

IsAuthentication returns true if this is a 401 / authentication error.

func (*APIError) IsIdempotency

func (e *APIError) IsIdempotency() bool

IsIdempotency returns true if this is an idempotency conflict.

func (*APIError) IsRateLimit

func (e *APIError) IsRateLimit() bool

IsRateLimit returns true if this is a 429 / rate limit error.

func (*APIError) IsRetryable

func (e *APIError) IsRetryable() bool

IsRetryable returns true for errors that may succeed on retry (429, 5xx, connection).

type APIKey

type APIKey struct {
	ID       string   `json:"id"`
	Object   string   `json:"object"`
	Name     string   `json:"name,omitempty"`
	Prefix   string   `json:"prefix"`
	Scopes   []string `json:"scopes"`
	Livemode bool     `json:"livemode"`
	Created  int64    `json:"created"`
	LastUsed int64    `json:"last_used,omitempty"`
	Revoked  bool     `json:"revoked"`
	Secret   string   `json:"secret,omitempty"` // only on create/rotate
}

APIKey is a NakoPay API key record.

type APIKeyList

type APIKeyList struct {
	Object string   `json:"object"`
	Data   []APIKey `json:"data"`
}

APIKeyList is a page of API keys.

type Client

type Client struct {
	Invoices          *InvoicesResource
	Customers         *CustomersResource
	PaymentLinks      *PaymentLinksResource
	Webhooks          *WebhooksResource
	Events            *EventsResource
	Rates             *RatesResource
	Credits           *CreditsResource
	Keys              *KeysResource
	Subscriptions     *SubscriptionsResource
	SubscriptionPlans *SubscriptionPlansResource
	Refunds           *RefundsResource
	Logs              *LogsResource
	Sandbox           *SandboxResource
	// contains filtered or unexported fields
}

Client is the entry point for all NakoPay API calls.

Construct one with New() and reuse it across goroutines (it is safe for concurrent use).

func New

func New(apiKey string, opts ...Option) *Client

New constructs a Client. apiKey must be a secret key (sk_live_… or sk_test_…). Passing a publishable key (pk_…) panics - those belong in the browser.

type ConnectionError

type ConnectionError struct {
	Err error
}

ConnectionError wraps any transport-level failure (DNS, refused, timeout).

func (*ConnectionError) Error

func (e *ConnectionError) Error() string

func (*ConnectionError) Unwrap

func (e *ConnectionError) Unwrap() error

type CreditBalance

type CreditBalance struct {
	BalanceSats string `json:"balance_sats"`
}

CreditBalance is the merchant's prepaid balance in sats.

type CreditsResource

type CreditsResource struct {
	Topups *TopupsResource
	// contains filtered or unexported fields
}

CreditsResource bundles prepaid-credit endpoints.

func (*CreditsResource) Balance

func (r *CreditsResource) Balance(ctx context.Context, opts ...RequestOption) (*CreditBalance, error)

Balance returns the current prepaid credit balance.

type Customer

type Customer struct {
	ID       string            `json:"id"`
	Object   string            `json:"object"`
	Email    string            `json:"email,omitempty"`
	Name     string            `json:"name,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
	Created  int64             `json:"created"`
}

Customer is a stored merchant customer.

type CustomerCreateParams

type CustomerCreateParams struct {
	Email    string            `json:"email,omitempty"`
	Name     string            `json:"name,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

CustomerCreateParams is the body for POST /customers.

type CustomerList

type CustomerList struct {
	Object     string     `json:"object"`
	Data       []Customer `json:"data"`
	HasMore    bool       `json:"has_more"`
	NextCursor string     `json:"next_cursor,omitempty"`
}

CustomerList is a page of customers.

type CustomersResource

type CustomersResource struct {
	// contains filtered or unexported fields
}

CustomersResource exposes /customers endpoints.

func (*CustomersResource) Create

func (*CustomersResource) List

func (r *CustomersResource) List(ctx context.Context, limit int, startingAfter string, opts ...RequestOption) (*CustomerList, error)

func (*CustomersResource) Retrieve

func (r *CustomersResource) Retrieve(ctx context.Context, id string, opts ...RequestOption) (*Customer, error)

type Event

type Event struct {
	ID         string          `json:"id"`
	Object     string          `json:"object"`
	Type       string          `json:"type"`
	APIVersion string          `json:"api_version"`
	Created    int64           `json:"created"`
	Livemode   bool            `json:"livemode"`
	Data       json.RawMessage `json:"data"`
}

Event is the parsed webhook payload.

func ConstructEvent

func ConstructEvent(payload []byte, sigHeader, secret string) (*Event, error)

ConstructEvent verifies the signature header and returns the parsed event.

Header format: t=<unix>,v1=<hex_hmac> Signed payload: <t>.<rawBody>

Use the default tolerance via ConstructEvent; pass ConstructEventWithTolerance for a custom one.

func ConstructEventWithTolerance

func ConstructEventWithTolerance(payload []byte, sigHeader, secret string, tolerance time.Duration) (*Event, error)

ConstructEventWithTolerance is ConstructEvent with a configurable timestamp tolerance.

type EventList

type EventList struct {
	Object     string  `json:"object"`
	Data       []Event `json:"data"`
	HasMore    bool    `json:"has_more"`
	NextCursor string  `json:"next_cursor,omitempty"`
}

EventList is a page of events.

type EventListParams

type EventListParams struct {
	Limit         int
	StartingAfter string
	Type          string
}

EventListParams filters listEvent calls.

type EventsResource

type EventsResource struct {
	// contains filtered or unexported fields
}

EventsResource exposes /events-list.

func (*EventsResource) Each

func (r *EventsResource) Each(ctx context.Context, p *EventListParams, fn func(*Event) bool) error

Each iterates every event across pages.

func (*EventsResource) List

type Invoice

type Invoice struct {
	ID       string `json:"id"`
	Object   string `json:"object"`
	Amount   string `json:"amount"`
	Currency string `json:"currency"`
	// Coin is empty on multi-method invoices until the buyer picks / pays.
	Coin          string            `json:"coin,omitempty"`
	AmountCrypto  string            `json:"amount_crypto,omitempty"`
	Address       string            `json:"address,omitempty"`
	Status        string            `json:"status"`
	CheckoutURL   string            `json:"checkout_url"`
	Description   string            `json:"description,omitempty"`
	CustomerEmail string            `json:"customer_email,omitempty"`
	CustomerID    string            `json:"customer,omitempty"`
	Metadata      map[string]string `json:"metadata,omitempty"`
	// PaymentMethods lists every (coin, network) option offered to the buyer.
	// Nil/empty on single-coin invoices.
	PaymentMethods []PaymentMethod `json:"payment_methods,omitempty"`
	// SettledCoin/SettledNetwork record what the buyer actually paid with.
	SettledCoin    string `json:"settled_coin,omitempty"`
	SettledNetwork string `json:"settled_network,omitempty"`
	Created        int64  `json:"created"`
	ExpiresAt      int64  `json:"expires_at,omitempty"`
	PaidAt         int64  `json:"paid_at,omitempty"`
	Livemode       bool   `json:"livemode"`
}

Invoice represents a payment invoice.

type InvoiceCreateParams

type InvoiceCreateParams struct {
	Amount   string `json:"amount"`
	Currency string `json:"currency"`
	// Coin is optional. Omit to create a multi-method invoice where the
	// customer picks any enabled coin/network at checkout. Pass a coin code
	// to lock the invoice to a single coin (legacy single-coin flow).
	Coin          string            `json:"coin,omitempty"`
	Description   string            `json:"description,omitempty"`
	CustomerEmail string            `json:"customer_email,omitempty"`
	CustomerID    string            `json:"customer,omitempty"`
	Metadata      map[string]string `json:"metadata,omitempty"`
	SuccessURL    string            `json:"success_url,omitempty"`
	CancelURL     string            `json:"cancel_url,omitempty"`
}

InvoiceCreateParams is the request body for creating an invoice.

type InvoiceList

type InvoiceList struct {
	Object     string    `json:"object"`
	Data       []Invoice `json:"data"`
	HasMore    bool      `json:"has_more"`
	NextCursor string    `json:"next_cursor,omitempty"`
}

InvoiceList is one page of invoices.

type InvoiceListParams

type InvoiceListParams struct {
	Limit         int    `json:"limit,omitempty"`
	StartingAfter string `json:"starting_after,omitempty"`
	Status        string `json:"status,omitempty"`
}

InvoiceListParams filters listInvoice calls.

type InvoicesResource

type InvoicesResource struct {
	// contains filtered or unexported fields
}

InvoicesResource exposes /invoices-* endpoints.

func (*InvoicesResource) Cancel

func (r *InvoicesResource) Cancel(ctx context.Context, id string, opts ...RequestOption) (*Invoice, error)

func (*InvoicesResource) Create

func (*InvoicesResource) Each

func (r *InvoicesResource) Each(ctx context.Context, p *InvoiceListParams, fn func(*Invoice) bool) error

Each iterates every invoice across pages, calling fn with each one. Stop by returning false from fn, or by cancelling ctx.

func (*InvoicesResource) List

List returns one page of invoices. Use the returned NextCursor to paginate.

func (*InvoicesResource) Retrieve

func (r *InvoicesResource) Retrieve(ctx context.Context, id string, opts ...RequestOption) (*Invoice, error)

type KeyCreateParams

type KeyCreateParams struct {
	Name     string   `json:"name,omitempty"`
	Scopes   []string `json:"scopes,omitempty"`
	Livemode bool     `json:"livemode,omitempty"`
}

KeyCreateParams is the body for POST /keys-create.

type KeysResource

type KeysResource struct {
	// contains filtered or unexported fields
}

KeysResource exposes /keys-* endpoints.

func (*KeysResource) Create

func (r *KeysResource) Create(ctx context.Context, p *KeyCreateParams, opts ...RequestOption) (*APIKey, error)

func (*KeysResource) List

func (r *KeysResource) List(ctx context.Context, opts ...RequestOption) (*APIKeyList, error)

func (*KeysResource) Revoke

func (r *KeysResource) Revoke(ctx context.Context, id string, opts ...RequestOption) error

func (*KeysResource) Rotate

func (r *KeysResource) Rotate(ctx context.Context, id string, opts ...RequestOption) (*APIKey, error)

type LogEntry

type LogEntry struct {
	ID        string            `json:"id"`
	Object    string            `json:"object"`
	Method    string            `json:"method"`
	Path      string            `json:"path"`
	Status    int               `json:"status"`
	Duration  int               `json:"duration_ms"`
	IPAddress string            `json:"ip_address,omitempty"`
	UserAgent string            `json:"user_agent,omitempty"`
	RequestID string            `json:"request_id,omitempty"`
	Created   int64             `json:"created"`
	Metadata  map[string]string `json:"metadata,omitempty"`
}

LogEntry is a single API request log row.

type LogList

type LogList struct {
	Object     string     `json:"object"`
	Data       []LogEntry `json:"data"`
	HasMore    bool       `json:"has_more"`
	NextCursor string     `json:"next_cursor,omitempty"`
}

LogList is one page of log entries.

type LogListParams

type LogListParams struct {
	Limit         int    `json:"limit,omitempty"`
	StartingAfter string `json:"starting_after,omitempty"`
	Method        string `json:"method,omitempty"`
	Path          string `json:"path,omitempty"`
	Status        string `json:"status,omitempty"`
}

LogListParams filters list calls.

type LogsResource

type LogsResource struct {
	// contains filtered or unexported fields
}

LogsResource exposes /logs-* endpoints.

func (*LogsResource) List

func (r *LogsResource) List(ctx context.Context, p *LogListParams, opts ...RequestOption) (*LogList, error)

List returns one page of API request logs.

type Option

type Option func(*config)

Option customises a Client at construction time.

func WithAPIVersion

func WithAPIVersion(v string) Option

WithAPIVersion pins to a specific API contract version.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL overrides the API root (useful for testing against a mock).

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient swaps the underlying http.Client.

func WithHeader

func WithHeader(k, v string) Option

WithHeader sets a default header sent on every request.

func WithMaxRetries

func WithMaxRetries(n int) Option

WithMaxRetries sets the retry budget for 429/5xx responses (default 3).

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the per-request timeout (default 30s).

type PaymentLink struct {
	ID          string `json:"id"`
	Object      string `json:"object"`
	URL         string `json:"url"`
	Amount      string `json:"amount,omitempty"`
	Currency    string `json:"currency,omitempty"`
	Description string `json:"description,omitempty"`
	Active      bool   `json:"active"`
	Created     int64  `json:"created"`
}

PaymentLink is a reusable hosted checkout link.

type PaymentLinkCreateParams

type PaymentLinkCreateParams struct {
	Amount      string `json:"amount,omitempty"`
	Currency    string `json:"currency,omitempty"`
	Description string `json:"description,omitempty"`
}

PaymentLinkCreateParams is the body for POST /payment-links.

type PaymentLinksResource

type PaymentLinksResource struct {
	// contains filtered or unexported fields
}

PaymentLinksResource exposes /payment-links endpoints.

func (*PaymentLinksResource) Create

func (*PaymentLinksResource) Retrieve

func (r *PaymentLinksResource) Retrieve(ctx context.Context, id string, opts ...RequestOption) (*PaymentLink, error)

type PaymentMethod

type PaymentMethod struct {
	Coin         string `json:"coin"`
	Network      string `json:"network"`
	BtcpayMethod string `json:"btcpay_method,omitempty"`
	Address      string `json:"address,omitempty"`
	Bolt11       string `json:"bolt11,omitempty"`
	AmountCrypto string `json:"amount_crypto"`
	BestChoice   bool   `json:"best_choice,omitempty"`
}

PaymentMethod is one concrete (coin, network) option offered on a multi-method invoice.

type Rates

type Rates struct {
	Object     string            `json:"object"`
	Base       string            `json:"base"`
	Quotes     map[string]string `json:"quotes"`
	TTLSeconds int               `json:"ttl_seconds"`
	FetchedAt  string            `json:"fetched_at"`
}

Rates is a fiat-quote response from /rates-get.

type RatesResource

type RatesResource struct {
	// contains filtered or unexported fields
}

RatesResource exposes /rates-get.

func (*RatesResource) Retrieve

func (r *RatesResource) Retrieve(ctx context.Context, base string, quotes []string, opts ...RequestOption) (*Rates, error)

Retrieve fetches FX quotes for base into one or more quote currencies.

type Refund

type Refund struct {
	ID            string            `json:"id"`
	Object        string            `json:"object"`
	Livemode      bool              `json:"livemode"`
	Invoice       string            `json:"invoice"`
	Amount        string            `json:"amount"`
	AmountFiat    string            `json:"amount_fiat,omitempty"`
	Currency      string            `json:"currency,omitempty"`
	Coin          string            `json:"coin"`
	Destination   string            `json:"destination,omitempty"`
	Reason        string            `json:"reason,omitempty"`
	Status        string            `json:"status"`
	TxHash        string            `json:"tx_hash,omitempty"`
	Fee           string            `json:"fee"`
	Metadata      map[string]string `json:"metadata,omitempty"`
	FailureReason string            `json:"failure_reason,omitempty"`
	CreatedAt     string            `json:"created_at"`
	BroadcastAt   string            `json:"broadcast_at,omitempty"`
	SucceededAt   string            `json:"succeeded_at,omitempty"`
	FailedAt      string            `json:"failed_at,omitempty"`
}

Refund represents a merchant-initiated refund against a paid invoice.

type RefundCreateParams

type RefundCreateParams struct {
	InvoiceID   string            `json:"invoice_id"`
	Amount      string            `json:"amount,omitempty"`
	Destination string            `json:"destination,omitempty"`
	Reason      string            `json:"reason,omitempty"`
	Metadata    map[string]string `json:"metadata,omitempty"`
}

RefundCreateParams is the body for POST /refunds-create.

type RefundList

type RefundList struct {
	Object     string   `json:"object"`
	Data       []Refund `json:"data"`
	HasMore    bool     `json:"has_more"`
	NextCursor string   `json:"next_cursor,omitempty"`
}

RefundList is one page of refunds.

type RefundListParams

type RefundListParams struct {
	Limit         int    `json:"limit,omitempty"`
	StartingAfter string `json:"starting_after,omitempty"`
	InvoiceID     string `json:"invoice_id,omitempty"`
	Status        string `json:"status,omitempty"`
}

RefundListParams filters /refunds-list.

type RefundsResource

type RefundsResource struct {
	// contains filtered or unexported fields
}

RefundsResource exposes /refunds-* endpoints.

func (*RefundsResource) Cancel

func (r *RefundsResource) Cancel(ctx context.Context, id string, opts ...RequestOption) (*Refund, error)

func (*RefundsResource) Create

func (*RefundsResource) List

func (*RefundsResource) Retrieve

func (r *RefundsResource) Retrieve(ctx context.Context, id string, opts ...RequestOption) (*Refund, error)

type RequestOption

type RequestOption func(*requestOptions)

RequestOption tweaks a single API call.

func WithIdempotencyKey

func WithIdempotencyKey(k string) RequestOption

WithIdempotencyKey sets the Idempotency-Key header for one call. If omitted, the SDK auto-generates one for every POST.

func WithRequestHeader

func WithRequestHeader(k, v string) RequestOption

WithRequestHeader adds an extra header to one call.

type SandboxResource

type SandboxResource struct {
	// contains filtered or unexported fields
}

SandboxResource exposes test-mode-only helpers. Requires sk_test_* key.

func (*SandboxResource) Seed

Seed creates demo customers + invoices in the sandbox.

type SandboxSeedParams

type SandboxSeedParams struct {
	Invoices  int      `json:"invoices,omitempty"`
	Customers int      `json:"customers,omitempty"`
	Coins     []string `json:"coins,omitempty"`
	Reset     bool     `json:"reset,omitempty"`
}

SandboxSeedParams configures /sandbox-seed (all fields optional).

type SandboxSeedResult

type SandboxSeedResult struct {
	Object      string   `json:"object"`
	CustomerIDs []string `json:"customer_ids"`
	InvoiceIDs  []string `json:"invoice_ids"`
}

SandboxSeedResult is the response from POST /sandbox-seed.

type SignatureVerificationError

type SignatureVerificationError struct {
	Code    string
	Message string
}

SignatureVerificationError is returned by ConstructEvent when verification fails.

func (*SignatureVerificationError) Error

type Subscription

type Subscription struct {
	ID                 string            `json:"id"`
	Object             string            `json:"object"`
	Status             string            `json:"status"` // active, past_due, canceled, paused
	Amount             string            `json:"amount"`
	Currency           string            `json:"currency"`
	Coin               string            `json:"coin"`
	Interval           string            `json:"interval"` // week, month, year
	IntervalCount      int               `json:"interval_count"`
	CustomerID         string            `json:"customer_id,omitempty"`
	CurrentPeriodStart int64             `json:"current_period_start"`
	CurrentPeriodEnd   int64             `json:"current_period_end"`
	CancelAtPeriodEnd  bool              `json:"cancel_at_period_end"`
	Metadata           map[string]string `json:"metadata,omitempty"`
	Created            int64             `json:"created"`
	Livemode           bool              `json:"livemode"`
}

Subscription represents a crypto subscription.

type SubscriptionList

type SubscriptionList struct {
	Object     string         `json:"object"`
	Data       []Subscription `json:"data"`
	HasMore    bool           `json:"has_more"`
	NextCursor string         `json:"next_cursor,omitempty"`
}

SubscriptionList is one page of subscriptions.

type SubscriptionListParams

type SubscriptionListParams struct {
	Limit         int    `json:"limit,omitempty"`
	StartingAfter string `json:"starting_after,omitempty"`
	Status        string `json:"status,omitempty"`
	CustomerID    string `json:"customer_id,omitempty"`
}

SubscriptionListParams filters list calls.

type SubscriptionPauseResult

type SubscriptionPauseResult struct {
	ID       string `json:"id"`
	Status   string `json:"status"`
	PausedAt int64  `json:"paused_at"`
}

SubscriptionPauseResult is the response from POST /subscriptions-pause.

type SubscriptionPlan

type SubscriptionPlan struct {
	ID            string            `json:"id"`
	Object        string            `json:"object"`
	Name          string            `json:"name"`
	Amount        string            `json:"amount"`
	Coin          string            `json:"coin"`
	AcceptedCoins []string          `json:"accepted_coins"`
	Interval      string            `json:"interval"` // weekly, monthly, yearly
	Active        bool              `json:"active"`
	Metadata      map[string]string `json:"metadata,omitempty"`
	Created       int64             `json:"created"`
}

SubscriptionPlan represents a subscription plan.

type SubscriptionPlanList

type SubscriptionPlanList struct {
	Object     string             `json:"object"`
	Data       []SubscriptionPlan `json:"data"`
	HasMore    bool               `json:"has_more"`
	NextCursor string             `json:"next_cursor,omitempty"`
}

SubscriptionPlanList is one page of subscription plans.

type SubscriptionPlansResource

type SubscriptionPlansResource struct {
	// contains filtered or unexported fields
}

SubscriptionPlansResource exposes /subscription-plans-* endpoints.

func (*SubscriptionPlansResource) List

List returns subscription plans.

type SubscriptionPortalResult

type SubscriptionPortalResult struct {
	PortalURL string `json:"portal_url"`
	Token     string `json:"token"`
	ExpiresAt int64  `json:"expires_at,omitempty"`
}

SubscriptionPortalResult is the response from POST /subscriptions-portal.

type SubscriptionResumeResult

type SubscriptionResumeResult struct {
	ID               string `json:"id"`
	Status           string `json:"status"`
	CurrentPeriodEnd int64  `json:"current_period_end"`
}

SubscriptionResumeResult is the response from POST /subscriptions-resume.

type SubscriptionsResource

type SubscriptionsResource struct {
	// contains filtered or unexported fields
}

SubscriptionsResource exposes /subscriptions-* endpoints.

func (*SubscriptionsResource) Cancel

func (r *SubscriptionsResource) Cancel(ctx context.Context, id string, atPeriodEnd bool, opts ...RequestOption) (*Subscription, error)

Cancel cancels a subscription (at period end by default).

func (*SubscriptionsResource) List

List returns one page of subscriptions.

func (*SubscriptionsResource) Pause

Pause pauses an active subscription. Pass empty token when authenticating with an API key.

func (*SubscriptionsResource) Portal

Portal generates a customer portal URL for the subscription.

func (*SubscriptionsResource) Resume

Resume resumes a paused subscription.

func (*SubscriptionsResource) Retrieve

func (r *SubscriptionsResource) Retrieve(ctx context.Context, id string, opts ...RequestOption) (*Subscription, error)

type Topup

type Topup struct {
	ID         string `json:"id"`
	Object     string `json:"object"`
	AmountSats string `json:"amount_sats"`
	Status     string `json:"status"`
	Address    string `json:"address,omitempty"`
	Bolt11     string `json:"bolt11,omitempty"`
	Created    int64  `json:"created"`
}

Topup is a prepaid-credit top-up invoice.

type TopupCreateParams

type TopupCreateParams struct {
	AmountSats string `json:"amount_sats"`
}

TopupCreateParams is the body for POST /credits-topup-create.

type TopupsResource

type TopupsResource struct {
	// contains filtered or unexported fields
}

TopupsResource exposes /credits-topup-* endpoints.

func (*TopupsResource) Create

func (r *TopupsResource) Create(ctx context.Context, p *TopupCreateParams, opts ...RequestOption) (*Topup, error)

func (*TopupsResource) Retrieve

func (r *TopupsResource) Retrieve(ctx context.Context, id string, opts ...RequestOption) (*Topup, error)

type WebhookCreateParams

type WebhookCreateParams struct {
	URL           string   `json:"url"`
	EnabledEvents []string `json:"enabled_events,omitempty"`
}

WebhookCreateParams is the body for POST /webhooks-create.

type WebhookEndpoint

type WebhookEndpoint struct {
	ID            string   `json:"id"`
	Object        string   `json:"object"`
	URL           string   `json:"url"`
	EnabledEvents []string `json:"enabled_events"`
	Status        string   `json:"status"`
	Secret        string   `json:"secret,omitempty"` // only on create
	Created       int64    `json:"created"`
}

WebhookEndpoint is a registered webhook destination.

type WebhookReplayResult

type WebhookReplayResult struct {
	ID           string `json:"id"`
	Event        string `json:"event"`
	ReplayedFrom string `json:"replayed_from"`
	Status       string `json:"status"`
}

WebhookReplayResult is the response from POST /webhooks-replay.

type WebhooksResource

type WebhooksResource struct {
	// contains filtered or unexported fields
}

WebhooksResource exposes /webhooks-* endpoints. Use the package-level ConstructEvent helper to verify incoming signatures.

func (*WebhooksResource) Create

func (*WebhooksResource) Delete

func (r *WebhooksResource) Delete(ctx context.Context, id string, opts ...RequestOption) error

func (*WebhooksResource) Replay

func (r *WebhooksResource) Replay(ctx context.Context, id, deliveryID string, opts ...RequestOption) (*WebhookReplayResult, error)

Replay re-delivers a previously sent event to a webhook endpoint. Pass an empty deliveryID to replay the most recent failed delivery.

func (*WebhooksResource) Test

func (r *WebhooksResource) Test(ctx context.Context, id string, opts ...RequestOption) error

Source Files

  • credits.go
  • customers.go
  • errors.go
  • events.go
  • http.go
  • invoices.go
  • keys.go
  • logs.go
  • nakopay.go
  • payment_links.go
  • rates.go
  • refunds.go
  • sandbox.go
  • subscriptions.go
  • webhook.go
  • webhooks.go

Jump to

Keyboard shortcuts

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