Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ucashpay-go

A zero-dependency Go client for U.CASH Pay: create crypto + card checkouts and verify settlement webhooks. Non-custodial.

Install

go get github.com/UdotCASH/ucashpay-go

Create a checkout

import "github.com/UdotCASH/ucashpay-go"

client := ucashpay.New(os.Getenv("UCASH_CLOUD_TOKEN"), "https://pay.u.cash")

res, err := client.CreateCheckout("10.00", "USD", orderID, "Order #"+orderID, "https://yoursite.com/thanks")
if err != nil { /* ... */ }
if res.OK {
    http.Redirect(w, r, res.PaymentURL, http.StatusFound) // send buyer to hosted checkout
}

Verify a webhook

func webhook(w http.ResponseWriter, r *http.Request) {
    raw, _ := io.ReadAll(r.Body)
    sig := r.Header.Get("X-Webhook-Signature")
    client := ucashpay.New("", "")
    v := client.VerifyWebhook(string(raw), sig, os.Getenv("UCASH_WEBHOOK_SECRET"))
    if !v.Verified {
        http.Error(w, v.Error, http.StatusUnauthorized)
        return
    }
    // parse the body, mark the order paid, respond 200
    w.WriteHeader(http.StatusOK)
}

Set the webhook URL in pay.u.cash to your handler, save, then Test Webhook.

Set up your pay.u.cash account

  1. Sign up at pay.u.cash with email + password, then click the verification link in the email.
  2. Set your receive addresses under Settings → Addresses (a wallet per coin, or ENS/Unstoppable/FIO names). Crypto settles here.
  3. Create a store at Account → Stores → + Add Store.
  4. Copy the Store Cloud Token + Store Webhook Secret into your env. Use the store-level token, not the account-wide one.
  5. Set the webhook URL as above, then Test Webhook.

License

MIT.

About

U.CASH Pay client for Go: create crypto + card checkouts and verify settlement webhooks. Non-custodial, zero-dep.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages