Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

plisio-go

A zero-dependency, idiomatic Go client for the Plisio cryptocurrency payment gateway API.

Install

go get github.com/obeliskdev/plisio-go

Quick start

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/obeliskdev/plisio-go"
)

func main() {
	client := plisio.NewClient(os.Getenv("PLISIO_KEY")) // your SECRET_KEY

	inv, err := client.CreateInvoice(context.Background(),
		plisio.WithOrderName("order-1"),
		plisio.WithOrderNumber(1001),
		plisio.WithSourceAmount(20, plisio.USD), // 20 USD, converted to crypto
		plisio.WithAllowedCurrencies(plisio.BTC, plisio.ETH, plisio.USDT_TRX),
		plisio.WithCallbackURL("https://example.com/plisio/callback?json=true"),
		plisio.WithExpireMin(30),
	)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Pay at:", inv.InvoiceURL)
}

Handling callbacks

Append ?json=true to your callback URL, then validate and parse each POST:

func handler(w http.ResponseWriter, r *http.Request) {
	body, _ := io.ReadAll(r.Body)
	cb, err := client.ParseCallback(body)
	if err != nil {
		http.Error(w, "invalid", http.StatusUnprocessableEntity)
		return
	}
	if cb.Status == plisio.StatusCompleted {
		// fulfill the order for cb.OrderNumber
	}
	w.WriteHeader(http.StatusOK)
}

Amounts and numbers

Plisio does not guarantee a consistent JSON type for monetary fields, so every amount/rate is returned as plisio.Number:

f, _ := cb.Amount.Float64() // as float
s := cb.Amount.String()     // exact text, no precision loss
if cb.Amount.IsNull() { ... }

Endpoints

Method Description
GetBalance Cryptocurrency balance
GetCurrencies Supported cryptocurrencies
CreateInvoice Create a payment invoice
GetCommission Estimate commission + network fee
Withdraw Send crypto (single or mass cash-out)
GetFee Estimate network fee
GetFeePlan Available fee plans
GetOperations List transactions (paginated, filterable)
GetOperation Transaction details
ValidateCallback / ParseCallback Verify webhook signatures

License

MIT

About

Idiomatic, zero-dependency Go client for the Plisio crypto payment gateway API - functional options, precision-safe Number type, HMAC-SHA1 webhook validation

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages