Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ucashpay (Rails / Ruby)

A zero-dependency Ruby client for U.CASH Pay: create crypto + card checkouts and verify settlement webhooks. Non-custodial. Works in any Ruby app; idiomatic in Rails.

Install

# Gemfile
gem 'ucashpay'
bundle install

Create a checkout

client = UcashPay::Client.new(ENV['UCASH_CLOUD_TOKEN'])

r = client.create_checkout(
  amount: '10.00',
  currency: 'USD',
  external_reference: order.id,          # idempotent; returned in the webhook
  title: "Order ##{order.id}",
  redirect_url: order_url(order),
)

redirect_to r[:payment_url] if r[:ok]    # send the buyer to hosted checkout

Receive payments (webhook)

# config/routes.rb
post '/ucashpay/webhook', to: 'ucash_pay#webhook'
# app/controllers/ucash_pay_controller.rb
class UcashPayController < ApplicationController
  skip_before_action :verify_authenticity_token  # verified by HMAC instead

  def webhook
    client = UcashPay::Client.new(ENV['UCASH_CLOUD_TOKEN'])
    result = client.verify_webhook(
      request.raw_post,
      request.headers['X-Webhook-Signature'],
      ENV['UCASH_WEBHOOK_SECRET'],
    )
    return render json: { error: result[:error] }, status: :unauthorized unless result[:verified]

    tx = result[:transaction]
    order = Order.find(tx['transaction']['external_reference'])
    order.mark_paid!
    render json: { ok: true }
  end
end

Set the webhook URL in pay.u.cash to https://your-app.com/ucashpay/webhook, 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 Ruby/Rails: create crypto + card checkouts and verify settlement webhooks. Non-custodial, zero-dep.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages