payoneer-client 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +10 -0
- data/README.md +60 -4
- data/lib/payoneer/client.rb +43 -7
- data/lib/payoneer/configuration.rb +6 -2
- data/lib/payoneer/response.rb +0 -4
- data/payoneer-client.gemspec +3 -3
- data/spec/client_spec.rb +55 -0
- data/spec/spec_helper.rb +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b979e7078cae676e9250121313b692534a95d0d9
|
4
|
+
data.tar.gz: aa8d722834abe42c3c3e3ccf01c565e9564c5ed4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e91dfb81f67df1ac74223f6b504da96a7fe615f7353e6602d17a5682871bb81bfa3b05aff2063b2de48441e6517077d08db03c340eeb0547c14fff5bf7376357
|
7
|
+
data.tar.gz: b7b36d1580d962929f35436554337d99151097f0718f9349e5cca330bbcdda498cc7972b924b61621e4b2bcd5de1346d56da35bae43d1507e17def86755ef181
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
-
|
1
|
+
[![Build Status](https://travis-ci.org/tophatter/payoneer-api-ruby.svg?branch=master)](https://travis-ci.org/tophatter/payoneer-api-ruby)
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/github/tophatter/payoneer-api-ruby/badge.svg?branch=master)](https://coveralls.io/github/tophatter/payoneer-api-ruby?branch=master)
|
3
|
+
|
4
|
+
### Payoneer SDK for Ruby:
|
5
|
+
|
6
|
+
#### Install:
|
2
7
|
|
3
8
|
```
|
4
9
|
gem install payoneer-client
|
5
10
|
```
|
6
11
|
|
7
|
-
|
12
|
+
#### Usage:
|
8
13
|
|
9
14
|
```ruby
|
10
15
|
client = Payoneer::Client.new(
|
@@ -58,8 +63,59 @@ client.payee_details('fake-payee-id').body
|
|
58
63
|
"AccountNumber"=>"123456789",
|
59
64
|
"RoutingNumber"=>"121042882",
|
60
65
|
"AccountType"=>"S"}}
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
##### Performing a normal payout:
|
70
|
+
```ruby
|
71
|
+
response = client.payout(
|
72
|
+
program_id: 'fake-partner-id',
|
73
|
+
payment_id: 43,
|
74
|
+
amount: 100.0,
|
75
|
+
payee_id: 42,
|
76
|
+
description: "Foo Bar's order"
|
77
|
+
)
|
78
|
+
|
79
|
+
response.body
|
80
|
+
=> {
|
81
|
+
"Description" => "",
|
82
|
+
"PaymentID" => "1234",
|
83
|
+
"Status" => "000",
|
84
|
+
"PayoneerID" => "42"
|
85
|
+
}
|
86
|
+
````
|
87
|
+
|
88
|
+
##### Performing a payout with expanded params:
|
89
|
+
If the orders type is `"url"`, `credentials` must be a dictionary containing one of the following:
|
90
|
+
- `type: "AUTHORIZATION"` with a required `token` field
|
91
|
+
- `type: "PASSWORD"` with required `user_name` and `password` fields
|
92
|
+
```ruby
|
93
|
+
response = client.expanded_payout(
|
94
|
+
payee_id: 42,
|
95
|
+
client_reference_id: 43,
|
96
|
+
amount: 100.0,
|
97
|
+
currency: 'USD',
|
98
|
+
description: "Foo Bar's order",
|
99
|
+
seller_id: 44,
|
100
|
+
seller_name: "Foo Bar",
|
101
|
+
seller_url: "foo@bar.com",
|
102
|
+
seller_type: 'ECOMMERCE',
|
103
|
+
path: 'orders@path.com',
|
104
|
+
credentials: { type: 'AUTHORIZATION', token: 'fake_token'}
|
105
|
+
)
|
106
|
+
|
107
|
+
response.body
|
108
|
+
=> {
|
109
|
+
"audit_id" => 123456789,
|
110
|
+
"code" => 0,
|
111
|
+
"description" => "Success",
|
112
|
+
"payout_id" => "1234",
|
113
|
+
"amount" => 100.0,
|
114
|
+
"currency" => "USD",
|
115
|
+
"PaymentID" => "1234"
|
116
|
+
}
|
61
117
|
```
|
62
118
|
|
63
|
-
|
119
|
+
#### Console:
|
64
120
|
|
65
|
-
After checking out the repo, run `bin/payoneer-console` for an interactive
|
121
|
+
After checking out the repo, run `bin/payoneer-console` for an interactive console that will allow you to experiment.
|
data/lib/payoneer/client.rb
CHANGED
@@ -39,6 +39,47 @@ module Payoneer
|
|
39
39
|
)
|
40
40
|
end
|
41
41
|
|
42
|
+
# Includes additional items as needed to be Payoneer SAFE compliant
|
43
|
+
def expanded_payout(payee_id:, client_reference_id:, amount:, currency:, description:, payout_date: Time.now, seller_id:, seller_name:, seller_url:, seller_type: 'ECOMMERCE', orders_type: 'url', path:, credentials:)
|
44
|
+
params = {
|
45
|
+
payee_id: payee_id,
|
46
|
+
client_reference_id: client_reference_id,
|
47
|
+
amount: amount,
|
48
|
+
currency: currency,
|
49
|
+
description: description,
|
50
|
+
payout_date: payout_date.strftime('%Y-%m-%d'),
|
51
|
+
orders_report: {
|
52
|
+
merchant: {
|
53
|
+
id: seller_id,
|
54
|
+
store: {
|
55
|
+
name: seller_name,
|
56
|
+
url: seller_url,
|
57
|
+
type: seller_type
|
58
|
+
}
|
59
|
+
},
|
60
|
+
orders: {
|
61
|
+
type: orders_type,
|
62
|
+
path: path,
|
63
|
+
credentials: credentials
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
encoded_credentials = 'Basic ' + Base64.encode64("#{configuration.username}:#{configuration.api_password}").chomp
|
69
|
+
response = RestClient.post "#{configuration.json_base_uri}/payouts", params.to_json, content_type: 'application/json', accept: :json, Authorization: encoded_credentials
|
70
|
+
raise ResponseError.new(code: response.code, body: response.body) if response.code != 200
|
71
|
+
|
72
|
+
hash = JSON.parse(response.body)
|
73
|
+
hash['PaymentID'] = hash['payout_id'] # Keep consistent with the normal payout response body
|
74
|
+
|
75
|
+
if hash.key?('Code')
|
76
|
+
Response.new(hash['Code'], hash['Description'])
|
77
|
+
else
|
78
|
+
hash = block_given? ? yield(hash) : hash
|
79
|
+
Response.new(Response::OK_STATUS_CODE, hash)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
42
83
|
def payout_details(payee_id:, payment_id:)
|
43
84
|
post('GetPaymentStatus', p4: payee_id, p5: payment_id)
|
44
85
|
end
|
@@ -46,7 +87,7 @@ module Payoneer
|
|
46
87
|
private
|
47
88
|
|
48
89
|
def post(method_name, params = {})
|
49
|
-
response = RestClient.post(configuration.
|
90
|
+
response = RestClient.post(configuration.xml_base_uri, {
|
50
91
|
mname: method_name,
|
51
92
|
p1: configuration.username,
|
52
93
|
p2: configuration.api_password,
|
@@ -61,12 +102,7 @@ module Payoneer
|
|
61
102
|
if hash.key?('Code')
|
62
103
|
Response.new(hash['Code'], hash['Description'])
|
63
104
|
else
|
64
|
-
hash =
|
65
|
-
yield(hash)
|
66
|
-
else
|
67
|
-
hash
|
68
|
-
end
|
69
|
-
|
105
|
+
hash = block_given? ? yield(hash) : hash
|
70
106
|
Response.new(Response::OK_STATUS_CODE, hash)
|
71
107
|
end
|
72
108
|
end
|
@@ -18,8 +18,12 @@ module Payoneer
|
|
18
18
|
@host || 'api.payoneer.com'
|
19
19
|
end
|
20
20
|
|
21
|
-
def
|
22
|
-
@
|
21
|
+
def xml_base_uri
|
22
|
+
@xml_base_uri || "#{protocol}://#{host}/Payouts/HttpApi/API.aspx"
|
23
|
+
end
|
24
|
+
|
25
|
+
def json_base_uri
|
26
|
+
@json_base_uri || "#{protocol}://#{host}/v2/programs/#{@partner_id}"
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
data/lib/payoneer/response.rb
CHANGED
data/payoneer-client.gemspec
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# gem push payoneer-client-{VERSION}.gem
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'payoneer-client'
|
6
|
-
s.version = '0.
|
6
|
+
s.version = '0.4'
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.licenses = ['MIT']
|
9
9
|
s.authors = ['Chris Estreich']
|
@@ -14,10 +14,10 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.extra_rdoc_files = ['README.md']
|
16
16
|
|
17
|
-
s.required_ruby_version = '~> 2.
|
17
|
+
s.required_ruby_version = '~> 2.2'
|
18
18
|
|
19
|
-
s.add_dependency 'rest-client', '~> 1.6'
|
20
19
|
s.add_dependency 'activesupport', '~> 4.2'
|
20
|
+
s.add_dependency 'rest-client', '~> 1.6'
|
21
21
|
|
22
22
|
s.files = `git ls-files`.split("\n")
|
23
23
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/spec/client_spec.rb
CHANGED
@@ -83,4 +83,59 @@ describe Payoneer::Client do
|
|
83
83
|
expect(response.body).to include('FirstName' => 'Foo', 'LastName' => 'Bar')
|
84
84
|
end
|
85
85
|
end
|
86
|
+
|
87
|
+
describe '#expanded_payout' do
|
88
|
+
let(:payee_id) { 42 }
|
89
|
+
let(:client_reference_id) { 43 }
|
90
|
+
let(:amount) { 100 }
|
91
|
+
let(:currency) { 'USD' }
|
92
|
+
let(:description) { (Time.now - 10.days).strftime('%Y-%m-%d') }
|
93
|
+
let(:seller_id) { 44 }
|
94
|
+
let(:seller_name) { 'Fake Seller' }
|
95
|
+
let(:seller_url) { 'http://tophatter.dev/users/1' }
|
96
|
+
let(:path) { 'fake_s3@path.com' }
|
97
|
+
let(:credentials) { { type: 'AUTHORIZATION', token: 'fake' } }
|
98
|
+
let(:endpoint) { "#{configuration.json_base_uri}/payouts" }
|
99
|
+
let(:headers) { { content_type: 'application/json', accept: :json, Authorization: 'Basic ' + Base64.encode64("#{configuration.username}:#{configuration.api_password}").chomp } }
|
100
|
+
let(:response) do
|
101
|
+
mock = double
|
102
|
+
allow(mock).to receive(:code).and_return(200)
|
103
|
+
allow(mock).to receive(:body).and_return(params.to_json)
|
104
|
+
mock
|
105
|
+
end
|
106
|
+
|
107
|
+
let(:params) do
|
108
|
+
{ payee_id: payee_id,
|
109
|
+
client_reference_id: client_reference_id,
|
110
|
+
amount: amount,
|
111
|
+
currency: 'USD',
|
112
|
+
description: description,
|
113
|
+
payout_date: Time.now.strftime('%Y-%m-%d'),
|
114
|
+
orders_report: {
|
115
|
+
merchant: {
|
116
|
+
id: seller_id,
|
117
|
+
store: {
|
118
|
+
name: seller_name,
|
119
|
+
url: seller_url,
|
120
|
+
type: 'ECOMMERCE'
|
121
|
+
}
|
122
|
+
},
|
123
|
+
orders: {
|
124
|
+
type: 'url',
|
125
|
+
path: path,
|
126
|
+
credentials: credentials
|
127
|
+
}
|
128
|
+
} }
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'generates the correct response' do
|
132
|
+
expect(RestClient).to receive(:post).exactly(1).times.with(endpoint, params.to_json, headers).and_return(response)
|
133
|
+
response = client.expanded_payout(payee_id: payee_id, client_reference_id: client_reference_id, amount: amount, description: description, currency: currency, seller_id: seller_id, seller_name: seller_name, seller_url: seller_url, path: path, credentials: credentials)
|
134
|
+
expect(response.ok?).to be_truthy
|
135
|
+
expect(response.body).to include('payee_id' => payee_id, 'amount' => amount)
|
136
|
+
expect(response.body).to include('orders_report')
|
137
|
+
expect(response.body['orders_report']).to include('orders')
|
138
|
+
expect(response.body['orders_report']['orders']).to include('path' => path)
|
139
|
+
end
|
140
|
+
end
|
86
141
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: payoneer-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Estreich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '4.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rest-client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.6'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '1.6'
|
41
41
|
description: Payoneer SDK for ruby.
|
42
42
|
email:
|
43
43
|
- chris@tophatter.com
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- ".gitignore"
|
52
52
|
- ".rspec"
|
53
53
|
- ".rubocop.yml"
|
54
|
+
- ".travis.yml"
|
54
55
|
- Gemfile
|
55
56
|
- LICENSE.md
|
56
57
|
- README.md
|
@@ -77,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
78
|
requirements:
|
78
79
|
- - "~>"
|
79
80
|
- !ruby/object:Gem::Version
|
80
|
-
version: '2.
|
81
|
+
version: '2.2'
|
81
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
83
|
requirements:
|
83
84
|
- - ">="
|
@@ -85,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
86
|
version: '0'
|
86
87
|
requirements: []
|
87
88
|
rubyforge_project:
|
88
|
-
rubygems_version: 2.6.
|
89
|
+
rubygems_version: 2.6.13
|
89
90
|
signing_key:
|
90
91
|
specification_version: 4
|
91
92
|
summary: Payoneer SDK for ruby.
|