Ruby gem wrapper for official Liqpay SDK https://github.com/liqpay/sdk-ruby
Add the gem to your Gemfile:
gem 'liqpay', github: 'liqpay/sdk-ruby'
And don't forget to run Bundler:
$ bundle install
Get API keys on https://www.liqpay.ua/ and save them in config:
# config/initializers/liqpay.rb
::Liqpay.configure do |config|
config.public_key = 'public_key'
config.private_key = 'private_key'
end
You can also store API keys in ENV['LIQPAY_PUBLIC_KEY']
and ENV['LIQPAY_PRIVATE_KEY']
Full Liqpay API documentation is available on https://www.liqpay.ua/en/doc
require 'liqpay'
liqpay = Liqpay.new
liqpay.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']
if liqpay.match?(data, signature)
responce_hash = liqpay.decode_data(data)
# Check responce_hash['status'] and process due to Liqpay API documentation.
else
# Wrong signature!
end
To 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.configure do |config|
config.public_key = 'public_key'
config.private_key = 'private_key'
end
To 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