Go Module: kkhay-gov1.0.4Zero Dependencies
Go (Golang) SDK
The official Go SDK for K Khay Gateway. Built with zero external dependencies using the Go standard library (net/http, crypto/hmac, encoding/json). Optimized for microservices, Gin, Echo, and Fiber.
1. Installation
Go Modules
$go get github.com/boboaungdev/kkhay-go
2. Client Initialization & Invoice Creation
main.go
package main import ( "context" "fmt" "log" "os" kkhay "github.com/boboaungdev/kkhay-go") func main() { client := kkhay.NewClient(os.Getenv("KKHAY_API_KEY")) // Create an invoice invoice, err := client.CreateInvoice(context.Background(), &kkhay.CreateInvoiceParams{ Amount: 49.99, Currency: "USD", PayNetwork: "bsc", // Optional network (bsc, base, solana, btc) PayToken: "USDT", // Optional token OrderID: "ORDER-8821", Title: "Pro Cloud Server", CustomerEmail: "ops@company.io", RedirectURL: "https://company.io/billing/success", }) if err != nil { log.Fatalf("Failed to create invoice: %v", err) } fmt.Printf("Invoice Created: %s\n", invoice.ID) fmt.Printf("Checkout URL: %s\n", invoice.HostedURL)}3. Webhook Signature Verification (HTTP Server)
webhook.go
package main import ( "io" "net/http" "os" kkhay "github.com/boboaungdev/kkhay-go") func handleWebhook(w http.ResponseWriter, r *http.Request) { body, err := io.ReadAll(r.Body) if err != nil { http.Error(w, "Cannot read body", http.StatusBadRequest) return } signature := r.Header.Get("x-kkhay-signature") secret := os.Getenv("KKHAY_WEBHOOK_SECRET") event, err := kkhay.ParseWebhookEvent(body, signature, secret) if err != nil { http.Error(w, "Invalid signature", http.StatusUnauthorized) return } if event.Event == "payment.finished" || event.Event == "payment.paid" { // Fulfill order in database: event.OrderID, event.TxHash } w.WriteHeader(http.StatusOK)}