paylane 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,4 +2,4 @@ rvm:
2
2
  - 1.9.3
3
3
  notifications:
4
4
  email:
5
- - bkzl@ragnarson.com
5
+ - devs@shellycloud.com
data/README.md CHANGED
@@ -14,7 +14,7 @@ or
14
14
 
15
15
  Start from create a client for API.
16
16
 
17
- gateway = PayLane::Gateway.new('login, 'password')
17
+ gateway = PayLane::Gateway.new('login', 'password')
18
18
  client = PayLane::API.new(gateway.connect)
19
19
 
20
20
  Now all methods from [original API](http://devzone.paylane.com/wp-content/uploads/2012/05/paylane_direct_system.pdf) are available in the client object.
@@ -8,42 +8,49 @@ module PayLane
8
8
  end
9
9
 
10
10
  def multi_sale(params)
11
- request(:multiSale, params, 'multi_sale_params')[:multi_sale_response][:response]
11
+ response = request(:multiSale, params, 'multi_sale_params')
12
+ Response.new(response[:multi_sale_response][:response])
12
13
  end
13
14
 
14
15
  def capture_sale(params)
15
- request(:captureSale, params)[:capture_sale_response][:response]
16
+ response = request(:captureSale, params)
17
+ Response.new(response[:capture_sale_response][:response])
16
18
  end
17
19
 
18
20
  def close_sale_authorization(params)
19
- request(:closeSaleAuthorization, params)[:close_sale_authorization_response][:response]
21
+ response = request(:closeSaleAuthorization, params)
22
+ Response.new(response[:close_sale_authorization_response][:response])
20
23
  end
21
24
 
22
25
  def refund(params)
23
- request(:refund, params)[:refund_response][:response]
26
+ response = request(:refund, params)
27
+ Response.new(response[:refund_response][:response])
24
28
  end
25
29
 
26
30
  def resale(params)
27
- request(:resale, params)[:resale_response][:response]
31
+ response = request(:resale, params)
32
+ Response.new(response[:resale_response][:response])
28
33
  end
29
34
 
30
35
  def get_sale_result(params)
31
- request(:getSaleResult, params)[:get_sale_result_response][:response]
36
+ response = request(:getSaleResult, params)
37
+ Response.new(response[:get_sale_result_response][:response])
32
38
  end
33
39
 
34
40
  def check_sales(params)
35
- request(:checkSales, params, 'check_sales_params')[:check_sales_response][:check_sales_response]
41
+ response = request(:checkSales, params, 'check_sales_params')
42
+ Response.new(response[:check_sales_response][:check_sales_response])
36
43
  end
37
44
 
38
45
  private
39
46
 
40
47
  def request(method, params, params_prefix = nil)
41
48
  begin
42
- body = params_prefix ? {params_prefix => params} : params
43
- soap_response = @client.request(method) { soap.body = body }
44
- PayLane::Response.new(soap_response.to_hash)
49
+ @client.request(method) do
50
+ soap.body = (params_prefix ? {params_prefix => params} : params)
51
+ end.to_hash
45
52
  rescue Savon::Error => e
46
- err = PayLane::ConnectionError.new(e)
53
+ err = ConnectionError.new(e)
47
54
  PayLane.logger.error("[PayLane][Savon] #{err.to_hash}")
48
55
  raise err
49
56
  end
@@ -1,8 +1,8 @@
1
1
  module PayLane
2
2
  class Payment
3
3
  def initialize(options = {})
4
- gateway = PayLane::Gateway.new(PayLane.login, PayLane.password)
5
- @api = PayLane::API.new(gateway.connect)
4
+ gateway = Gateway.new(PayLane.login, PayLane.password)
5
+ @api = API.new(gateway.connect)
6
6
  @options = options
7
7
  end
8
8
 
@@ -1,8 +1,8 @@
1
1
  module PayLane
2
2
  class RecurringPayment
3
3
  def initialize(previous_sale_id, options = {})
4
- gateway = PayLane::Gateway.new(PayLane.login, PayLane.password)
5
- @api = PayLane::API.new(gateway.connect)
4
+ gateway = Gateway.new(PayLane.login, PayLane.password)
5
+ @api = API.new(gateway.connect)
6
6
  @previous_sale_id = previous_sale_id
7
7
  @options = options
8
8
  end
@@ -1,15 +1,13 @@
1
1
  module PayLane
2
2
  class Response < Hash
3
- def initialize(response)
4
- @response = response
5
- end
3
+ attr_reader :body
6
4
 
7
- def [](key)
8
- @response[key]
5
+ def initialize(body)
6
+ @body = body
9
7
  end
10
8
 
11
9
  def has_ok?
12
- @response.include?(:ok)
10
+ @body.include?(:ok)
13
11
  end
14
12
 
15
13
  def has_error?
@@ -17,20 +15,16 @@ module PayLane
17
15
  end
18
16
 
19
17
  def has_data?
20
- @response.include?(:data)
18
+ @body.include?(:data)
21
19
  end
22
20
 
23
21
  def error_description
24
- @response[:error][:error_description] if has_error?
22
+ @body[:error][:error_description] if has_error?
25
23
  end
26
24
 
27
25
  def attributes
28
- hash = (@response[:ok] || @response[:error])
29
- has_data? ? hash.merge(@response[:data]) : hash
30
- end
31
-
32
- def to_s
33
- @response.to_s
26
+ hash = (@body[:ok] || @body[:error])
27
+ has_data? ? hash.merge(@body[:data]) : hash
34
28
  end
35
29
  end
36
30
  end
@@ -1,3 +1,3 @@
1
1
  module PayLane
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -5,7 +5,7 @@ end
5
5
 
6
6
  module Helpers
7
7
  def mock_api_method(connection, method)
8
- response = double(to_hash: yield)
8
+ response = mock(to_hash: yield)
9
9
  connection.should_receive(:request).with(method).and_return(response)
10
10
  end
11
11
  end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe PayLane::API do
4
- let(:connection) {
4
+ let(:connection) do
5
5
  gateway = PayLane::Gateway.new(PublicTestAccount::LOGIN, PublicTestAccount::PASSWORD)
6
6
  gateway.connect
7
- }
7
+ end
8
8
  let(:api) { PayLane::API.new(connection) }
9
9
 
10
10
  describe '#multi_sale' do
@@ -31,7 +31,8 @@ describe PayLane::API do
31
31
 
32
32
  it "returns id_sale on successful card charge" do
33
33
  mock_api_method(connection, :multiSale) do
34
- {multi_sale_response: {response: {ok: {id_sale: "2772323"}, data: {fraud_score: "8.76"}}}}
34
+ {multi_sale_response: {response: {ok: {id_sale: "2772323"},
35
+ data: {fraud_score: "8.76"}}}}
35
36
  end
36
37
 
37
38
  params.merge({
@@ -44,12 +45,13 @@ describe PayLane::API do
44
45
  'name_on_card' => 'John Smith'
45
46
  }}})
46
47
 
47
- api.multi_sale(params).should include({ok: {id_sale: "2772323"}})
48
+ api.multi_sale(params).body.should include({ok: {id_sale: "2772323"}})
48
49
  end
49
50
 
50
51
  it "returns id_sale on successful direct debit" do
51
52
  mock_api_method(connection, :multiSale) do
52
- {multi_sale_response: {response: {ok: {id_sale: "2772323"}, data: {fraud_score: "8.76"}}}}
53
+ {multi_sale_response: {response: {ok: {id_sale: "2772323"},
54
+ data: {fraud_score: "8.76"}}}}
53
55
  end
54
56
 
55
57
  params.merge({
@@ -61,12 +63,13 @@ describe PayLane::API do
61
63
  'account_holder' => 'John Smith'
62
64
  }}})
63
65
 
64
- api.multi_sale(params).should include({ok: {id_sale: "2772323"}})
66
+ api.multi_sale(params).body.should include({ok: {id_sale: "2772323"}})
65
67
  end
66
68
 
67
69
  it "returns id_sale_authorization for sales marked by 'capture_later'" do
68
70
  mock_api_method(connection, :multiSale) do
69
- {multi_sale_response: {response: {ok: {id_sale_authorization: "2772323"}, data: {fraud_score: "8.76"}}}}
71
+ {multi_sale_response: {response: {ok: {id_sale_authorization: "2772323"},
72
+ data: {fraud_score: "8.76"}}}}
70
73
  end
71
74
 
72
75
  params.merge({
@@ -82,7 +85,16 @@ describe PayLane::API do
82
85
  'capture_later' => true
83
86
  })
84
87
 
85
- api.multi_sale(params).should include({ok: {id_sale_authorization: "2772323"}})
88
+ api.multi_sale(params).body.should include({ok: {id_sale_authorization: "2772323"}})
89
+ end
90
+
91
+ it "returns instance of PayLane::Response class" do
92
+ mock_api_method(connection, :multiSale) do
93
+ {multi_sale_response: {response: {ok: {id_sale: "2772323"},
94
+ data: {fraud_score: "8.76"}}}}
95
+ end
96
+
97
+ api.multi_sale(params).class.should == PayLane::Response
86
98
  end
87
99
  end
88
100
 
@@ -97,7 +109,7 @@ describe PayLane::API do
97
109
  'amount' => 9.99
98
110
  }
99
111
 
100
- api.capture_sale(params).should include({ok: {id_sale: "2772323"}})
112
+ api.capture_sale(params).body.should include({ok: {id_sale: "2772323"}})
101
113
  end
102
114
  end
103
115
 
@@ -109,7 +121,7 @@ describe PayLane::API do
109
121
 
110
122
  params = {'id_sale_authorization' => '119225'}
111
123
 
112
- api.close_sale_authorization(params).should include({ok: {is_closed: true}})
124
+ api.close_sale_authorization(params).body.should include({ok: {is_closed: true}})
113
125
  end
114
126
  end
115
127
 
@@ -125,7 +137,7 @@ describe PayLane::API do
125
137
  'reason' => 'test_refund_method'
126
138
  }
127
139
 
128
- api.refund(params).should include({ok: {id_refund: "213871"}})
140
+ api.refund(params).body.should include({ok: {id_refund: "213871"}})
129
141
  end
130
142
  end
131
143
 
@@ -142,7 +154,7 @@ describe PayLane::API do
142
154
  'description' => 'paylane_api_test_resale'
143
155
  }
144
156
 
145
- api.resale(params).should include({ok: {id_sale: "2773239"}})
157
+ api.resale(params).body.should include({ok: {id_sale: "2773239"}})
146
158
  end
147
159
  end
148
160
 
@@ -157,7 +169,7 @@ describe PayLane::API do
157
169
  'description' => 'paylane_api_test'
158
170
  }
159
171
 
160
- api.get_sale_result(params).should include({ok: {id_sale: "2772323"}})
172
+ api.get_sale_result(params).body.should include({ok: {id_sale: "2772323"}})
161
173
  end
162
174
 
163
175
  it "returns id_sale_error if find processed sale with error" do
@@ -170,21 +182,30 @@ describe PayLane::API do
170
182
  'description' => 'paylane_api_test'
171
183
  }
172
184
 
173
- api.get_sale_result(params).should include({ok: {id_sale_error: "831072"}})
185
+ api.get_sale_result(params).body.should include({ok: {id_sale_error: "831072"}})
174
186
  end
175
187
  end
176
188
 
177
189
  describe '#check_sales' do
178
190
  it 'returns details for requested sale ids' do
179
191
  mock_api_method(connection, :checkSales) do
180
- {check_sales_response: {check_sales_response: {ok: {sale_status: [{id_sale: "1", status: "NOT_FOUND", is_refund: false, is_chargeback: false, is_reversal: false}, {id_sale: "2772323", status: "PERFORMED", is_refund: false, is_chargeback: false, is_reversal: false}]}}}}
192
+ {check_sales_response: {check_sales_response: {ok: {sale_status: [
193
+ {id_sale: "1", status: "NOT_FOUND", is_refund: false,
194
+ is_chargeback: false, is_reversal: false},
195
+ {id_sale: "2772323", status: "PERFORMED", is_refund: false,
196
+ is_chargeback: false, is_reversal: false}
197
+ ]}}}}
181
198
  end
182
199
 
183
200
  params = {'id_sale_list' => [2772323, 1]}
184
201
 
185
- sales = api.check_sales(params)[:ok][:sale_status]
186
- sales.should include({id_sale: "1", status: "NOT_FOUND", is_refund: false, is_chargeback: false, is_reversal: false})
187
- sales.should include({id_sale: "2772323", status: "PERFORMED", is_refund: false, is_chargeback: false, is_reversal: false})
202
+ sales = api.check_sales(params).body[:ok][:sale_status]
203
+ sales.should include({id_sale: "1", status: "NOT_FOUND",
204
+ is_refund: false, is_chargeback: false,
205
+ is_reversal: false})
206
+ sales.should include({id_sale: "2772323", status: "PERFORMED",
207
+ is_refund: false, is_chargeback: false,
208
+ is_reversal: false})
188
209
  end
189
210
  end
190
211
  end
metadata CHANGED
@@ -1,67 +1,76 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paylane
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ prerelease:
5
+ version: 1.1.0
5
6
  platform: ruby
6
7
  authors:
7
8
  - Bartlomiej Kozal
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-03-25 00:00:00.000000000 Z
12
+ date: 2013-04-26 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: savon
16
+ type: :runtime
15
17
  requirement: !ruby/object:Gem::Requirement
18
+ none: false
16
19
  requirements:
17
20
  - - '='
18
21
  - !ruby/object:Gem::Version
19
22
  version: 1.2.0
20
- type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - '='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 1.2.0
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rake
32
+ type: :development
29
33
  requirement: !ruby/object:Gem::Requirement
34
+ none: false
30
35
  requirements:
31
36
  - - ! '>='
32
37
  - !ruby/object:Gem::Version
33
38
  version: '0'
34
- type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: '0'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rspec
48
+ type: :development
43
49
  requirement: !ruby/object:Gem::Requirement
50
+ none: false
44
51
  requirements:
45
52
  - - ! '>='
46
53
  - !ruby/object:Gem::Version
47
54
  version: '0'
48
- type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '0'
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: fakeweb
64
+ type: :development
57
65
  requirement: !ruby/object:Gem::Requirement
66
+ none: false
58
67
  requirements:
59
68
  - - ! '>='
60
69
  - !ruby/object:Gem::Version
61
70
  version: '0'
62
- type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ! '>='
67
76
  - !ruby/object:Gem::Version
@@ -99,26 +108,27 @@ files:
99
108
  - spec/spec_helper.rb
100
109
  homepage: ''
101
110
  licenses: []
102
- metadata: {}
103
111
  post_install_message:
104
112
  rdoc_options: []
105
113
  require_paths:
106
114
  - lib
107
115
  required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
108
117
  requirements:
109
118
  - - ! '>='
110
119
  - !ruby/object:Gem::Version
111
120
  version: '0'
112
121
  required_rubygems_version: !ruby/object:Gem::Requirement
122
+ none: false
113
123
  requirements:
114
124
  - - ! '>='
115
125
  - !ruby/object:Gem::Version
116
126
  version: '0'
117
127
  requirements: []
118
128
  rubyforge_project:
119
- rubygems_version: 2.0.3
129
+ rubygems_version: 1.8.23
120
130
  signing_key:
121
- specification_version: 4
131
+ specification_version: 3
122
132
  summary: Ruby client for PayLane service.
123
133
  test_files:
124
134
  - spec/helpers.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZDQ0NWIxMmQwZmRjMDg5ZjE5ZjhkNzQ0MWFjOWI5OWNjZmI1ZTQ2MA==
5
- data.tar.gz: !binary |-
6
- MGU2MTFiMzJhOGVhMzhiZmMzZmQ2NWI4ODA2OTE3OTljZjhhYTA2ZA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NzY5MTRkNTgzMDBlZTAwNWY0N2YyZWYxNjNhMTEzODFmN2Y2YzgxNmMxZmIz
10
- MDBlNTQwODM0Yjg2ZjRlYWU3MGQ5MWVkZGRkMWJiNTU1YTU1Nzk0MTJjYTBk
11
- ODgxZmJkNDJmM2FlMzQ0MzA0NWFlYzY0NDIyNGJmMTQ5ZmYxYzk=
12
- data.tar.gz: !binary |-
13
- ZGY2MWNjMDkyZjBiMjgwZjI2MjkzZDQyYmE0MGJkNGIzMzI4ZjM4M2QwOWEz
14
- ZGUyODdkYjI4YzM5OTJkNzE4MjZkMWZjMmMyNDExNzJjNmMyZTkyODIyYTg2
15
- ZTYzODVkNWFjMDNhZWM2NTNjNGE5NjNjNjEzZTVlMmVkZGUyOGE=