payoneer_api 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 186608abc85884aea5d12fb594a9e9581ce6fde6
4
- data.tar.gz: 3f83e3d00cd6ebfe32759ffb7f95eaa228ec802c
3
+ metadata.gz: 33e43fd7651b0a58cdd851610958734328104830
4
+ data.tar.gz: d7ae4ae60dd310df87921b0f0c083ebdcd3443e4
5
5
  SHA512:
6
- metadata.gz: 5a000acb2128f7bd5ea79f6a84e409930b35955688bef4e1c01252b801c25c42ae652c51fa08d8e17465b8c49581e98e1b1f7bcee8c22b0eb2e13d0c37907435
7
- data.tar.gz: fb2456ececf88ad71a6d93b7615b8a01cef0d662462b31f68eb954a4b35cea6bde386c2e83ffd48b3ff5472c1d4d2f5d417591239266abec5abf5a95b7d87443
6
+ metadata.gz: 20b193951555db211b5ecd9896e060cc14c02ac175efaedb1fa4fe8e68aa250273b904a7096176de67c29c8fffdd7ab63a852006d2b2a7fedc0658300d9a9c6c
7
+ data.tar.gz: 6cdef89c4d3669568b7d948a6d9a2ce7c002e407d8adc323e727bab81246cb2c33a07c445e7f90d293330bdd17eaf692b5e789b4032e77138c45c2241cb691d7
@@ -1,4 +1,7 @@
1
1
  require 'net/http'
2
2
  require 'net/https'
3
+
4
+ require 'payoneer_api/core_ext/hash'
5
+
3
6
  require 'payoneer_api/payoneer_exception'
4
7
  require 'payoneer_api/client'
@@ -4,13 +4,22 @@ module PayoneerApi
4
4
  PRODUCTION_API_URL = 'https://api.payoneer.com/payouts/HttpAPI/API.aspx?'
5
5
  API_PORT = '443'
6
6
 
7
- def self.new_payee_link(partner_id, username, password, member_name)
8
- new(partner_id, username, password).payee_signup_url(member_name)
7
+ def self.new_payee_signup_url(member_name, options = {})
8
+ new(options).payee_signup_url(member_name)
9
+ end
10
+
11
+ def self.new_payee_prefilled_signup_url(member_name, options = {})
12
+ attributes = options.slice!(:partner_id, :username, :password)
13
+ new(options).payee_prefilled_signup_url(member_name, attributes)
9
14
  end
10
15
 
11
16
  def initialize(options = {})
12
17
  @partner_id, @username, @password = options[:partner_id], options[:username], options[:password]
18
+ @partner_id ||= ENV['PAYONEER_PARTNER_ID']
19
+ @username ||= ENV['PAYONEER_USERNAME']
20
+ @password ||= ENV['PAYONEER_PASSWORD']
13
21
  @environment = options[:environment]
22
+ @environment ||= ENV['PAYONEER_ENVIRONMENT']
14
23
  if @environment.nil? && defined?(Rails)
15
24
  Rails.env.production? ? 'production' : 'sandbox'
16
25
  end
@@ -47,13 +56,11 @@ module PayoneerApi
47
56
  end
48
57
 
49
58
  def api_error_description(response)
50
- return nil unless response and response.body
51
- body_hash = Nokogiri::XML.parse(response.body)
52
- if body_hash['PayoneerResponse']
53
- return body_hash['PayoneerResponse']['Description']
54
- else
55
- return body_hash.to_s
56
- end
59
+ return unless response and response.body
60
+ result = Nokogiri::XML.parse(response.body)
61
+ error_message = result.css('PayoneerResponse Description').first
62
+ return error_message if error_message
63
+ result.to_s
57
64
  end
58
65
 
59
66
  def get_api_call(args_hash)
@@ -133,11 +140,16 @@ module PayoneerApi
133
140
  end
134
141
  end
135
142
  end
136
- builder.to_xml#.tap { |x| puts x.inspect }
143
+ builder.to_xml#.tap { |x| puts x.to_s if sandbox? }
137
144
  end
138
145
 
139
146
  def api_url
140
- @environment.to_s == 'production' ? PRODUCTION_API_URL : SANDBOX_API_URL
147
+ sandbox? ? SANDBOX_API_URL : PRODUCTION_API_URL
148
+ end
149
+
150
+ def sandbox?
151
+ return true unless @environment
152
+ @environment.to_s != 'production'
141
153
  end
142
154
  end
143
155
  end
@@ -0,0 +1,44 @@
1
+ # Taken from activesupport
2
+
3
+ class Hash
4
+ # Slice a hash to include only the given keys. This is useful for
5
+ # limiting an options hash to valid keys before passing to a method:
6
+ #
7
+ # def search(criteria = {})
8
+ # criteria.assert_valid_keys(:mass, :velocity, :time)
9
+ # end
10
+ #
11
+ # search(options.slice(:mass, :velocity, :time))
12
+ #
13
+ # If you have an array of keys you want to limit to, you should splat them:
14
+ #
15
+ # valid_keys = [:mass, :velocity, :time]
16
+ # search(options.slice(*valid_keys))
17
+ def slice(*keys)
18
+ keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
19
+ keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if has_key?(k) }
20
+ end
21
+
22
+ # Replaces the hash with only the given keys.
23
+ # Returns a hash containing the removed key/value pairs.
24
+ #
25
+ # { a: 1, b: 2, c: 3, d: 4 }.slice!(:a, :b)
26
+ # # => {:c=>3, :d=>4}
27
+ def slice!(*keys)
28
+ keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true)
29
+ omit = slice(*self.keys - keys)
30
+ hash = slice(*keys)
31
+ hash.default = default
32
+ hash.default_proc = default_proc if default_proc
33
+ replace(hash)
34
+ omit
35
+ end
36
+
37
+ # Removes and returns the key/value pairs matching the given keys.
38
+ #
39
+ # { a: 1, b: 2, c: 3, d: 4 }.extract!(:a, :b) # => {:a=>1, :b=>2}
40
+ # { a: 1, b: 2 }.extract!(:a, :x) # => {:a=>1}
41
+ def extract!(*keys)
42
+ keys.each_with_object(self.class.new) { |key, result| result[key] = delete(key) if has_key?(key) }
43
+ end
44
+ end
@@ -1,8 +1,8 @@
1
1
  module PayoneerApi
2
2
  class Version
3
3
  MAJOR = 0
4
- MINOR = 0
5
- PATCH = 1
4
+ MINOR = 1
5
+ PATCH = 0
6
6
  PRE = nil
7
7
 
8
8
  class << self
@@ -0,0 +1,51 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.sandbox.payoneer.com/Payouts/HttpApi/API.aspx
6
+ body:
7
+ encoding: US-ASCII
8
+ string: mname=GetTokenXML&p1=Room5620&p2=12Gauh3uSe&p3=100035620&p4=1&xml=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0A%3CPayoneerDetails%3E%0A++%3CDetails%3E%0A++++%3CuserName%3ERoom5620%3C%2FuserName%3E%0A++++%3Cpassword%3E12Gauh3uSe%3C%2Fpassword%3E%0A++++%3Cprid%3E100035620%3C%2Fprid%3E%0A++++%3Capuid%3E1%3C%2Fapuid%3E%0A++%3C%2FDetails%3E%0A++%3CPersonalDetails%3E%0A++++%3Caddress1%2F%3E%0A++%3C%2FPersonalDetails%3E%0A%3C%2FPayoneerDetails%3E%0A
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - '*/*'
14
+ User-Agent:
15
+ - Ruby
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Cache-Control:
24
+ - no-cache, no-store, must-revalidate
25
+ Pragma:
26
+ - no-cache
27
+ Content-Type:
28
+ - text/html; charset=utf-8
29
+ Expires:
30
+ - '-1'
31
+ Set-Cookie:
32
+ - ASP.NET_SessionId=xrr5vet2zjf1nh330dbhx2y1; domain=.sandbox.payoneer.com;
33
+ path=/; secure; HttpOnly
34
+ - pid=100035620; domain=.sandbox.payoneer.com; expires=Fri, 01-May-2015 05:52:51
35
+ GMT; path=/; secure
36
+ P3p:
37
+ - CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
38
+ X-Powered-By:
39
+ - ASP.NET
40
+ Date:
41
+ - Fri, 02 May 2014 05:52:52 GMT
42
+ Content-Length:
43
+ - '185'
44
+ Connection:
45
+ - Keep-Alive
46
+ body:
47
+ encoding: UTF-8
48
+ string: <?xml version="1.0" encoding="UTF-8"?><PayoneerToken><Token>http://payouts.sandbox.payoneer.com/partners/lp.aspx?token=b8e8eab41931475cb4b66b54996a7cb1A9A9579049</Token></PayoneerToken>
49
+ http_version:
50
+ recorded_at: Fri, 02 May 2014 05:52:50 GMT
51
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.sandbox.payoneer.com/Payouts/HttpApi/API.aspx?mname=GetToken&p1=Room5620&p2=12Gauh3uSe&p3=100035620&p4=1
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - '*/*'
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Cache-Control:
22
+ - no-cache, no-store, must-revalidate
23
+ Pragma:
24
+ - no-cache
25
+ Content-Type:
26
+ - text/html; charset=utf-8
27
+ Expires:
28
+ - '-1'
29
+ Set-Cookie:
30
+ - ASP.NET_SessionId=vswidgodnjjgszj1rybaxt5d; domain=.sandbox.payoneer.com;
31
+ path=/; secure; HttpOnly
32
+ - pid=100035620; domain=.sandbox.payoneer.com; expires=Fri, 01-May-2015 05:52:43
33
+ GMT; path=/; secure
34
+ P3p:
35
+ - CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
36
+ X-Powered-By:
37
+ - ASP.NET
38
+ Date:
39
+ - Fri, 02 May 2014 05:52:49 GMT
40
+ Content-Length:
41
+ - '101'
42
+ Connection:
43
+ - Keep-Alive
44
+ body:
45
+ encoding: UTF-8
46
+ string: http://payouts.sandbox.payoneer.com/partners/lp.aspx?token=b8e8eab41931475cb4b66b54996a7cb1A9A9579049
47
+ http_version:
48
+ recorded_at: Fri, 02 May 2014 05:52:48 GMT
49
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.sandbox.payoneer.com/Payouts/HttpApi/API.aspx
6
+ body:
7
+ encoding: US-ASCII
8
+ string: mname=GetTokenXML&p1=bogus&p2=bogus&p3=bogus&p4=1&xml=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0A%3CPayoneerDetails%3E%0A++%3CDetails%3E%0A++++%3CuserName%3Ebogus%3C%2FuserName%3E%0A++++%3Cpassword%3Ebogus%3C%2Fpassword%3E%0A++++%3Cprid%3Ebogus%3C%2Fprid%3E%0A++++%3Capuid%3E1%3C%2Fapuid%3E%0A++%3C%2FDetails%3E%0A++%3CPersonalDetails%3E%0A++++%3Caddress1%2F%3E%0A++%3C%2FPersonalDetails%3E%0A%3C%2FPayoneerDetails%3E%0A
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - '*/*'
14
+ User-Agent:
15
+ - Ruby
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Cache-Control:
24
+ - no-cache, no-store, must-revalidate
25
+ Pragma:
26
+ - no-cache
27
+ Content-Type:
28
+ - text/html; charset=utf-8
29
+ Expires:
30
+ - '-1'
31
+ Set-Cookie:
32
+ - ASP.NET_SessionId=ozwwufn2rwhhfq4hxw4fzqum; domain=.sandbox.payoneer.com;
33
+ path=/; secure; HttpOnly
34
+ P3p:
35
+ - CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
36
+ X-Powered-By:
37
+ - ASP.NET
38
+ Date:
39
+ - Fri, 02 May 2014 04:52:05 GMT
40
+ Content-Length:
41
+ - '220'
42
+ Connection:
43
+ - Keep-Alive
44
+ body:
45
+ encoding: UTF-8
46
+ string: <?xml version='1.0' encoding='ISO-8859-1' ?><PayoneerResponse><Result>A00B556F</Result><Description>Unauthorized
47
+ Access or invalid parameters, please check your IP address and parameters.</Description></PayoneerResponse>
48
+ http_version:
49
+ recorded_at: Fri, 02 May 2014 04:52:04 GMT
50
+ recorded_with: VCR 2.9.0
@@ -9,6 +9,20 @@ describe PayoneerApi::Client do
9
9
  )
10
10
  }
11
11
 
12
+ describe '.new_payee_signup_url', vcr: true do
13
+ it 'returns a url to the registration page (implicit credentials through environment variables)' do
14
+ response = PayoneerApi::Client.new_payee_signup_url('1')
15
+ expect(URI.parse(response).host).to eq('payouts.sandbox.payoneer.com')
16
+ end
17
+ end
18
+
19
+ describe '.new_payee_prefilled_signup_url', vcr: true do
20
+ it 'returns a url to the prefilled registration page' do
21
+ response = PayoneerApi::Client.new_payee_prefilled_signup_url('1', {})
22
+ expect(URI.parse(response).host).to eq('payouts.sandbox.payoneer.com')
23
+ end
24
+ end
25
+
12
26
  describe '#payee_signup_url', vcr: true do
13
27
  it 'returns a url to the registration page' do
14
28
  response = client.payee_signup_url('1')
@@ -17,6 +31,21 @@ describe PayoneerApi::Client do
17
31
  end
18
32
 
19
33
  describe '#payee_prefilled_signup_url', vcr: true do
34
+ context 'with incorrect login credentials' do
35
+ it 'returns a parsed error notification' do
36
+ client = PayoneerApi::Client.new(
37
+ partner_id: 'bogus',
38
+ username: 'bogus',
39
+ password: 'bogus',
40
+ environment: 'sandbox'
41
+ )
42
+ expect {
43
+ client.payee_prefilled_signup_url('1', {})
44
+ }.to raise_error(PayoneerApi::PayoneerException,
45
+ 'Unauthorized Access or invalid parameters, please check your IP address and parameters.')
46
+ end
47
+ end
48
+
20
49
  context 'with all correct params passed in' do
21
50
  let(:params) {{
22
51
  redirect_url: 'http://test.com/redirect',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payoneer_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donald Piret
@@ -104,11 +104,15 @@ files:
104
104
  - README.md
105
105
  - lib/payoneer_api.rb
106
106
  - lib/payoneer_api/client.rb
107
+ - lib/payoneer_api/core_ext/hash.rb
107
108
  - lib/payoneer_api/payoneer_exception.rb
108
109
  - lib/payoneer_api/version.rb
109
110
  - payoneer_api.gemspec
111
+ - spec/fixtures/vcr_cassettes/PayoneerApi_Client/_new_payee_prefilled_signup_url/returns_a_url_to_the_prefilled_registration_page.yml
112
+ - spec/fixtures/vcr_cassettes/PayoneerApi_Client/_new_payee_signup_url/returns_a_url_to_the_registration_page_implicit_credentials_through_environment_variables_.yml
110
113
  - spec/fixtures/vcr_cassettes/PayoneerApi_Client/_payee_prefilled_signup_url/with_all_correct_params_passed_in/includes_a_token_parameter_in_this_url.yml
111
114
  - spec/fixtures/vcr_cassettes/PayoneerApi_Client/_payee_prefilled_signup_url/with_all_correct_params_passed_in/returns_a_url_to_the_prefilled_registration_page.yml
115
+ - spec/fixtures/vcr_cassettes/PayoneerApi_Client/_payee_prefilled_signup_url/with_incorrect_login_credentials/returns_a_parsed_error_notification.yml
112
116
  - spec/fixtures/vcr_cassettes/PayoneerApi_Client/_payee_signup_url/returns_a_url_to_the_registration_page.yml
113
117
  - spec/payoneer_api/client_spec.rb
114
118
  - spec/spec_helper.rb
@@ -137,8 +141,11 @@ signing_key:
137
141
  specification_version: 4
138
142
  summary: Ruby wrapper for Payoneer API
139
143
  test_files:
144
+ - spec/fixtures/vcr_cassettes/PayoneerApi_Client/_new_payee_prefilled_signup_url/returns_a_url_to_the_prefilled_registration_page.yml
145
+ - spec/fixtures/vcr_cassettes/PayoneerApi_Client/_new_payee_signup_url/returns_a_url_to_the_registration_page_implicit_credentials_through_environment_variables_.yml
140
146
  - spec/fixtures/vcr_cassettes/PayoneerApi_Client/_payee_prefilled_signup_url/with_all_correct_params_passed_in/includes_a_token_parameter_in_this_url.yml
141
147
  - spec/fixtures/vcr_cassettes/PayoneerApi_Client/_payee_prefilled_signup_url/with_all_correct_params_passed_in/returns_a_url_to_the_prefilled_registration_page.yml
148
+ - spec/fixtures/vcr_cassettes/PayoneerApi_Client/_payee_prefilled_signup_url/with_incorrect_login_credentials/returns_a_parsed_error_notification.yml
142
149
  - spec/fixtures/vcr_cassettes/PayoneerApi_Client/_payee_signup_url/returns_a_url_to_the_registration_page.yml
143
150
  - spec/payoneer_api/client_spec.rb
144
151
  - spec/spec_helper.rb