Official Ruby gem for the K Khay Sovereign Crypto Payment Gateway.
Accept non-custodial and custodial crypto payments (USDT, USDC, BNB, ETH across BSC, Polygon, Arbitrum, Base, and Ethereum) directly in Ruby on Rails, Sinatra, Hanami, or standalone Ruby backends with zero external dependencies.
Add to your application's Gemfile:
gem "kkhay"And then execute:
bundle installOr install it directly:
gem install kkhayKkhay.configure do |config|
config.api_key = ENV["KKHAY_API_KEY"]
# config.base_url = "https://api.kkhay.com" # default
# config.timeout = 30 # default in seconds
endclient = Kkhay.client
response = client.create_invoice(
price_amount: 49.99,
price_currency: "USD",
pay_network: "bsc",
pay_token: "USDT",
order_id: "ORDER-7721",
title: "Pro Membership",
customer_email: "buyer@example.com",
redirect_url: "https://myshop.com/orders/success",
cancel_url: "https://myshop.com/cart"
)
invoice = response[:invoice]
puts "Invoice ID: #{invoice[:id]}"
puts "Hosted Checkout URL: #{invoice[:hostedUrl]}"data = client.get_invoice("inv_9f81a7b2")
puts "Status: #{data[:invoice][:status]}"
data[:payments].each do |payment|
puts "Tx: #{payment[:txHash]} (#{payment[:confirmations]} confirmations)"
endclass KkhayWebhooksController < ApplicationController
skip_before_action :verify_authenticity_token
def create
payload = request.raw_post
signature = request.headers["x-kkhay-signature"]
secret = ENV["KKHAY_IPN_SECRET"]
event = Kkhay::Webhook.parse_event(payload, signature, secret)
if event[:event] == "payment.finished"
order = Order.find_by(id: event[:order_id])
order&.update!(status: "paid", tx_hash: event[:tx_hash])
end
head :ok
rescue Kkhay::SignatureVerificationError => e
render json: { error: e.message }, status: :bad_request
end
endMIT © K Khay