Ruby gem wrapper for official Liqpay SDK https://github.com/liqpay/sdk-ruby
Add the gem to your Gemfile:
gem'liqpay',git: 'https://github.com/liqpay/sdk-ruby.git'And don't forget to run Bundler:
$ bundle installGet API keys on https://www.liqpay.ua/ and save them in config (RoR):
# config/initializers/liqpay.rb
::Liqpay.configuredo |config|
config.public_key='public_key'config.private_key='private_key'endYou can also store API keys in ENV['LIQPAY_PUBLIC_KEY'] and ENV['LIQPAY_PRIVATE_KEY']
And for pure Ruby (liqpay_config.rb for example)
moduleLiqpayConfigdefself.configure
::Liqpay.configuredo |config|
config.public_key='public_key'config.private_key='private_key'endendendLiqpayConfig.configureAnd after that in main.rb or in another each
require'liqpay'require_relative'liqpay_config'Full Liqpay API documentation is available on https://www.liqpay.ua/en/doc
require'liqpay'liqpay=Liqpay.newliqpay.api('request',{action: 'invoice_send',version: '3',email: email,amount: '1',currency: 'USD',order_id: order_id,goods: [{amount: 100,count: 2,unit: 'шт.',name: 'телефон'}]})html=liqpay.cnb_form({action: "pay",amount: "1",currency: "USD",description: "description text",order_id: "order_id_1",version: "3"})data=request.parameters['data']signature=request.parameters['signature']ifliqpay.match?(data,signature)responce_hash=liqpay.decode_data(data)# Check responce_hash['status'] and process due to Liqpay API documentation.else# Wrong signature!endTo pass the API tests, specify API keys in ENV['LIQPAY_PUBLIC_KEY'] and ENV['LIQPAY_PRIVATE_KEY']
or in spec/dummy/config.rb:
# spec/dummy/config.rb
::Liqpay.configuredo |config|
config.public_key='public_key'config.private_key='private_key'endTo run local only tests(keys are not required), execute
rspec --tag ~@real
With real api test you can specify email to recive invoce from Liqpay:
LIQPAY_PUBLIC_KEY=real_public_key LIQPAY_PRIVATE_KEY=real_private_key TEST_EMAIL=real_email rspec --tag @real