LiqPay ruby sdk
Switch branches/tags
Nothing to show
Clone or download
Didovick Andrew
Latest commit a7a990f Jul 31, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib liqpay.com changed to liqpay.ua Jul 31, 2017
spec liqpay.com changed to liqpay.ua Jul 31, 2017
.gitignore Make gem Apr 20, 2015
README.md liqpay.com changed to liqpay.ua Jul 31, 2017
liqpay.gemspec liqpay.com changed to liqpay.ua Jul 31, 2017

README.md

Ruby gem for liqpay.ua API

Ruby gem wrapper for official Liqpay SDK https://github.com/liqpay/sdk-ruby

Installation

Add the gem to your Gemfile:

gem 'liqpay', github: 'liqpay/sdk-ruby'

And don't forget to run Bundler:

$ bundle install

Configuration

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']

Usage

Full Liqpay API documentation is available on https://www.liqpay.ua/en/doc

Api

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:   'телефон'
  }]
})

Checkout

html = liqpay.cnb_form({
  action:      "pay",
  amount:      "1",
  currency:    "USD",
  description: "description text",
  order_id:    "order_id_1",
  version:     "3"
})

Callback

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

Tests

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