Skip to content
ArionPay

Ruby gem

Accept crypto payments in your Ruby app

Create crypto invoices from your Rails, Sinatra or Rack app and check the signed webhook when the customer pays. The money goes straight to your own wallet.

Install

gem install arionpay
Source on GitHub
Example

What it does

ArionPay for Ruby developers

The arionpay gem is the official ArionPay client for Ruby 3.0 or newer, using only the standard library. It creates and reads invoices, checks webhook signatures on the raw body, and moves test invoices through payment scenarios.
Read moreInvoices are Hashes with the same field names as the webhook, so one method can handle a webhook and a read. ArionPay never holds the money: it goes straight to your own wallet.
  • No dependencies (standard library only). Ruby 3.0 or newer.
  • README examples for Rails, Sinatra and plain Rack. Hanami and plain scripts work too.
  • Every invoice request carries an idempotency key, so a network error can never create two invoices.
  • verify_webhook checks the signature on the raw body and raises ArionPay::SignatureError when it does not match or is more than 5 minutes old.
  • ArionPay.order_matches?(invoice, "49.90", "USD") checks the order total to the cent before you deliver.
  • A client is safe to share between threads (Puma, Sidekiq).
  • Bad arguments raise ArgumentError before anything is sent. API errors are ArionPay::APIError, and messages never contain your secret.

Requirements and licence

Works with
Ruby 3.0 or newer · Rails, Sinatra, Hanami, any Rack app or plain scripts · standard library only
Cost
The library is free. ArionPay charges 0.5% per payment, with no monthly fee.
Source
Open source (MIT) on GitHub.

Setup

Set it up in 5 steps

  1. Step 1

    Install the gem

    Run gem install arionpay, or add gem "arionpay" to your Gemfile.

  2. Step 2

    Copy your keys

    In your ArionPay dashboard, open your store and copy the API key (pk_) and the API secret (sk_, it asks for your authenticator code). The webhook signing secret (whsec_) is on the Webhooks page. Keep them in environment variables or Rails credentials.

  3. Step 3

    Create an invoice

    Call create_invoice with amount:, currency: and order_id:, then redirect the customer to invoice["invoiceUrl"].

  4. Step 4

    Check the webhook

    Set your webhook address on the Webhooks page, or per invoice with callback_url:. Pass the raw body (request.raw_post in Rails) and the ArionPay-Signature header to verify_webhook, and deliver on invoice.paid.

  5. Step 5

    Test without real money

    Create an invoice with test: true and an asset such as USDT_TRC20, then call simulate_payment(invoice["id"], "exact"). Your webhook gets invoice.paid, like a real payment.

After the setup

How a payment reaches your code

  • invoice.pending: a payment was seen on the network and waits for confirmations. Do not deliver yet.
  • invoice.paid: fully paid and confirmed, or accepted by you by hand in the dashboard. Deliver only on this event (or when get_invoice says paid). Coming back to success_url does not prove payment.
  • Before you deliver, match the invoice to your order: your order_id or metadata, and ArionPay.order_matches? for the amount and currency.
  • invoice.partial, invoice.expired and invoice.needs_review never mean deliver. A late payment can still make an expired invoice paid.
  • ArionPay sends again for about 3 days when your server does not answer 2xx. Handle each event["id"] once and answer quickly, sending emails from a background job.

16 coins and tokens on 9 networks

All coins
  • BTCBitcoin
  • ETHEthereum
  • USDTEthereum
  • USDCEthereum
  • BNBBNB Smart Chain
  • USDTBNB Smart Chain
  • USDCBNB Smart Chain
  • POLPolygon
  • USDTPolygon
  • USDCPolygon
  • TRXTRON
  • USDTTRON
  • LTCLitecoin
  • DOGEDogecoin
  • BCHBitcoin Cash
  • DASHDash

Questions about the ArionPay Ruby library

Short answers before you add it to your code.

Yes. In a controller based on ActionController::API, or with skip_forgery_protection, pass request.raw_post and request.headers["ArionPay-Signature"] to verify_webhook. Rescue ArionPay::SignatureError and answer 401.