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 > Settings > Access Token > Create token.
Set Label
as Ruby
and leave PublicKey
blank and press Request pairing.
In Pairing permission 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'
client = BitPay::SDK::Client.new(
api_uri: ENV["API_URI"],
pem: File.read('btcpay.pem'),
debug: true # Optional
)
puts client.pair_client(pairingCode: ENV["PAIRING_CODE"])
$ API_URI=YOUR_BTCPAY_INSTANCE PAIRING_CODE=YOUR_PAIDING_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'
client = BitPay::SDK::Client.new(
api_uri: ENV["API_URI"],
pem: File.read('btcpay.pem'),
tokens: {
'merchant' => ENV["RUBY_TOKEN"], # default facade for get_invoice
'pos' => ENV["RUBY_TOKEN"] # default facade for create_invoice
},
debug: true # Optional
)
puts client.create_invoice(price: 1, currency: 'EUR')
$ API_URI=YOUR_BTCPAY_INSTANCE RUBY_TOKEN=YOUR_RUBY_TOKEN ruby invoice.rb
Time for a challenge, try fetching the above created invoice.