paytureman 0.3.0 → 0.5.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/.gitignore +1 -0
- data/lib/payments/payment_new.rb +10 -2
- data/lib/payture/api.rb +9 -5
- data/lib/paytureman.rb +1 -0
- data/paytureman.gemspec +3 -3
- data/spec/requests/payment_process_spec.rb +50 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecfb2af79747d781ab577d9424ec75fa87b0aed5
|
4
|
+
data.tar.gz: 3cacba04b75c0ee01b23ea637011c4d76985aa3a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dc7562f7b30eedfae776d7e1f5d3227134972b7cd18278b35e6fe2d91023de33ba412d47820c650280da0a34ec5101c84db296ae7c942d02728b034a043877c
|
7
|
+
data.tar.gz: dc4fa2ff9f82487982cdeccd3d9a11a3204cbd4d53259badc409b8416d76a796b984d7056a158c15bf9e389d4de4d18afa9f5b551b0b4d5e0f335240608915ca
|
data/.gitignore
CHANGED
data/lib/payments/payment_new.rb
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
module Paytureman
|
2
2
|
|
3
|
+
class PaymentDescription < Struct.new(:product, :total, :template_tag, :language)
|
4
|
+
|
5
|
+
def to_h
|
6
|
+
super.select { |_, v| v.present? }
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
3
11
|
class PaymentNew < Payment
|
4
12
|
|
5
|
-
def prepare
|
6
|
-
session_id = payture.init(self.order_id, (self.amount*100).round, self.ip)
|
13
|
+
def prepare(description = PaymentDescription.new)
|
14
|
+
session_id = payture.init(self.order_id, (self.amount*100).round, self.ip, description.to_h)
|
7
15
|
if session_id
|
8
16
|
PaymentPrepared.new(self.order_id, self.amount, self.ip, session_id)
|
9
17
|
else
|
data/lib/payture/api.rb
CHANGED
@@ -4,9 +4,13 @@ module Paytureman
|
|
4
4
|
|
5
5
|
attr_accessor :rest_client
|
6
6
|
|
7
|
-
def init(order_id, amount, ip)
|
7
|
+
def init(order_id, amount, ip, description = {})
|
8
|
+
|
9
|
+
data = { SessionType: :Block, OrderId: order_id, Amount: amount, IP: ip }
|
10
|
+
data.merge!(description)
|
11
|
+
|
8
12
|
init_params = {
|
9
|
-
|
13
|
+
'Data' => URI.escape(data.map { |a| a.join('=').camelize }.join(';'))
|
10
14
|
}
|
11
15
|
|
12
16
|
response = make_request(:init, init_params)
|
@@ -42,9 +46,9 @@ module Paytureman
|
|
42
46
|
|
43
47
|
def make_request(method, params)
|
44
48
|
params = Hash[
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
params.merge(key: 'MerchantRutravel').
|
50
|
+
map { |k, v| [ k.to_s.camelize, v ] }
|
51
|
+
]
|
48
52
|
response = rest_client.post "https://sandbox.payture.com/apim/#{method.to_s.camelize}", params
|
49
53
|
puts response.body
|
50
54
|
return nil if response.body.empty?
|
data/lib/paytureman.rb
CHANGED
data/paytureman.gemspec
CHANGED
@@ -4,9 +4,9 @@ $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.
|
8
|
-
spec.authors = ["Ivan Kasatenko", "Nickolay Sverchkov"]
|
9
|
-
spec.email = ["
|
7
|
+
spec.version = "0.5.0"
|
8
|
+
spec.authors = ["Ivan Kasatenko", "Nickolay Sverchkov", "Alexander Fomin"]
|
9
|
+
spec.email = ["contact@uniqsystems.ru"]
|
10
10
|
spec.summary = %q{Payture API implementation}
|
11
11
|
spec.description = %q{Payture InPay API implementation}
|
12
12
|
spec.homepage = ""
|
@@ -6,9 +6,10 @@ describe "Payment" do
|
|
6
6
|
let(:amount) { 123.45 }
|
7
7
|
let(:ip) { '123.45.67.89' }
|
8
8
|
let(:session_id) { SecureRandom.uuid }
|
9
|
+
|
9
10
|
let(:payture_mock) {
|
10
11
|
double("Payture").tap do |mock|
|
11
|
-
expect(mock).to receive(:init).with(order_id, amount*100, ip).and_return(session_id)
|
12
|
+
expect(mock).to receive(:init).with(order_id, amount*100, ip, {}).and_return(session_id)
|
12
13
|
end
|
13
14
|
}
|
14
15
|
|
@@ -19,6 +20,7 @@ describe "Payment" do
|
|
19
20
|
payment.payture = payture_mock
|
20
21
|
|
21
22
|
payment = payment.prepare
|
23
|
+
|
22
24
|
expect(payment).to be_kind_of(PaymentPrepared)
|
23
25
|
|
24
26
|
payment = payment.block
|
@@ -68,4 +70,51 @@ describe "Payment" do
|
|
68
70
|
expect(payment).to be_kind_of(PaymentRefunded)
|
69
71
|
end
|
70
72
|
|
73
|
+
let(:init_payment_url) { "https://sandbox.payture.com/apim/Init" }
|
74
|
+
let(:empty_response) { double('Request', body: '<xml />') }
|
75
|
+
let(:product) { 'Order payment' }
|
76
|
+
let(:total) { 1231 }
|
77
|
+
|
78
|
+
it "should use additional params on request" do
|
79
|
+
expect(RestClient).to receive(:post).with(
|
80
|
+
init_payment_url,
|
81
|
+
{
|
82
|
+
"Data" => "SessionType=Block;OrderId=#{order_id};Amount=#{(amount*100).to_i};IP=#{ip};Product=#{URI.escape(product)};Total=#{total}",
|
83
|
+
"Key" => "MerchantRutravel"
|
84
|
+
}
|
85
|
+
).and_return(empty_response)
|
86
|
+
|
87
|
+
payment = PaymentNew.new(order_id, amount, ip)
|
88
|
+
|
89
|
+
payment.prepare(PaymentDescription.new(product, total))
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should not use description in request if they not defined" do
|
93
|
+
expect(RestClient).to receive(:post).with(
|
94
|
+
init_payment_url,
|
95
|
+
{
|
96
|
+
"Data" => "SessionType=Block;OrderId=#{order_id};Amount=#{(amount*100).to_i};IP=#{ip}",
|
97
|
+
"Key" => "MerchantRutravel"
|
98
|
+
}
|
99
|
+
).and_return(empty_response)
|
100
|
+
|
101
|
+
payment = PaymentNew.new(order_id, amount, ip)
|
102
|
+
payment.prepare(PaymentDescription.new(nil, nil, nil, nil))
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should send valid params" do
|
106
|
+
expect(RestClient).to receive(:post).with(
|
107
|
+
"https://sandbox.payture.com/apim/Charge",
|
108
|
+
{
|
109
|
+
"OrderId" => order_id,
|
110
|
+
"Password" => "123",
|
111
|
+
"Key" => "MerchantRutravel"
|
112
|
+
}
|
113
|
+
).and_return(empty_response)
|
114
|
+
|
115
|
+
payment = PaymentBlocked.new(order_id, amount, ip, 'session')
|
116
|
+
|
117
|
+
payment.charge
|
118
|
+
end
|
119
|
+
|
71
120
|
end
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paytureman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Kasatenko
|
8
8
|
- Nickolay Sverchkov
|
9
|
+
- Alexander Fomin
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
13
|
+
date: 2014-04-28 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rest_client
|
@@ -111,7 +112,7 @@ dependencies:
|
|
111
112
|
version: '0'
|
112
113
|
description: Payture InPay API implementation
|
113
114
|
email:
|
114
|
-
-
|
115
|
+
- contact@uniqsystems.ru
|
115
116
|
executables: []
|
116
117
|
extensions: []
|
117
118
|
extra_rdoc_files: []
|