I haven't done Ruby in 5+ years and this reminder to myself how to kick start the bitpay-sdk gem to work with BTCPay Server.
No idea.
This guide is a butchered version of bitpay-sdk GUIDE.md
- Working BTCPay Server
- A store configured in BTCPay
In BTCPay Server visit Stores > select Your Store > Access Token > Create a new token.
Set Label
as Ruby
and leave PublicKey
blank and press Request pairing.
In Pairing permission choose Your Store in Pair to
and press Approve.
Grab a the Server initiated pairing code and keep it handy.
- Install gem
- Generate private key (keep this!)
- Pair and grab token (keep this!)
gem i bitpay-sdk
# OpenSSL v3 via https://github.com/bitpay/bitpay-ruby-keyutils/issues/3
ruby -rbitpay_sdk -e'puts OpenSSL::PKey::EC.generate("secp256k1").to_pem' > btcpay.pem
# OpenSSL v2
#ruby -rbitpay_sdk -e'puts BitPay::KeyUtils.generate_pem' > btcpay.pem
# pair.rb
require 'bitpay_sdk'
API_URI = 'YOUR_BTCPAY_INSTANCE'
client = BitPay::SDK::Client.new(
api_uri: API_URI,
pem: File.read('btcpay.pem'),
debug: true # Optional
)
puts client.pair_client(pairingCode: 'YOUR_PAIRING_CODE')
$ ruby pair.rb
The output contains a token
property. Capture this! If you loose it, you can refresh the 'Access Tokens' page to find it.
# invoice.rb
require 'bitpay_sdk'
API_URI = 'YOUR_BTCPAY_INSTANCE'
RUBY_TOKEN = 'YOUR_RUBY_ACCESS_TOKEN'
client = BitPay::SDK::Client.new(
api_uri: API_URI,
pem: File.read('btcpay.pem'),
tokens: {
'merchant' => RUBY_TOKEN, # default facade for get_invoice
'pos' => RUBY_TOKEN # default facade for create_invoice
},
debug: true # Optional
)
puts client.create_invoice(price: 1, currency: 'EUR')
$ ruby invoice.rb
Time for a challenge, try fetching the above created invoice.