paytureman 0.5.0 → 0.7.0
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.
- checksums.yaml +4 -4
- data/README.md +22 -2
- data/lib/payments/payment.rb +21 -9
- data/lib/payments/payment_blocked.rb +4 -4
- data/lib/payments/payment_charged.rb +3 -3
- data/lib/payments/payment_new.rb +21 -3
- data/lib/payments/payment_prepared.rb +3 -3
- data/lib/payments/payment_with_session.rb +4 -4
- data/lib/payture/api.rb +20 -8
- data/lib/paytureman.rb +2 -1
- data/lib/service/configuration.rb +56 -0
- data/paytureman.gemspec +1 -1
- data/spec/requests/payment_process_spec.rb +86 -21
- data/spec/requests/payture/api_spec.rb +28 -0
- data/spec/requests/service/configuration_spec.rb +42 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cab53a95a5cb505acc786ae18db994f36b2b5f2b
|
4
|
+
data.tar.gz: 6195ca545af50b0edbb0ee007704991494bf617b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa7323cddc4e9a62fad4a86f5f44b0002bc3cbccfc9b9b93eab0594135554846f69104ed04f6173fa32747f6473edb589b5bac5975c34ae75f6f2f5227ed2fbb
|
7
|
+
data.tar.gz: 2f6c25408ebecb50ee21d0ecafc1700c6ba9bd85440f43d39ee26010654b76563dfbc8da8e78614260412e909b14005e06913c581fe7334a8b86de1666e060aa
|
data/README.md
CHANGED
@@ -21,6 +21,19 @@ Or install it yourself as:
|
|
21
21
|
```ruby
|
22
22
|
require 'paytureman'
|
23
23
|
|
24
|
+
Paytureman::Configuration.setup do |config|
|
25
|
+
config.host = "sandbox"
|
26
|
+
config.key = "MerchantKey"
|
27
|
+
config.password = "123"
|
28
|
+
end
|
29
|
+
|
30
|
+
# or you can use several configs
|
31
|
+
Paytureman::Configuration.setup :production do |config|
|
32
|
+
config.host = "secure"
|
33
|
+
config.key = "Merchant12345"
|
34
|
+
config.password = "password"
|
35
|
+
end
|
36
|
+
|
24
37
|
order_id = SecureRandom.uuid # generate an order ID
|
25
38
|
amount = 123.15 # amount to be charged
|
26
39
|
customer_ip = "123.45.67.89" # customer's IP address
|
@@ -28,8 +41,15 @@ customer_ip = "123.45.67.89" # customer's IP address
|
|
28
41
|
# create initial payment
|
29
42
|
payment = Paytureman::PaymentNew.new(order_id, amount, customer_ip)
|
30
43
|
|
44
|
+
# in case with several configs
|
45
|
+
payment = Paytureman::PaymentNew.new(order_id, amount, customer_ip, :production)
|
46
|
+
|
31
47
|
# prepare it
|
32
|
-
|
48
|
+
description = Paytureman::PaymentDescription.new
|
49
|
+
description.product = 'Paytureman demo payment'
|
50
|
+
description.total = amount
|
51
|
+
|
52
|
+
payment = payment.prepare(description)
|
33
53
|
# ... assert(payment.kind_of?(Paytureman::PaymentPrepared))
|
34
54
|
|
35
55
|
puts "Please, visit #{payment.url} to proceed with the payment. Then press Enter."
|
@@ -51,4 +71,4 @@ payment = payment.charge
|
|
51
71
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
72
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
73
|
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
-
5. Create new Pull Request
|
74
|
+
5. Create new Pull Request
|
data/lib/payments/payment.rb
CHANGED
@@ -2,18 +2,24 @@ module Paytureman
|
|
2
2
|
|
3
3
|
class Payment
|
4
4
|
|
5
|
+
attr_accessor :gateway
|
5
6
|
attr_reader :order_id
|
7
|
+
attr_writer :configuration
|
6
8
|
|
7
|
-
def initialize(order_id, amount,
|
8
|
-
@order_id
|
9
|
+
def initialize(order_id, amount, gateway = nil)
|
10
|
+
@order_id = order_id
|
11
|
+
@amount = amount
|
12
|
+
@gateway = gateway
|
9
13
|
end
|
10
14
|
|
11
15
|
def save_to_memento(memento)
|
12
|
-
memento.order_id
|
16
|
+
memento.order_id = order_id
|
17
|
+
memento.amount = amount
|
18
|
+
memento.gateway = gateway
|
13
19
|
end
|
14
20
|
|
15
21
|
def self.new_from_memento(memento)
|
16
|
-
new(memento.order_id, memento.amount, memento.
|
22
|
+
new(memento.order_id, memento.amount, memento.gateway)
|
17
23
|
end
|
18
24
|
|
19
25
|
def self.new_from_payment(donor)
|
@@ -34,17 +40,23 @@ module Paytureman
|
|
34
40
|
current_payment_type.new_from_payment(self)
|
35
41
|
end
|
36
42
|
|
37
|
-
attr_accessor :payture
|
38
|
-
|
39
43
|
protected
|
40
44
|
|
41
|
-
attr_accessor :amount
|
45
|
+
attr_accessor :amount
|
42
46
|
attr_writer :order_id
|
43
47
|
|
48
|
+
def amount_in_cents
|
49
|
+
(amount * 100).round
|
50
|
+
end
|
51
|
+
|
52
|
+
def configuration
|
53
|
+
@configuration ||= Configuration.instance
|
54
|
+
end
|
55
|
+
|
44
56
|
def payture
|
45
|
-
@payture ||=
|
57
|
+
@payture ||= configuration.api_for(gateway)
|
46
58
|
end
|
47
59
|
|
48
60
|
end
|
49
61
|
|
50
|
-
end
|
62
|
+
end
|
@@ -3,16 +3,16 @@ module Paytureman
|
|
3
3
|
class PaymentBlocked < PaymentWithSession
|
4
4
|
|
5
5
|
def unblock
|
6
|
-
if payture.unblock(order_id,
|
7
|
-
PaymentCancelled.new(order_id, amount,
|
6
|
+
if payture.unblock(order_id, amount_in_cents)
|
7
|
+
PaymentCancelled.new(order_id, amount, session_id, gateway)
|
8
8
|
else
|
9
9
|
self
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
def charge
|
14
|
-
if payture.charge(order_id
|
15
|
-
PaymentCharged.new(order_id, amount,
|
14
|
+
if payture.charge(order_id)
|
15
|
+
PaymentCharged.new(order_id, amount, session_id, gateway)
|
16
16
|
else
|
17
17
|
self
|
18
18
|
end
|
@@ -2,12 +2,12 @@ module Paytureman
|
|
2
2
|
|
3
3
|
class PaymentCharged < PaymentWithSession
|
4
4
|
def refund
|
5
|
-
if payture.refund(order_id,
|
6
|
-
PaymentRefunded.new(order_id, amount,
|
5
|
+
if payture.refund(order_id, amount_in_cents)
|
6
|
+
PaymentRefunded.new(order_id, amount, session_id, gateway)
|
7
7
|
else
|
8
8
|
self
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
end
|
13
|
+
end
|
data/lib/payments/payment_new.rb
CHANGED
@@ -10,15 +10,33 @@ module Paytureman
|
|
10
10
|
|
11
11
|
class PaymentNew < Payment
|
12
12
|
|
13
|
+
def initialize(order_id, amount, ip, gateway = nil)
|
14
|
+
super(order_id, amount, gateway)
|
15
|
+
@ip = ip
|
16
|
+
end
|
17
|
+
|
18
|
+
def save_to_memento(memento)
|
19
|
+
super
|
20
|
+
memento.ip = ip
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.new_from_memento(memento)
|
24
|
+
new(memento.order_id, memento.amount, memento.ip, memento.gateway)
|
25
|
+
end
|
26
|
+
|
13
27
|
def prepare(description = PaymentDescription.new)
|
14
|
-
session_id = payture.init(
|
28
|
+
session_id = payture.init(order_id, amount_in_cents, ip, description.to_h)
|
15
29
|
if session_id
|
16
|
-
PaymentPrepared.new(
|
30
|
+
PaymentPrepared.new(order_id, amount, session_id, gateway)
|
17
31
|
else
|
18
32
|
self
|
19
33
|
end
|
20
34
|
end
|
21
35
|
|
36
|
+
protected
|
37
|
+
|
38
|
+
attr_reader :ip
|
39
|
+
|
22
40
|
end
|
23
41
|
|
24
|
-
end
|
42
|
+
end
|
@@ -3,13 +3,13 @@ module Paytureman
|
|
3
3
|
class PaymentPrepared < PaymentWithSession
|
4
4
|
|
5
5
|
def url
|
6
|
-
|
6
|
+
payture.pay_url(session_id)
|
7
7
|
end
|
8
8
|
|
9
9
|
def block
|
10
|
-
PaymentBlocked.new(order_id, amount,
|
10
|
+
PaymentBlocked.new(order_id, amount, session_id, gateway)
|
11
11
|
end
|
12
12
|
|
13
13
|
end
|
14
14
|
|
15
|
-
end
|
15
|
+
end
|
@@ -2,9 +2,9 @@ module Paytureman
|
|
2
2
|
|
3
3
|
class PaymentWithSession < Payment
|
4
4
|
|
5
|
-
def initialize(order_id, amount,
|
5
|
+
def initialize(order_id, amount, session_id, gateway = nil)
|
6
|
+
super(order_id, amount, gateway)
|
6
7
|
@session_id = session_id
|
7
|
-
super(order_id, amount, ip)
|
8
8
|
end
|
9
9
|
|
10
10
|
def save_to_memento(memento)
|
@@ -13,7 +13,7 @@ module Paytureman
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.new_from_memento(memento)
|
16
|
-
new(memento.order_id, memento.amount, memento.
|
16
|
+
new(memento.order_id, memento.amount, memento.session_id, memento.gateway)
|
17
17
|
end
|
18
18
|
|
19
19
|
protected
|
@@ -22,4 +22,4 @@ module Paytureman
|
|
22
22
|
|
23
23
|
end
|
24
24
|
|
25
|
-
end
|
25
|
+
end
|
data/lib/payture/api.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
module Paytureman
|
2
2
|
class Api
|
3
|
-
include Singleton
|
4
|
-
|
5
3
|
attr_accessor :rest_client
|
6
4
|
|
5
|
+
def initialize(host, key, password)
|
6
|
+
@host = host
|
7
|
+
@key = key
|
8
|
+
@password = password
|
9
|
+
end
|
10
|
+
|
7
11
|
def init(order_id, amount, ip, description = {})
|
8
12
|
|
9
13
|
data = { SessionType: :Block, OrderId: order_id, Amount: amount, IP: ip }
|
@@ -17,18 +21,22 @@ module Paytureman
|
|
17
21
|
response[:success] && response[:session_id]
|
18
22
|
end
|
19
23
|
|
20
|
-
def
|
21
|
-
|
24
|
+
def pay_url(session_id)
|
25
|
+
"#{url_for(:pay)}?SessionId=#{session_id}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def charge(order_id)
|
29
|
+
response = make_request(:charge, order_id: order_id, password: @password)
|
22
30
|
response[:success]
|
23
31
|
end
|
24
32
|
|
25
33
|
def refund(order_id, amount)
|
26
|
-
response = make_request(:refund, order_id: order_id, amount: amount, password:
|
34
|
+
response = make_request(:refund, order_id: order_id, amount: amount, password: @password)
|
27
35
|
response[:success]
|
28
36
|
end
|
29
37
|
|
30
38
|
def unblock(order_id, amount)
|
31
|
-
response = make_request(:unblock, order_id: order_id, amount: amount, password:
|
39
|
+
response = make_request(:unblock, order_id: order_id, amount: amount, password: @password)
|
32
40
|
response[:success]
|
33
41
|
end
|
34
42
|
|
@@ -46,10 +54,10 @@ module Paytureman
|
|
46
54
|
|
47
55
|
def make_request(method, params)
|
48
56
|
params = Hash[
|
49
|
-
params.merge(key:
|
57
|
+
params.merge(key: @key).
|
50
58
|
map { |k, v| [ k.to_s.camelize, v ] }
|
51
59
|
]
|
52
|
-
response = rest_client.post
|
60
|
+
response = rest_client.post url_for(method), params
|
53
61
|
puts response.body
|
54
62
|
return nil if response.body.empty?
|
55
63
|
doc = REXML::Document.new(response.body)
|
@@ -69,6 +77,10 @@ module Paytureman
|
|
69
77
|
return result
|
70
78
|
end
|
71
79
|
|
80
|
+
def url_for(method)
|
81
|
+
"https://#@host.payture.com/apim/#{method.to_s.camelize}"
|
82
|
+
end
|
83
|
+
|
72
84
|
end
|
73
85
|
end
|
74
86
|
|
data/lib/paytureman.rb
CHANGED
@@ -17,4 +17,5 @@ require_relative 'payments/payment_refunded'
|
|
17
17
|
require_relative 'payments/payment_cancelled'
|
18
18
|
require_relative 'payments/payment_unknown'
|
19
19
|
|
20
|
-
require_relative 'service/payment_persistence'
|
20
|
+
require_relative 'service/payment_persistence'
|
21
|
+
require_relative 'service/configuration'
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Paytureman
|
2
|
+
class Configuration
|
3
|
+
include Singleton
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def setup(namespace = nil)
|
7
|
+
settings = Settings.new
|
8
|
+
yield settings
|
9
|
+
instance.add_settings(namespace, settings)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_accessor :configurations
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@configurations = {}
|
17
|
+
add_settings(nil, Settings.new)
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_settings(namespace, settings)
|
21
|
+
configurations[gateway_name(namespace)] = settings
|
22
|
+
end
|
23
|
+
|
24
|
+
def settings(namespace)
|
25
|
+
configurations[gateway_name(namespace)]
|
26
|
+
end
|
27
|
+
|
28
|
+
def api_for(namespace)
|
29
|
+
config = settings(namespace) or raise GatewayNotFoundException.new(namespace)
|
30
|
+
Paytureman::Api.new(config.host, config.key, config.password)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def gateway_name(key)
|
36
|
+
key.to_s.to_sym
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class Settings
|
41
|
+
attr_accessor :host, :key, :password
|
42
|
+
|
43
|
+
def initialize
|
44
|
+
@host = 'sandbox'
|
45
|
+
@key = 'MerchantRutravel'
|
46
|
+
@password = '123'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class GatewayNotFoundException < Exception
|
51
|
+
def initialize(name)
|
52
|
+
super("Gateway #{name} has not been defined in the configuration")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/paytureman.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "paytureman"
|
7
|
-
spec.version = "0.
|
7
|
+
spec.version = "0.7.0"
|
8
8
|
spec.authors = ["Ivan Kasatenko", "Nickolay Sverchkov", "Alexander Fomin"]
|
9
9
|
spec.email = ["contact@uniqsystems.ru"]
|
10
10
|
spec.summary = %q{Payture API implementation}
|
@@ -8,16 +8,14 @@ describe "Payment" do
|
|
8
8
|
let(:session_id) { SecureRandom.uuid }
|
9
9
|
|
10
10
|
let(:payture_mock) {
|
11
|
-
|
12
|
-
expect(mock).to receive(:init).with(order_id, amount*100, ip, {}).and_return(session_id)
|
13
|
-
end
|
11
|
+
Api.any_instance
|
14
12
|
}
|
15
13
|
|
16
14
|
it "should charge successfully" do
|
17
|
-
|
15
|
+
payture_mock.stub(:init).with(order_id, amount*100, ip, {}).and_return(session_id)
|
16
|
+
payture_mock.stub(:charge).with(order_id).and_return(true)
|
18
17
|
|
19
18
|
payment = PaymentNew.new(order_id, amount, ip)
|
20
|
-
payment.payture = payture_mock
|
21
19
|
|
22
20
|
payment = payment.prepare
|
23
21
|
|
@@ -26,16 +24,16 @@ describe "Payment" do
|
|
26
24
|
payment = payment.block
|
27
25
|
expect(payment).to be_kind_of(PaymentBlocked)
|
28
26
|
|
29
|
-
|
27
|
+
|
30
28
|
payment = payment.charge
|
31
29
|
expect(payment).to be_kind_of(PaymentCharged)
|
32
30
|
end
|
33
31
|
|
34
32
|
it "should unblock successfully" do
|
35
|
-
|
33
|
+
payture_mock.stub(:init).with(order_id, amount*100, ip, {}).and_return(session_id)
|
34
|
+
payture_mock.stub(:unblock).with(order_id, amount*100).and_return(true)
|
36
35
|
|
37
36
|
payment = PaymentNew.new(order_id, amount, ip)
|
38
|
-
payment.payture = payture_mock
|
39
37
|
|
40
38
|
payment = payment.prepare
|
41
39
|
expect(payment).to be_kind_of(PaymentPrepared)
|
@@ -43,17 +41,16 @@ describe "Payment" do
|
|
43
41
|
payment = payment.block
|
44
42
|
expect(payment).to be_kind_of(PaymentBlocked)
|
45
43
|
|
46
|
-
payment.payture = payture_mock
|
47
44
|
payment = payment.unblock
|
48
45
|
expect(payment).to be_kind_of(PaymentCancelled)
|
49
46
|
end
|
50
47
|
|
51
48
|
it "should refund successfully" do
|
52
|
-
|
53
|
-
|
49
|
+
payture_mock.stub(:init).with(order_id, amount*100, ip, {}).and_return(session_id)
|
50
|
+
payture_mock.stub(:charge).with(order_id).and_return(true)
|
51
|
+
payture_mock.stub(:refund).with(order_id, amount*100).and_return(true)
|
54
52
|
|
55
53
|
payment = PaymentNew.new(order_id, amount, ip)
|
56
|
-
payment.payture = payture_mock
|
57
54
|
|
58
55
|
payment = payment.prepare
|
59
56
|
expect(payment).to be_kind_of(PaymentPrepared)
|
@@ -61,11 +58,9 @@ describe "Payment" do
|
|
61
58
|
payment = payment.block
|
62
59
|
expect(payment).to be_kind_of(PaymentBlocked)
|
63
60
|
|
64
|
-
payment.payture = payture_mock
|
65
61
|
payment = payment.charge
|
66
62
|
expect(payment).to be_kind_of(PaymentCharged)
|
67
63
|
|
68
|
-
payment.payture = payture_mock
|
69
64
|
payment = payment.refund
|
70
65
|
expect(payment).to be_kind_of(PaymentRefunded)
|
71
66
|
end
|
@@ -99,22 +94,92 @@ describe "Payment" do
|
|
99
94
|
).and_return(empty_response)
|
100
95
|
|
101
96
|
payment = PaymentNew.new(order_id, amount, ip)
|
97
|
+
|
102
98
|
payment.prepare(PaymentDescription.new(nil, nil, nil, nil))
|
103
99
|
end
|
104
100
|
|
101
|
+
let(:real_configuration) {
|
102
|
+
double('configuration').tap do |config|
|
103
|
+
allow(config).to receive(:api_for).with(:real).and_return(Api.new('secure', 'MERCHANT100100', 'password'))
|
104
|
+
end
|
105
|
+
}
|
106
|
+
|
105
107
|
it "should send valid params" do
|
106
108
|
expect(RestClient).to receive(:post).with(
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
109
|
+
"https://secure.payture.com/apim/Charge",
|
110
|
+
{
|
111
|
+
"OrderId" => order_id,
|
112
|
+
"Password" => "password",
|
113
|
+
"Key" => "MERCHANT100100"
|
114
|
+
}
|
113
115
|
).and_return(empty_response)
|
114
116
|
|
115
|
-
payment = PaymentBlocked.new(order_id, amount,
|
117
|
+
payment = PaymentBlocked.new(order_id, amount, 'session', :real)
|
118
|
+
payment.configuration = real_configuration
|
116
119
|
|
117
120
|
payment.charge
|
118
121
|
end
|
119
122
|
|
123
|
+
describe 'using same gateway when status changing' do
|
124
|
+
before do
|
125
|
+
Configuration.setup :settings do |config|
|
126
|
+
config.host = 'host'
|
127
|
+
config.key = 'key'
|
128
|
+
config.password = 'password'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'when charged' do
|
133
|
+
payture_mock.stub(:init).with(order_id, amount*100, ip, {}).and_return(session_id)
|
134
|
+
payture_mock.stub(:charge).with(order_id).and_return(true)
|
135
|
+
|
136
|
+
payment = PaymentNew.new(order_id, amount, ip, :settings)
|
137
|
+
|
138
|
+
payment = payment.prepare
|
139
|
+
expect(payment.gateway).to eq :settings
|
140
|
+
|
141
|
+
payment = payment.block
|
142
|
+
expect(payment.gateway).to eq :settings
|
143
|
+
|
144
|
+
payment = payment.charge
|
145
|
+
expect(payment.gateway).to eq :settings
|
146
|
+
end
|
147
|
+
|
148
|
+
it "when unblocked" do
|
149
|
+
payture_mock.stub(:init).with(order_id, amount*100, ip, {}).and_return(session_id)
|
150
|
+
payture_mock.stub(:unblock).with(order_id, amount*100).and_return(true)
|
151
|
+
|
152
|
+
payment = PaymentNew.new(order_id, amount, ip, :settings)
|
153
|
+
|
154
|
+
payment = payment.prepare
|
155
|
+
expect(payment.gateway).to eq :settings
|
156
|
+
|
157
|
+
payment = payment.block
|
158
|
+
expect(payment.gateway).to eq :settings
|
159
|
+
|
160
|
+
payment = payment.unblock
|
161
|
+
expect(payment.gateway).to eq :settings
|
162
|
+
end
|
163
|
+
|
164
|
+
it "when refunded" do
|
165
|
+
payture_mock.stub(:init).with(order_id, amount*100, ip, {}).and_return(session_id)
|
166
|
+
payture_mock.stub(:charge).with(order_id).and_return(true)
|
167
|
+
payture_mock.stub(:refund).with(order_id, amount*100).and_return(true)
|
168
|
+
|
169
|
+
payment = PaymentNew.new(order_id, amount, ip, :settings)
|
170
|
+
|
171
|
+
payment = payment.prepare
|
172
|
+
expect(payment.gateway).to eq :settings
|
173
|
+
|
174
|
+
payment = payment.block
|
175
|
+
expect(payment.gateway).to eq :settings
|
176
|
+
|
177
|
+
payment = payment.charge
|
178
|
+
expect(payment.gateway).to eq :settings
|
179
|
+
|
180
|
+
payment = payment.refund
|
181
|
+
expect(payment.gateway).to eq :settings
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
120
185
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Api do
|
4
|
+
|
5
|
+
let(:empty_response) { double('Request', body: '<xml />') }
|
6
|
+
let(:host) { 'secure' }
|
7
|
+
let(:key) { 'merchant' }
|
8
|
+
let(:password) { 'password' }
|
9
|
+
|
10
|
+
describe 'send request with defined host and key' do
|
11
|
+
subject { Api.new(host, key, password) }
|
12
|
+
|
13
|
+
it 'should send request with settings' do
|
14
|
+
expect(RestClient).to receive(:post).with(
|
15
|
+
"https://#{host}.payture.com/apim/Charge",
|
16
|
+
{
|
17
|
+
"OrderId" => 1,
|
18
|
+
"Password" => password,
|
19
|
+
"Key" => key
|
20
|
+
}
|
21
|
+
).and_return(empty_response)
|
22
|
+
|
23
|
+
subject.charge(1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Configuration do
|
4
|
+
context 'with default configuration' do
|
5
|
+
describe 'settings' do
|
6
|
+
subject { Configuration.instance.settings(nil) }
|
7
|
+
|
8
|
+
its(:host) { should eq 'sandbox' }
|
9
|
+
its(:key) { should eq 'MerchantRutravel' }
|
10
|
+
its(:password) { should eq '123' }
|
11
|
+
|
12
|
+
it 'should build api' do
|
13
|
+
allow(Api.any_instance).to receive(:new).with('sandbox', 'MerchantRutravel', '123')
|
14
|
+
Configuration.instance.api_for(nil)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'set up' do
|
20
|
+
context 'host' do
|
21
|
+
before do
|
22
|
+
Configuration.setup :settings do |config|
|
23
|
+
config.host = 'host'
|
24
|
+
config.key = 'key'
|
25
|
+
config.password = 'password'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
subject { Configuration.instance.settings(:settings) }
|
30
|
+
|
31
|
+
its(:host) { should eq 'host' }
|
32
|
+
its(:key) { should eq 'key' }
|
33
|
+
its(:password) { should eq 'password' }
|
34
|
+
|
35
|
+
|
36
|
+
it 'should build api' do
|
37
|
+
allow(Api.any_instance).to receive(:new).with('host', 'key', 'password')
|
38
|
+
Configuration.instance.api_for(nil)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paytureman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Kasatenko
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest_client
|
@@ -134,9 +134,12 @@ files:
|
|
134
134
|
- lib/payments/payment_with_session.rb
|
135
135
|
- lib/payture/api.rb
|
136
136
|
- lib/paytureman.rb
|
137
|
+
- lib/service/configuration.rb
|
137
138
|
- lib/service/payment_persistence.rb
|
138
139
|
- paytureman.gemspec
|
139
140
|
- spec/requests/payment_process_spec.rb
|
141
|
+
- spec/requests/payture/api_spec.rb
|
142
|
+
- spec/requests/service/configuration_spec.rb
|
140
143
|
- spec/spec_helper.rb
|
141
144
|
homepage: ''
|
142
145
|
licenses:
|
@@ -164,4 +167,6 @@ specification_version: 4
|
|
164
167
|
summary: Payture API implementation
|
165
168
|
test_files:
|
166
169
|
- spec/requests/payment_process_spec.rb
|
170
|
+
- spec/requests/payture/api_spec.rb
|
171
|
+
- spec/requests/service/configuration_spec.rb
|
167
172
|
- spec/spec_helper.rb
|