liberty_reserve_link 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +48 -2
- data/lib/liberty_reserve_link/sci.rb +54 -0
- data/lib/liberty_reserve_link/version.rb +1 -1
- data/lib/liberty_reserve_link.rb +1 -0
- data/spec/models/sci_spec.rb +18 -0
- metadata +5 -2
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# LibertyReserveLink
|
2
2
|
|
3
|
-
|
3
|
+
LibertyReserveLink is a library to communicate with [Liberty Reserve](http://libertyreserve.com) API and SCI
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,53 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Create a credential object:
|
22
|
+
|
23
|
+
cred = LibertyReserveLink::Credential.new("account_name", "secret", "api_name")
|
24
|
+
|
25
|
+
For API create Client object:
|
26
|
+
|
27
|
+
api = LibertyReserveLink::Client.new(cred)
|
28
|
+
|
29
|
+
For SCI create Sci object:
|
30
|
+
|
31
|
+
sci = LibertyReserveLink::Sci.new(cred)
|
32
|
+
|
33
|
+
## API
|
34
|
+
|
35
|
+
To get balance:
|
36
|
+
|
37
|
+
api.balance
|
38
|
+
=> {"Euro" => 0.0, "Usd" => 0.0, "GoldGram" => 0.0}
|
39
|
+
|
40
|
+
api_balance("usd")
|
41
|
+
=> 0.0
|
42
|
+
|
43
|
+
To make a trasfer:
|
44
|
+
|
45
|
+
api.transfer(receiver, amount, currency, memo)
|
46
|
+
|
47
|
+
## SCI
|
48
|
+
|
49
|
+
To generate URL to LibertyReserve payment processing:
|
50
|
+
|
51
|
+
sci.payment_uri(amount, currency, order_id, item_name, options={})
|
52
|
+
|
53
|
+
Options can be one of (See [LR SCI Guide](http://www.libertyreserve.com/en/help/sciguide) for more info):
|
54
|
+
|
55
|
+
* `lr_acc_from` - Buyer's account number.
|
56
|
+
* `lr_comments` - Memo, that Merchant may want to include along with payment.
|
57
|
+
* `lr_success_url` - URL address of payment successful page at the Merchant's web site.
|
58
|
+
* `lr_success_url_method` - Payment successful page redirect HTTP method.
|
59
|
+
* `lr_fail_url` - URL address of payment failed page at the Merchant's web site.
|
60
|
+
* `lr_fail_url_method` - Payment failed page redirect HTTP method.
|
61
|
+
* `lr_status_url` - URL address of payment status page at the Merchant's web site or E-mail address to send a successful payment notification via e-mail.
|
62
|
+
* `lr_status_url_method` - payment status form data transmit HTTP method.
|
63
|
+
|
64
|
+
To validate callback from LibertyReserve in controller:
|
65
|
+
|
66
|
+
sci.valid?(params)
|
67
|
+
|
22
68
|
|
23
69
|
## Contributing
|
24
70
|
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
class LibertyReserveLink::Sci
|
4
|
+
|
5
|
+
ENDPOINT = 'https://sci.libertyreserve.com'
|
6
|
+
ALLOWED_OPTIONS = %w{lr_acc_from lr_comments lr_success_url lr_success_url_method lr_fail_url lr_fail_url_method lr_status_url lr_status_url_method}
|
7
|
+
|
8
|
+
def initialize(credential)
|
9
|
+
@credential = credential
|
10
|
+
check_credential
|
11
|
+
end
|
12
|
+
|
13
|
+
def check_credential
|
14
|
+
raise LibertyReserveLink::Client::InvalidCredentialException unless @credential.valid?
|
15
|
+
end
|
16
|
+
|
17
|
+
def account
|
18
|
+
@credential.account
|
19
|
+
end
|
20
|
+
|
21
|
+
def name
|
22
|
+
@credential.name
|
23
|
+
end
|
24
|
+
|
25
|
+
def secret
|
26
|
+
@credential.secret
|
27
|
+
end
|
28
|
+
|
29
|
+
def escape_options options
|
30
|
+
options.reject {|k, v| !(ALLOWED_OPTIONS.include? k.to_s)}
|
31
|
+
end
|
32
|
+
|
33
|
+
def payment_request_uri(amount, currency, order_id, item_name, options={})
|
34
|
+
endpoint = URI.parse ENDPOINT
|
35
|
+
@query = {lr_acc: account, lr_store: name, lr_amnt: amount,
|
36
|
+
lr_currency: currency, lr_merchant_ref: order_id,
|
37
|
+
item_name: item_name, order_id: order_id
|
38
|
+
}.merge(escape_options(options))
|
39
|
+
endpoint.query = @query.to_query
|
40
|
+
endpoint.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def hash(input)
|
44
|
+
Digest::SHA256.new.digest(input).unpack('H*').first.upcase
|
45
|
+
end
|
46
|
+
|
47
|
+
def prepare_string(params)
|
48
|
+
"#{account}:#{params[:lr_paidby]}:#{name.gsub(/\\\//, '')}:#{params[:lr_amnt]}:#{params[:lr_transfer]}:#{params[:lr_currency]}:#{secret}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def valid?(params)
|
52
|
+
params[:lr_encrypted] == hash(prepare_string(params)) && params[:lr_paidto] == account
|
53
|
+
end
|
54
|
+
end
|
data/lib/liberty_reserve_link.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe LibertyReserveLink::Sci do
|
6
|
+
let(:credential) { LibertyReserveLink::Credential.new("account", "secret", "name") }
|
7
|
+
let(:sci) { LibertyReserveLink::Sci.new(credential) }
|
8
|
+
let(:sci_options) { sci.escape_options options }
|
9
|
+
let(:options) { {:valenok => "valenok", :test => "test", :lr_success_url => "url"} }
|
10
|
+
|
11
|
+
it "filter options" do
|
12
|
+
expect(sci_options.keys).to eq [:lr_success_url]
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns hash" do
|
16
|
+
expect(sci.hash("test")).to eq "9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08"
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liberty_reserve_link
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -139,11 +139,13 @@ files:
|
|
139
139
|
- lib/liberty_reserve_link.rb
|
140
140
|
- lib/liberty_reserve_link/client.rb
|
141
141
|
- lib/liberty_reserve_link/credential.rb
|
142
|
+
- lib/liberty_reserve_link/sci.rb
|
142
143
|
- lib/liberty_reserve_link/token.rb
|
143
144
|
- lib/liberty_reserve_link/version.rb
|
144
145
|
- liberty_reserve_link.gemspec
|
145
146
|
- spec/models/client_spec.rb
|
146
147
|
- spec/models/credential_spec.rb
|
148
|
+
- spec/models/sci_spec.rb
|
147
149
|
- spec/models/token_spec.rb
|
148
150
|
- spec/spec_helper.rb
|
149
151
|
homepage: ''
|
@@ -174,5 +176,6 @@ summary: Library for communicating with LibertyReserve API and SCI
|
|
174
176
|
test_files:
|
175
177
|
- spec/models/client_spec.rb
|
176
178
|
- spec/models/credential_spec.rb
|
179
|
+
- spec/models/sci_spec.rb
|
177
180
|
- spec/models/token_spec.rb
|
178
181
|
- spec/spec_helper.rb
|