forked from liqpay/sdk-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Oleg Kukareka
committed
Apr 20, 2015
1 parent
adaaae2
commit c9dca31
Showing
11 changed files
with
189 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
*.iml | ||
*.idea | ||
Gemfile.lock | ||
*.gem | ||
spec/dummy/config.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,66 @@ | ||
sdk-ruby | ||
======== | ||
# Ruby gem for LiqPay.com API | ||
|
||
Ruby gem wrapper for official Liqpay SDK https://github.com/liqpay/sdk-ruby | ||
|
||
## Installation | ||
|
||
Add the gem to your Gemfile: | ||
|
||
```ruby | ||
gem 'novaposhta2', github: 'kukareka/novaposhta2' | ||
``` | ||
|
||
And don't forget to run Bundler: | ||
|
||
```shell | ||
$ bundle install | ||
``` | ||
|
||
## Configuration | ||
|
||
Get API keys on https://www.liqpay.com/ and save them in config: | ||
|
||
```ruby | ||
# 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 | ||
|
||
```ruby | ||
require 'liqpay' | ||
liqpay = Liqpay.new | ||
liqpay.api 'invoice/send', { email: '[email protected]', amount: 100, currency: 'UAH', | ||
order_id: 1, | ||
goods: [{ | ||
amount: 100, | ||
count: 1, | ||
unit: 'pcs', | ||
name: 'Order' }]} | ||
``` | ||
|
||
Full Liqpay API documentation is available on https://www.liqpay.com/en/doc | ||
|
||
## 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`: | ||
|
||
```ruby | ||
# spec/dummy/config.rb | ||
::Liqpay.configure do |config| | ||
config.public_key = 'public_key' | ||
config.private_key = 'private_key' | ||
end | ||
``` | ||
|
||
|
||
|
||
|
||
LiqPay SDK-RUBY | ||
|
||
Documentation https://www.liqpay.com/ru/doc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'liqpay/config' | ||
require 'liqpay/client' | ||
require 'liqpay/coder' | ||
require 'liqpay/liqpay' | ||
|
||
module Liqpay | ||
def self.config # :nodoc: | ||
@config ||= ::Liqpay::Config.new | ||
end | ||
|
||
def self.new(*options) | ||
::Liqpay::Liqpay.new(*options) | ||
end | ||
|
||
def self.configure # :nodoc: | ||
yield config | ||
@config | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Liqpay | ||
class Config | ||
attr_accessor :private_key, :public_key, :version, :server_url, :return_url | ||
|
||
def initialize | ||
@private_key = ENV['LIQPAY_PRIVATE_KEY'] | ||
@public_key = ENV['LIQPAY_PUBLIC_KEY'] | ||
@version = 3 | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Gem::Specification.new do |s| | ||
s.name = 'liqpay' | ||
s.version = '0.0.1' | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ['Oleg Kukareka'] | ||
s.email = '[email protected]' | ||
s.homepage = 'https://github.com/kukareka/liqpay' | ||
s.summary = 'LiqPay.com Ruby SDK' | ||
s.description = 'Gem wrapper for official liqpay/sdk-ruby' | ||
s.homepage = 'https://github.com/kukareka/liqpay' | ||
s.required_ruby_version = '>= 1.9' | ||
|
||
s.rubyforge_project = 'liqpay' | ||
|
||
s.files = Dir['{lib}/**/*.rb'] | ||
s.require_path = 'lib' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'spec_helper' | ||
|
||
begin | ||
require File.expand_path('../../../dummy/config.rb', __FILE__) unless ENV['LIQPAY_PUBLIC_KEY'] && ENV['LIQPAY_PRIVATE_KEY'] | ||
rescue LoadError | ||
puts "Could not load API keys. Please provide API keys in ENV['LIQPAY_PUBLIC_KEY'] && ENV['LIQPAY_PRIVATE_KEY'] or spec/dummy/config.rb" | ||
end | ||
|
||
module Liqpay | ||
describe 'Invoice API' do | ||
before :all do | ||
@liqpay = Liqpay.new | ||
end | ||
it 'should be able to send and cancel invoices' do | ||
order_id = rand(1000) | ||
r = @liqpay.api 'invoice/send', { email: '[email protected]', amount: 100, currency: 'UAH', | ||
order_id: order_id, | ||
goods: [{ | ||
amount: 100, | ||
count: 1, | ||
unit: 'Order', | ||
name: "Order #{order_id}" }]} | ||
expect(r['result']).to eq 'ok' | ||
r = @liqpay.api 'invoice/cancel', {order_id: order_id} | ||
expect(r['result']).to eq 'ok' | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'spec_helper' | ||
|
||
module Liqpay | ||
describe ::Liqpay::Config do | ||
before :each do | ||
::Liqpay.configure do |c| | ||
c.private_key = 'private_key' | ||
c.public_key = 'public_key' | ||
end | ||
end | ||
|
||
it 'should have private key' do | ||
expect(::Liqpay.config.private_key).to eq 'private_key' | ||
end | ||
|
||
it 'should have public key' do | ||
expect(::Liqpay.config.public_key).to eq 'public_key' | ||
end | ||
|
||
it 'should reflect changes through block' do | ||
::Liqpay.configure do |c| | ||
c.private_key = 'private_key3' | ||
end | ||
expect(::Liqpay.config.private_key).to eq 'private_key3' | ||
end | ||
end | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'liqpay' |