paytureman 0.2.0 → 0.3.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/.rspec +1 -1
- data/lib/payments/payment.rb +10 -9
- data/lib/payments/payment_charged.rb +7 -0
- data/lib/payments/payment_prepared.rb +2 -2
- data/lib/payments/payment_refunded.rb +6 -0
- data/lib/payments/payment_with_session.rb +7 -7
- data/lib/payture/api.rb +8 -3
- data/lib/paytureman.rb +1 -0
- data/lib/service/payment_persistence.rb +3 -3
- data/paytureman.gemspec +2 -2
- data/spec/requests/payment_process_spec.rb +27 -5
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a03ccebbf30e38c8f018192cff679b2b095b8970
|
4
|
+
data.tar.gz: f3530763d1ef951108a6310da690db417c22180b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 656054e162832c5e0e306bf6c69c7179891a790212f1c615b35388364e28f25750d8d65d66a2f5d27f13f6615f816e3b6e50e206dcc71f00c5b47f3af875cf3c
|
7
|
+
data.tar.gz: e6efde9c23365f7604cb89894eed419f2909d42e47b573e30819306cce03cfeda242a5919a2220db822648a83f2d0d580474cc2c196732f7c31d463257c4f8e8
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
--color
|
2
|
-
--format doc
|
2
|
+
--format doc
|
data/lib/payments/payment.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
module Paytureman
|
2
|
-
|
2
|
+
|
3
3
|
class Payment
|
4
|
-
|
4
|
+
|
5
5
|
attr_reader :order_id
|
6
6
|
|
7
7
|
def initialize(order_id, amount, ip)
|
8
8
|
@order_id, @amount, @ip = order_id, amount, ip
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def save_to_memento(memento)
|
12
12
|
memento.order_id, memento.amount, memento.ip = order_id, amount, ip
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def self.new_from_memento(memento)
|
16
16
|
new(memento.order_id, memento.amount, memento.ip)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def self.new_from_payment(donor)
|
20
20
|
memento = OpenStruct.new
|
21
21
|
donor.save_to_memento(memento)
|
@@ -28,18 +28,19 @@ module Paytureman
|
|
28
28
|
:prepared => PaymentPrepared,
|
29
29
|
:authorized => PaymentBlocked,
|
30
30
|
:voided => PaymentCancelled,
|
31
|
-
:charged => PaymentCharged
|
31
|
+
:charged => PaymentCharged,
|
32
|
+
:refund => PaymentRefunded
|
32
33
|
}[payture.status(order_id)] || PaymentUnknown
|
33
34
|
current_payment_type.new_from_payment(self)
|
34
35
|
end
|
35
36
|
|
36
37
|
attr_accessor :payture
|
37
|
-
|
38
|
+
|
38
39
|
protected
|
39
|
-
|
40
|
+
|
40
41
|
attr_accessor :amount, :ip
|
41
42
|
attr_writer :order_id
|
42
|
-
|
43
|
+
|
43
44
|
def payture
|
44
45
|
@payture ||= Api.instance
|
45
46
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Paytureman
|
2
|
-
|
2
|
+
|
3
3
|
class PaymentWithSession < Payment
|
4
|
-
|
4
|
+
|
5
5
|
def initialize(order_id, amount, ip, session_id)
|
6
6
|
@session_id = session_id
|
7
7
|
super(order_id, amount, ip)
|
@@ -11,15 +11,15 @@ module Paytureman
|
|
11
11
|
memento.session_id = session_id
|
12
12
|
super(memento)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def self.new_from_memento(memento)
|
16
16
|
new(memento.order_id, memento.amount, memento.ip, memento.session_id)
|
17
|
-
end
|
18
|
-
|
17
|
+
end
|
18
|
+
|
19
19
|
protected
|
20
|
-
|
20
|
+
|
21
21
|
attr_accessor :session_id
|
22
|
-
|
22
|
+
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
data/lib/payture/api.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Paytureman
|
2
2
|
class Api
|
3
3
|
include Singleton
|
4
|
-
|
4
|
+
|
5
5
|
attr_accessor :rest_client
|
6
|
-
|
6
|
+
|
7
7
|
def init(order_id, amount, ip)
|
8
8
|
init_params = {
|
9
9
|
data: "SessionType=Block;OrderId=#{order_id};Amount=#{amount};IP=#{ip}",
|
@@ -17,7 +17,12 @@ module Paytureman
|
|
17
17
|
response = make_request(:charge, order_id: order_id, password: '123')
|
18
18
|
response[:success]
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
|
+
def refund(order_id, amount)
|
22
|
+
response = make_request(:refund, order_id: order_id, amount: amount, password: '123')
|
23
|
+
response[:success]
|
24
|
+
end
|
25
|
+
|
21
26
|
def unblock(order_id, amount)
|
22
27
|
response = make_request(:unblock, order_id: order_id, amount: amount, password: '123')
|
23
28
|
response[:success]
|
data/lib/paytureman.rb
CHANGED
@@ -12,6 +12,7 @@ require_relative 'payments/payment_new'
|
|
12
12
|
require_relative 'payments/payment_prepared'
|
13
13
|
require_relative 'payments/payment_blocked'
|
14
14
|
require_relative 'payments/payment_charged'
|
15
|
+
require_relative 'payments/payment_refunded'
|
15
16
|
require_relative 'payments/payment_cancelled'
|
16
17
|
require_relative 'payments/payment_unknown'
|
17
18
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module Paytureman
|
2
2
|
|
3
3
|
class PaymentPersistence
|
4
|
-
|
4
|
+
|
5
5
|
include Singleton
|
6
|
-
|
6
|
+
|
7
7
|
def load(memento)
|
8
8
|
memento.type.constantize.new_from_memento(memento)
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def save(payment, memento)
|
12
12
|
payment.save_to_memento(memento)
|
13
13
|
memento.type = payment.class.name
|
data/paytureman.gemspec
CHANGED
@@ -4,8 +4,8 @@ $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"]
|
7
|
+
spec.version = "0.3.0"
|
8
|
+
spec.authors = ["Ivan Kasatenko", "Nickolay Sverchkov"]
|
9
9
|
spec.email = ["ivan@uniqsystems.ru"]
|
10
10
|
spec.summary = %q{Payture API implementation}
|
11
11
|
spec.description = %q{Payture InPay API implementation}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Payment" do
|
4
|
-
|
4
|
+
|
5
5
|
let(:order_id) { SecureRandom.uuid }
|
6
6
|
let(:amount) { 123.45 }
|
7
7
|
let(:ip) { '123.45.67.89' }
|
@@ -11,7 +11,7 @@ describe "Payment" do
|
|
11
11
|
expect(mock).to receive(:init).with(order_id, amount*100, ip).and_return(session_id)
|
12
12
|
end
|
13
13
|
}
|
14
|
-
|
14
|
+
|
15
15
|
it "should charge successfully" do
|
16
16
|
expect(payture_mock).to receive(:charge).with(order_id, session_id).and_return(true)
|
17
17
|
|
@@ -20,7 +20,7 @@ describe "Payment" do
|
|
20
20
|
|
21
21
|
payment = payment.prepare
|
22
22
|
expect(payment).to be_kind_of(PaymentPrepared)
|
23
|
-
|
23
|
+
|
24
24
|
payment = payment.block
|
25
25
|
expect(payment).to be_kind_of(PaymentBlocked)
|
26
26
|
|
@@ -28,7 +28,7 @@ describe "Payment" do
|
|
28
28
|
payment = payment.charge
|
29
29
|
expect(payment).to be_kind_of(PaymentCharged)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
it "should unblock successfully" do
|
33
33
|
expect(payture_mock).to receive(:unblock).with(order_id, amount*100).and_return(true)
|
34
34
|
|
@@ -37,7 +37,7 @@ describe "Payment" do
|
|
37
37
|
|
38
38
|
payment = payment.prepare
|
39
39
|
expect(payment).to be_kind_of(PaymentPrepared)
|
40
|
-
|
40
|
+
|
41
41
|
payment = payment.block
|
42
42
|
expect(payment).to be_kind_of(PaymentBlocked)
|
43
43
|
|
@@ -46,4 +46,26 @@ describe "Payment" do
|
|
46
46
|
expect(payment).to be_kind_of(PaymentCancelled)
|
47
47
|
end
|
48
48
|
|
49
|
+
it "should refund successfully" do
|
50
|
+
expect(payture_mock).to receive(:charge).with(order_id, session_id).and_return(true)
|
51
|
+
expect(payture_mock).to receive(:refund).with(order_id, amount*100).and_return(true)
|
52
|
+
|
53
|
+
payment = PaymentNew.new(order_id, amount, ip)
|
54
|
+
payment.payture = payture_mock
|
55
|
+
|
56
|
+
payment = payment.prepare
|
57
|
+
expect(payment).to be_kind_of(PaymentPrepared)
|
58
|
+
|
59
|
+
payment = payment.block
|
60
|
+
expect(payment).to be_kind_of(PaymentBlocked)
|
61
|
+
|
62
|
+
payment.payture = payture_mock
|
63
|
+
payment = payment.charge
|
64
|
+
expect(payment).to be_kind_of(PaymentCharged)
|
65
|
+
|
66
|
+
payment.payture = payture_mock
|
67
|
+
payment = payment.refund
|
68
|
+
expect(payment).to be_kind_of(PaymentRefunded)
|
69
|
+
end
|
70
|
+
|
49
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paytureman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Kasatenko
|
8
|
+
- Nickolay Sverchkov
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rest_client
|
@@ -127,6 +128,7 @@ files:
|
|
127
128
|
- lib/payments/payment_charged.rb
|
128
129
|
- lib/payments/payment_new.rb
|
129
130
|
- lib/payments/payment_prepared.rb
|
131
|
+
- lib/payments/payment_refunded.rb
|
130
132
|
- lib/payments/payment_unknown.rb
|
131
133
|
- lib/payments/payment_with_session.rb
|
132
134
|
- lib/payture/api.rb
|