paylane 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +22 -0
- data/Rakefile +8 -0
- data/lib/paylane.rb +17 -0
- data/lib/paylane/api.rb +58 -0
- data/lib/paylane/gateway.rb +21 -0
- data/lib/paylane/payment.rb +53 -0
- data/lib/paylane/railtie.rb +7 -0
- data/lib/paylane/recurring_payment.rb +28 -0
- data/lib/paylane/response.rb +36 -0
- data/lib/paylane/version.rb +3 -0
- data/paylane.gemspec +24 -0
- data/spec/helpers.rb +11 -0
- data/spec/paylane/api_spec.rb +191 -0
- data/spec/paylane/gateway_spec.rb +13 -0
- data/spec/paylane/payment_spec.rb +41 -0
- data/spec/paylane/recurring_payment_spec.rb +24 -0
- data/spec/paylane/resposne_spec.rb +51 -0
- data/spec/spec_helper.rb +21 -0
- metadata +140 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012 Bartlomiej Kozal
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Paylane
|
|
2
|
+
|
|
3
|
+
Ruby client for [PayLane](http://paylane.com) service.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
**It's strongly recommended to NOT install current version - development in progress**
|
|
8
|
+
|
|
9
|
+
TODO: Write installation instructions here
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
TODO: Write usage instructions here
|
|
14
|
+
|
|
15
|
+
## Contributing
|
|
16
|
+
|
|
17
|
+
1. Fork it
|
|
18
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
19
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
20
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
21
|
+
5. Create new Pull Request
|
|
22
|
+
|
data/Rakefile
ADDED
data/lib/paylane.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require "savon"
|
|
2
|
+
require "paylane/version"
|
|
3
|
+
require "paylane/gateway"
|
|
4
|
+
require "paylane/api"
|
|
5
|
+
require "paylane/response"
|
|
6
|
+
require "paylane/payment"
|
|
7
|
+
require "paylane/recurring_payment"
|
|
8
|
+
require "paylane/railtie" if defined?(Rails)
|
|
9
|
+
|
|
10
|
+
module PayLane
|
|
11
|
+
class << self
|
|
12
|
+
attr_accessor :currency, :login, :password, :logger
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
self.currency = "EUR"
|
|
16
|
+
self.logger = Logger.new(STDOUT)
|
|
17
|
+
end
|
data/lib/paylane/api.rb
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module PayLane
|
|
2
|
+
class API
|
|
3
|
+
def initialize(client)
|
|
4
|
+
@client = client
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def multi_sale(params)
|
|
8
|
+
PayLane::Response.new do
|
|
9
|
+
request(:multiSale, params, 'multi_sale_params')[:multi_sale_response][:response]
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def capture_sale(params)
|
|
14
|
+
PayLane::Response.new do
|
|
15
|
+
request(:captureSale, params)[:capture_sale_response][:response]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def close_sale_authorization(params)
|
|
20
|
+
PayLane::Response.new do
|
|
21
|
+
request(:closeSaleAuthorization, params)[:close_sale_authorization_response][:response]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def refund(params)
|
|
26
|
+
PayLane::Response.new do
|
|
27
|
+
request(:refund, params)[:refund_response][:response]
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def resale(params)
|
|
32
|
+
PayLane::Response.new do
|
|
33
|
+
request(:resale, params)[:resale_response][:response]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def get_sale_result(params)
|
|
38
|
+
PayLane::Response.new do
|
|
39
|
+
request(:getSaleResult, params)[:get_sale_result_response][:response]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def check_sales(params)
|
|
44
|
+
PayLane::Response.new do
|
|
45
|
+
request(:checkSales, params, 'check_sales_params')[:check_sales_response][:check_sales_response]
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def request(method, params, params_prefix = nil)
|
|
52
|
+
body = params_prefix ? {params_prefix => params} : params
|
|
53
|
+
soap_response = @client.request(method) { soap.body = body }
|
|
54
|
+
soap_response.to_hash
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module PayLane
|
|
2
|
+
class Gateway
|
|
3
|
+
attr_reader :client
|
|
4
|
+
|
|
5
|
+
def initialize(login, password)
|
|
6
|
+
@login = login
|
|
7
|
+
@password = password
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def connect
|
|
11
|
+
@client = Savon.client do |wsdl, http|
|
|
12
|
+
wsdl.document = wsdl_location
|
|
13
|
+
http.auth.basic(@login, @password)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def wsdl_location
|
|
18
|
+
'https://direct.paylane.com/wsdl/production/Direct.wsdl'
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module PayLane
|
|
2
|
+
class Payment
|
|
3
|
+
def initialize(options = {})
|
|
4
|
+
gateway = PayLane::Gateway.new(PayLane.login, PayLane.password)
|
|
5
|
+
@api = PayLane::API.new(gateway.connect)
|
|
6
|
+
@options = options
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def charge_card(amount)
|
|
10
|
+
do_payment(amount, {'card_data' => card_data})
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def direct_debit(amount)
|
|
14
|
+
do_payment(amount, {'account_data' => account_data})
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def do_payment(amount, payment_method)
|
|
20
|
+
@amount = amount
|
|
21
|
+
response = @api.multi_sale(params.merge('payment_method' => payment_method))
|
|
22
|
+
PayLane.logger.info("[PayLane] #{response}")
|
|
23
|
+
response
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
protected
|
|
27
|
+
|
|
28
|
+
def params
|
|
29
|
+
{
|
|
30
|
+
'customer' => customer,
|
|
31
|
+
'amount' => @amount,
|
|
32
|
+
'currency_code' => PayLane.currency,
|
|
33
|
+
'processing_date' => "#{Date.today}",
|
|
34
|
+
'product' => {
|
|
35
|
+
'description' => "[#{@options[:product]}][#{Time.now.getutc}]"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def card_data
|
|
41
|
+
{}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def account_data
|
|
45
|
+
{}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def customer
|
|
49
|
+
{}
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module PayLane
|
|
2
|
+
class RecurringPayment
|
|
3
|
+
def initialize(previous_sale_id, options = {})
|
|
4
|
+
gateway = PayLane::Gateway.new(PayLane.login, PayLane.password)
|
|
5
|
+
@api = PayLane::API.new(gateway.connect)
|
|
6
|
+
@previous_sale_id = previous_sale_id
|
|
7
|
+
@options = options
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def charge_card(amount)
|
|
11
|
+
@amount = amount
|
|
12
|
+
response = @api.resale(params)
|
|
13
|
+
PayLane.logger.info("[PayLane] #{response}")
|
|
14
|
+
response
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
|
|
19
|
+
def params
|
|
20
|
+
{
|
|
21
|
+
'id_sale' => @previous_sale_id,
|
|
22
|
+
'amount' => @amount,
|
|
23
|
+
'currency' => PayLane.currency,
|
|
24
|
+
'description' => "[#{@options[:product]}][#{Time.now.getutc}]"
|
|
25
|
+
}
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module PayLane
|
|
2
|
+
class Response < Hash
|
|
3
|
+
def initialize
|
|
4
|
+
@response = yield
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def [](key)
|
|
8
|
+
@response[key]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def has_ok?
|
|
12
|
+
@response.include?(:ok)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def has_error?
|
|
16
|
+
!has_ok?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def has_data?
|
|
20
|
+
@response.include?(:data)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def error_description
|
|
24
|
+
@response[:error][:error_description] if has_error?
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
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
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
data/paylane.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path('../lib/paylane/version', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.authors = ["Bartlomiej Kozal"]
|
|
6
|
+
gem.email = ["bkzl@me.com"]
|
|
7
|
+
gem.description = %q{Ruby client for PayLane service.}
|
|
8
|
+
gem.summary = %q{Ruby client for PayLane service.}
|
|
9
|
+
gem.homepage = ""
|
|
10
|
+
|
|
11
|
+
gem.files = `git ls-files`.split($\)
|
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
14
|
+
gem.name = "paylane"
|
|
15
|
+
gem.require_paths = ["lib"]
|
|
16
|
+
gem.version = PayLane::VERSION
|
|
17
|
+
|
|
18
|
+
gem.add_dependency "savon"
|
|
19
|
+
gem.add_development_dependency "rake"
|
|
20
|
+
gem.add_development_dependency "rspec"
|
|
21
|
+
gem.add_development_dependency "fakeweb"
|
|
22
|
+
|
|
23
|
+
gem.post_install_message = "**It's strongly recommended to NOT install current version - development in progress**"
|
|
24
|
+
end
|
data/spec/helpers.rb
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe PayLane::API do
|
|
4
|
+
let(:connection) {
|
|
5
|
+
gateway = PayLane::Gateway.new(PublicTestAccount::LOGIN, PublicTestAccount::PASSWORD)
|
|
6
|
+
gateway.connect
|
|
7
|
+
}
|
|
8
|
+
let(:api) { PayLane::API.new(connection) }
|
|
9
|
+
|
|
10
|
+
describe '#multi_sale' do
|
|
11
|
+
let(:params) do
|
|
12
|
+
params = {
|
|
13
|
+
'customer' => {
|
|
14
|
+
'name' => 'John Smith',
|
|
15
|
+
'email' => 'johnsmith@example.com',
|
|
16
|
+
'ip' => '127.0.0.1',
|
|
17
|
+
'address' => {
|
|
18
|
+
'street_house' => '1st Avenue',
|
|
19
|
+
'city' => 'Lodz',
|
|
20
|
+
'state' => 'Lodz',
|
|
21
|
+
'zip' => '00-000',
|
|
22
|
+
'country_code' => 'PL'
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
'amount' => 9.99,
|
|
26
|
+
'currency_code' => "EUR",
|
|
27
|
+
'product' => {
|
|
28
|
+
'description' => "paylane_api_test"
|
|
29
|
+
}}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "returns id_sale on successful card charge" do
|
|
33
|
+
mock_api_method(connection, :multiSale) do
|
|
34
|
+
{multi_sale_response: {response: {ok: {id_sale: "2772323"}, data: {fraud_score: "8.76"}}}}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
params.merge({
|
|
38
|
+
'payment_method' => {
|
|
39
|
+
'card_data' => {
|
|
40
|
+
'card_number' => 4111111111111111,
|
|
41
|
+
'card_code' => 123,
|
|
42
|
+
'expiration_month' => 12,
|
|
43
|
+
'expiration_year' => 2020,
|
|
44
|
+
'name_on_card' => 'John Smith'
|
|
45
|
+
}}})
|
|
46
|
+
|
|
47
|
+
api.multi_sale(params).should include({ok: {id_sale: "2772323"}})
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "returns id_sale on successful direct debit" do
|
|
51
|
+
mock_api_method(connection, :multiSale) do
|
|
52
|
+
{multi_sale_response: {response: {ok: {id_sale: "2772323"}, data: {fraud_score: "8.76"}}}}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
params.merge({
|
|
56
|
+
'payment_method' => {
|
|
57
|
+
'card_data' => {
|
|
58
|
+
'account_country' => 'DE',
|
|
59
|
+
'bank_code' => 12345678,
|
|
60
|
+
'account_number' => 12345678901,
|
|
61
|
+
'account_holder' => 'John Smith'
|
|
62
|
+
}}})
|
|
63
|
+
|
|
64
|
+
api.multi_sale(params).should include({ok: {id_sale: "2772323"}})
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "returns id_sale_authorization for sales marked by 'capture_later'" do
|
|
68
|
+
mock_api_method(connection, :multiSale) do
|
|
69
|
+
{multi_sale_response: {response: {ok: {id_sale_authorization: "2772323"}, data: {fraud_score: "8.76"}}}}
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
params.merge({
|
|
73
|
+
'payment_method' => {
|
|
74
|
+
'card_data' => {
|
|
75
|
+
'card_number' => 4111111111111111,
|
|
76
|
+
'card_code' => 123,
|
|
77
|
+
'expiration_month' => 12,
|
|
78
|
+
'expiration_year' => 2020,
|
|
79
|
+
'name_on_card' => 'John Smith'
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
'capture_later' => true
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
api.multi_sale(params).should include({ok: {id_sale_authorization: "2772323"}})
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe '#capture_sale' do
|
|
90
|
+
it "returns id_sale on successful sale authorization" do
|
|
91
|
+
mock_api_method(connection, :captureSale) do
|
|
92
|
+
{capture_sale_response: {response: {ok: {id_sale: "2772323"}}}}
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
params = {
|
|
96
|
+
'id_sale_authorization' => '119225',
|
|
97
|
+
'amount' => 9.99
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
api.capture_sale(params).should include({ok: {id_sale: "2772323"}})
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
describe 'close_sale_authorization' do
|
|
105
|
+
it "returns id_closed on successful close sale authorization" do
|
|
106
|
+
mock_api_method(connection, :closeSaleAuthorization) do
|
|
107
|
+
{close_sale_authorization_response: {response: {ok: {is_closed: true}}}}
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
params = {'id_sale_authorization' => '119225'}
|
|
111
|
+
|
|
112
|
+
api.close_sale_authorization(params).should include({ok: {is_closed: true}})
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
describe '#refund' do
|
|
117
|
+
it 'returns id_refund on successful refund' do
|
|
118
|
+
mock_api_method(connection, :refund) do
|
|
119
|
+
{refund_response: {response: {ok: {id_refund: "213871"}}}}
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
params = {
|
|
123
|
+
'id_sale' => '2772323',
|
|
124
|
+
'amount' => 9.99,
|
|
125
|
+
'reason' => 'test_refund_method'
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
api.refund(params).should include({ok: {id_refund: "213871"}})
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
describe '#resale' do
|
|
133
|
+
it 'returns id_sale on successful performed recurring charge' do
|
|
134
|
+
mock_api_method(connection, :resale) do
|
|
135
|
+
{resale_response: {response: {ok: {id_sale: "2773239"}}}}
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
params = {
|
|
139
|
+
'id_sale' => '2772323',
|
|
140
|
+
'amount' => 20.00,
|
|
141
|
+
'currency' => 'EUR',
|
|
142
|
+
'description' => 'paylane_api_test_resale'
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
api.resale(params).should include({ok: {id_sale: "2773239"}})
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
describe '#get_sale_result' do
|
|
150
|
+
it "returns id_sale if find processed sale" do
|
|
151
|
+
mock_api_method(connection, :getSaleResult) do
|
|
152
|
+
{get_sale_result_response: {response: {ok: {id_sale: "2772323"}}}}
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
params = {
|
|
156
|
+
'amount' => 9.99,
|
|
157
|
+
'description' => 'paylane_api_test'
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
api.get_sale_result(params).should include({ok: {id_sale: "2772323"}})
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it "returns id_sale_error if find processed sale with error" do
|
|
164
|
+
mock_api_method(connection, :getSaleResult) do
|
|
165
|
+
{get_sale_result_response: {response: {ok: {id_sale_error: "831072"}}}}
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
params = {
|
|
169
|
+
'amount' => 9.99,
|
|
170
|
+
'description' => 'paylane_api_test'
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
api.get_sale_result(params).should include({ok: {id_sale_error: "831072"}})
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
describe '#check_sales' do
|
|
178
|
+
it 'returns details for requested sale ids' do
|
|
179
|
+
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}]}}}}
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
params = {'id_sale_list' => [2772323, 1]}
|
|
184
|
+
|
|
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})
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe PayLane::Gateway do
|
|
4
|
+
let(:gateway) { PayLane::Gateway.new(PublicTestAccount::LOGIN, PublicTestAccount::PASSWORD) }
|
|
5
|
+
|
|
6
|
+
it "authenticate to API" do
|
|
7
|
+
client = gateway.connect
|
|
8
|
+
client.should be_instance_of(Savon::Client)
|
|
9
|
+
client.wsdl.document.should == "https://direct.paylane.com/wsdl/production/Direct.wsdl"
|
|
10
|
+
client.http.auth.basic.should == ["test", "test"]
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe PayLane::Payment do
|
|
4
|
+
let(:api) { PayLane::API }
|
|
5
|
+
let(:payment) { PayLane::Payment.new }
|
|
6
|
+
|
|
7
|
+
describe 'payment method' do
|
|
8
|
+
let(:params) do
|
|
9
|
+
{
|
|
10
|
+
'customer' => {},
|
|
11
|
+
'amount' => 10.00,
|
|
12
|
+
'currency_code' => 'EUR',
|
|
13
|
+
'processing_date' => "#{Date.today}",
|
|
14
|
+
'product' => {
|
|
15
|
+
'description' => '[][2012-11-30 06:30:00 UTC]'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
before do
|
|
21
|
+
PayLane.stub_chain(:logger, :info)
|
|
22
|
+
Time.stub_chain(:now, :getutc).and_return(Time.utc(2012, 11, 30, 6, 30))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe '#charge_card' do
|
|
26
|
+
it 'charges credit card by specific amount' do
|
|
27
|
+
expected_params = params.merge('payment_method' => {'card_data' => {}})
|
|
28
|
+
api.any_instance.should_receive(:multi_sale).with(expected_params)
|
|
29
|
+
payment.charge_card(10.00)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe '#direct_debit' do
|
|
34
|
+
it 'charges account by specific amount' do
|
|
35
|
+
expected_params = params.merge('payment_method' => {'account_data' => {}})
|
|
36
|
+
api.any_instance.should_receive(:multi_sale).with(expected_params)
|
|
37
|
+
payment.direct_debit(10.00)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe PayLane::RecurringPayment do
|
|
4
|
+
let(:api) { PayLane::API }
|
|
5
|
+
let(:recurring_payment) { PayLane::RecurringPayment.new(12345) }
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
PayLane.stub_chain(:logger, :info)
|
|
9
|
+
Time.stub_chain(:now, :getutc).and_return(Time.utc(2012, 11, 30, 6, 30))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe '#charge_card' do
|
|
13
|
+
it 'charges previosuly charged account' do
|
|
14
|
+
expected_params = {
|
|
15
|
+
'id_sale' => 12345,
|
|
16
|
+
'amount' => 20.00,
|
|
17
|
+
'currency' => 'EUR',
|
|
18
|
+
'description' => '[][2012-11-30 06:30:00 UTC]'
|
|
19
|
+
}
|
|
20
|
+
api.any_instance.should_receive(:resale).with(expected_params)
|
|
21
|
+
recurring_payment.charge_card(20.00)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe PayLane::Response do
|
|
4
|
+
context 'has :ok and :data hashes' do
|
|
5
|
+
let(:response) do
|
|
6
|
+
PayLane::Response.new { {ok: {sale_id: 1}, data: {fraud_score: 1.0}} }
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "returns true on #has_ok?" do
|
|
10
|
+
response.has_ok?.should be_true
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "returns false on #has_error?" do
|
|
14
|
+
response.has_error?.should be_false
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "returns content of :ok key on #attributes" do
|
|
18
|
+
response.attributes.should == {sale_id: 1, fraud_score: 1.00}
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "returns true on #has_data?" do
|
|
22
|
+
response.has_data?.should be_true
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
context 'has :error hash' do
|
|
27
|
+
let(:response) do
|
|
28
|
+
PayLane::Response.new { {error: {error_description: 'Something went wrong'}} }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "returns false on #has_ok?" do
|
|
32
|
+
response.has_ok?.should be_false
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "returns true on #has_error?" do
|
|
36
|
+
response.has_error?.should be_true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "returns error description" do
|
|
40
|
+
response.error_description.should == 'Something went wrong'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "returns content of :error key on #attributes" do
|
|
44
|
+
response.attributes.should == {error_description: 'Something went wrong'}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "returns false on #has_data?" do
|
|
48
|
+
response.has_data?.should be_false
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'paylane'
|
|
2
|
+
require 'fakeweb'
|
|
3
|
+
require 'helpers'
|
|
4
|
+
|
|
5
|
+
RSpec.configure do |config|
|
|
6
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
7
|
+
config.run_all_when_everything_filtered = true
|
|
8
|
+
config.order = 'random'
|
|
9
|
+
config.include PublicTestAccount
|
|
10
|
+
config.include Helpers
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
FakeWeb.allow_net_connect = false
|
|
14
|
+
|
|
15
|
+
Savon.configure do |config|
|
|
16
|
+
config.raise_errors = false
|
|
17
|
+
config.log = false
|
|
18
|
+
config.log_level = :info
|
|
19
|
+
HTTPI.log = false
|
|
20
|
+
end
|
|
21
|
+
|
metadata
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: paylane
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Bartlomiej Kozal
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-08-09 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: savon
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: rake
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
type: :development
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: rspec
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: fakeweb
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ! '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
type: :development
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
78
|
+
description: Ruby client for PayLane service.
|
|
79
|
+
email:
|
|
80
|
+
- bkzl@me.com
|
|
81
|
+
executables: []
|
|
82
|
+
extensions: []
|
|
83
|
+
extra_rdoc_files: []
|
|
84
|
+
files:
|
|
85
|
+
- .gitignore
|
|
86
|
+
- .rspec
|
|
87
|
+
- .travis.yml
|
|
88
|
+
- Gemfile
|
|
89
|
+
- LICENSE
|
|
90
|
+
- README.md
|
|
91
|
+
- Rakefile
|
|
92
|
+
- lib/paylane.rb
|
|
93
|
+
- lib/paylane/api.rb
|
|
94
|
+
- lib/paylane/gateway.rb
|
|
95
|
+
- lib/paylane/payment.rb
|
|
96
|
+
- lib/paylane/railtie.rb
|
|
97
|
+
- lib/paylane/recurring_payment.rb
|
|
98
|
+
- lib/paylane/response.rb
|
|
99
|
+
- lib/paylane/version.rb
|
|
100
|
+
- paylane.gemspec
|
|
101
|
+
- spec/helpers.rb
|
|
102
|
+
- spec/paylane/api_spec.rb
|
|
103
|
+
- spec/paylane/gateway_spec.rb
|
|
104
|
+
- spec/paylane/payment_spec.rb
|
|
105
|
+
- spec/paylane/recurring_payment_spec.rb
|
|
106
|
+
- spec/paylane/resposne_spec.rb
|
|
107
|
+
- spec/spec_helper.rb
|
|
108
|
+
homepage: ''
|
|
109
|
+
licenses: []
|
|
110
|
+
post_install_message: ! '**It''s strongly recommended to NOT install current version
|
|
111
|
+
- development in progress**'
|
|
112
|
+
rdoc_options: []
|
|
113
|
+
require_paths:
|
|
114
|
+
- lib
|
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
|
+
none: false
|
|
117
|
+
requirements:
|
|
118
|
+
- - ! '>='
|
|
119
|
+
- !ruby/object:Gem::Version
|
|
120
|
+
version: '0'
|
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
|
+
none: false
|
|
123
|
+
requirements:
|
|
124
|
+
- - ! '>='
|
|
125
|
+
- !ruby/object:Gem::Version
|
|
126
|
+
version: '0'
|
|
127
|
+
requirements: []
|
|
128
|
+
rubyforge_project:
|
|
129
|
+
rubygems_version: 1.8.23
|
|
130
|
+
signing_key:
|
|
131
|
+
specification_version: 3
|
|
132
|
+
summary: Ruby client for PayLane service.
|
|
133
|
+
test_files:
|
|
134
|
+
- spec/helpers.rb
|
|
135
|
+
- spec/paylane/api_spec.rb
|
|
136
|
+
- spec/paylane/gateway_spec.rb
|
|
137
|
+
- spec/paylane/payment_spec.rb
|
|
138
|
+
- spec/paylane/recurring_payment_spec.rb
|
|
139
|
+
- spec/paylane/resposne_spec.rb
|
|
140
|
+
- spec/spec_helper.rb
|