在 Ruby on Rails 中接受加密货币收款 | Shieldz

在 Ruby on Rails 中接受加密货币收款

为你的 Ruby on Rails 应用添加non-custodial加密货币结账:创建一张发票、把买家引导到托管结账页,并在一个签名 webhook 上履约。资金直接结算到你自己的wallet,$0 平台手续费。

安装

# uses Net::HTTP (no extra gem needed)

创建一张发票并重定向到结账页

require "net/http"; require "json"
res = Net::HTTP.post(
  URI("https://shieldz.cash/api/v1/invoices"),
  { amount_usd_cents: 5000, memo: "Order" }.to_json,
  { "Authorization" => "Bearer #{ENV['SHIELDZ_API_KEY']}", "Content-Type" => "application/json" }
)
invoice = JSON.parse(res.body)
redirect_to invoice["pay_url"]

验证 webhook

# Verify HMAC over "#{t}.#{raw_body}"
def shieldz_paid?(raw, header, secret)
  t = header[/t=(\d+)/, 1]; return false unless t
  expected = OpenSSL::HMAC.hexdigest("SHA256", secret, "#{t}.#{raw}")
  header.scan(/v1=([0-9a-f]+)/).flatten.any? { |s| Rack::Utils.secure_compare(s, expected) }
end

完整参考:API 文档SDKAPI 参考

探索 Shieldz

接受某种币: Bitcoin, USDC, USDT, Zcash.

对比: 对比 Coinbase Commerce, 对比 BTCPay Server, 对比 CryptAPI, 对比 NOWPayments.

使用场景: 面向自由职业者, 面向创作者, 面向开源项目, 面向网店.

构建: SDK, API 参考, 快速上手. 了解: 概览, 博客, 工作原理, 支持的币种, 定价, 是否安全, 自行验证.