lnpay

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2020 License: MIT Imports: 1 Imported by: 0

README

lnpay

Golang API wrapper for https://lnpay.co/.

Install

go get github.com/fiatjaf/lnpay

Usage

lnpaySecretKey := lnpay.TEST_KEY
// use your key here: "sak_..."
// you can find it at https://lnpay.co/developers/dashboard

client := lnpay.NewClient(lnpaySecretKey)
wallet, _ := client.CreateWallet("first wallet")

lntx, _ := wallet.Invoice(lnpay.InvoiceParams{
    Memo: "wallet funding",
    NumSatoshis: 1000,
    PassThru: map[string]interface{}{
        "useless_data": 123,
    },
})

fmt.Printf("created invoice with lntx_id %s and payment hash %s.\n", lntx.ID, lntx.RHashDecoded)

details, _ := wallet.Details()
fmt.Printf("wallet %s (%s) has a balance of %d satoshis.\n", details.ID, details.UserLabel, details.Balance)

wtx, _ := wallet.Pay(PayParams{PaymentRequest: "lnbc1..."})
fmt.Printf("sent payment of %d satoshis to node %s.\n", wtx.NumSatoshis, wtx.LnTx.DestPubKey)

Documentation

Index

Constants

View Source
const (
	BASE_URL = "https://lnpay.co/v1"
	TEST_KEY = "pak_O0iUMxk8kK_qUzkT4YKFvp1ZsUtp"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessKeys

type AccessKeys struct {
	WalletAdmin   []string `json:"Wallet Admin"`
	WalletInvoice []string `json:"Wallet Invoice"`
	WalletRead    []string `json:"Wallet Read"`
}

type Client

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

func NewClient

func NewClient(key string) *Client

NewClient is the first function you must call. Pass your main API key here. It will return a client you can later use to access wallets and transactions. You can find it at https://lnpay.co/developers/dashboard

func (*Client) CreateWallet

func (c *Client) CreateWallet(label string) (wal Wallet, err error)

CreateWallet creates a new wallet with a given descriptive label. It will return the wallet object which you can use to create invoices and payments. https://docs.lnpay.co/wallet/create-wallet

func (*Client) Transaction

func (c *Client) Transaction(lntxId string) (lnTx LnTx, err error)

Transaction

func (*Client) Wallet

func (c *Client) Wallet(key string) *Wallet

Wallet returns a wallet that was already created. Pass the wallet key you got when creating it. I can be either the admin, invoice or read-only key.

type Error

type Error struct {
	Name    string `json:"name"`
	Message string `json:"message"`
	Code    int    `json:"code"`
	Status  int    `json:"status"`
}

func (Error) Error

func (err Error) Error() string

type Event

type Event struct {
	Type        string `json:"type"`
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
}

type InvoiceParams

type InvoiceParams struct {
	Memo        string `json:"memo"`         // the invoice description.
	NumSatoshis int64  `json:"num_satoshis"` // the invoice amount.
	Expiry      int64  `json:"expiry"`       // seconds, default 86400 (1 day).

	// custom data you may want to associate with this invoice. optional.
	PassThru map[string]interface{} `json:"passThru"`

	// base64-encoded. If this is provided, memo will be ignored.
	// don't use this if you don't know what it means.
	DescriptionHash string `json:"description_hash"`
}

type LnTx

type LnTx struct {
	ID              string                 `json:"id"`
	CreatedAt       int                    `json:"created_at"`
	DestPubkey      string                 `json:"dest_pubkey"`
	PaymentRequest  string                 `json:"payment_request"`
	RHashDecoded    string                 `json:"r_hash_decoded"`
	Memo            string                 `json:"memo"`
	DescriptionHash string                 `json:"description_hash"`
	NumSatoshis     int64                  `json:"num_satoshis"`
	Expiry          int                    `json:"expiry"`
	ExpiresAt       int                    `json:"expires_at"`
	PaymentPreimage string                 `json:"payment_preimage"`
	Settled         int                    `json:"settled"`
	SettledAt       int                    `json:"settled_at"`
	IsKeysend       bool                   `json:"is_keysend"`
	CustomRecords   map[string]interface{} `json:"custom_records"`
}

type PayParams

type PayParams struct {
	// the BOLT11 payment request you want to pay.
	PaymentRequest string `json:"payment_request"`

	// custom data you may want to associate with this invoice. optional.
	PassThru map[string]interface{} `json:"passThru"`
}

type Pywl

type Pywl struct {
	DestinationURL string                 `json:"destination_url"`
	Memo           string                 `json:"memo"`
	ShortURL       string                 `json:"short_url"`
	NumSatoshis    int64                  `json:"lnd_value"`
	CreatedAt      int                    `json:"created_at"`
	UpdatedAt      int                    `json:"updated_at"`
	Metadata       map[string]interface{} `json:"metadata"`
	ID             string                 `json:"id"`
	PaywallLink    string                 `json:"paywall_link"`
	CustyDomain    struct {
		DomainName string `json:"domain_name"`
	} `json:"custyDomain"`
	StatusType  StatusType `json:"statusType"`
	PaywallType struct {
		Name        string `json:"name"`
		DisplayName string `json:"display_name"`
		Description string `json:"description"`
	} `json:"paywallType"`
	Template struct {
		Layout string `json:"layout"`
	} `json:"template"`
	LinkExpRule struct {
		Type        string `json:"type"`
		Name        string `json:"name"`
		DisplayName string `json:"display_name"`
		TimeMinutes int    `json:"time_minutes"`
	} `json:"linkExpRule"`
}

type StatusType

type StatusType struct {
	Type        string `json:"type"`
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
}

type TransferParams

type TransferParams struct {
	Memo         string `json:"memo"`           // the transfer description.
	NumSatoshis  int64  `json:"num_satoshis"`   // the transfer amount.
	DestWalletId string `json:"dest_wallet_id"` // the key or id of the destination
}

type Wal

type Wal struct {
	ID         string      `json:"id"`
	UserLabel  string      `json:"user_label"`
	CreatedAt  int         `json:"created_at"`
	UpdatedAt  int         `json:"updated_at"`
	Balance    int64       `json:"balance"`
	StatusType StatusType  `json:"statusType"`
	AccessKeys *AccessKeys `json:"accessKeys"`
}

type Wallet

type Wallet struct {
	*Client
	Key      string
	BASE_URL string
}

func (*Wallet) Details

func (w *Wallet) Details() (wal Wal, err error)

Details returns basic information about a wallet, such as its id, label or balance. https://docs.lnpay.co/wallet/get-balance

func (*Wallet) Invoice

func (w *Wallet) Invoice(params InvoiceParams) (lntx LnTx, err error)

Invoice creates an invoice associated with this wallet. https://docs.lnpay.co/wallet/generate-invoice

func (*Wallet) Pay

func (w *Wallet) Pay(params PayParams) (wtx Wtx, err error)

Pay pays a given invoice with funds from the wallet. https://docs.lnpay.co/wallet/pay-invoice

func (*Wallet) Transactions

func (w *Wallet) Transactions() (txs []Wtx, err error)

Transactions returns a list of the transactions associated with the wallet. https://docs.lnpay.co/wallet/get-transactions

func (*Wallet) Transfer

func (w *Wallet) Transfer(params TransferParams) (wtx Wtx, err error)

Transfer transfers between two lnpay.co wallets. https://docs.lnpay.co/wallet/transfers-between-wallets

type WebhookPaywallConversion

type WebhookPaywallConversion struct {
	ID        string `json:"id"`
	CreatedAt int    `json:"created_at"`
	Event     Event  `json:"event"`
	Data      struct {
		Pywl Pywl `json:"pywl"`
		Wtx  Wtx  `json:"wtx"`
	} `json:"data"`
}

"paywall_conversion" webhook payload https://docs.lnpay.co/webhooks/getting-started#paywalls

type WebhookPaywallCreated

type WebhookPaywallCreated struct {
	ID        string `json:"id"`
	CreatedAt int    `json:"created_at"`
	Event     Event  `json:"event"`
	Data      struct {
		Pywl Pywl `json:"pywl"`
	} `json:"data"`
}

"paywall_created" webhook payload https://docs.lnpay.co/webhooks/getting-started#paywalls

type WebhookWalletCreated

type WebhookWalletCreated struct {
	CreatedAt int    `json:"created_at"`
	ID        string `json:"id"`
	Event     Event  `json:"event"`
	Data      struct {
		Wal Wal `json:"wal"`
	} `json:"data"`
}

"wallet_created" webhook payload https://docs.lnpay.co/webhooks/getting-started#payloads

type WebhookWalletInternalTransfer

type WebhookWalletInternalTransfer struct {
	ID        string `json:"id"`
	CreatedAt int    `json:"created_at"`
	Event     Event  `json:"event"`
	Data      struct {
		Wtx Wtx `json:"wtx"`
	} `json:"data"`
}

"wallet_receive" webhook payload https://docs.lnpay.co/webhooks/getting-started#payloads

type WebhookWalletReceive

type WebhookWalletReceive struct {
	CreatedAt int    `json:"created_at"`
	ID        string `json:"id"`
	Event     Event  `json:"event"`
	Data      struct {
		Wtx Wtx `json:"wtx"`
	} `json:"data"`
}

"wallet_transfer_IN/OUT" webhook payload https://docs.lnpay.co/webhooks/getting-started#payloads

type WebhookWalletSend

type WebhookWalletSend struct {
	CreatedAt int    `json:"created_at"`
	ID        string `json:"id"`
	Event     Event  `json:"event"`
	Data      struct {
		Wtx Wtx `json:"wtx"`
	} `json:"data"`
}

"wallet_send" webhook payload https://docs.lnpay.co/webhooks/getting-started#payloads

type Wtx

type Wtx struct {
	UserLabel string                 `json:"user_label"`
	CreatedAt int                    `json:"created_at"`
	ID        string                 `json:"id"`
	Wal       Wal                    `json:"wal"`
	WtxType   WtxType                `json:"wtxType"`
	LnTx      LnTx                   `json:"lnTx"`
	PassThru  map[string]interface{} `json:"passThru"`
}

type WtxType

type WtxType struct {
	Layer       string `json:"layer"`
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
}

Jump to

Keyboard shortcuts

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