killbill-payment-test 1.8.4 → 1.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/payment_test/api.rb +32 -12
- data/lib/payment_test/api_control.rb +9 -13
- data/lib/payment_test/plugin_property_utils.rb +30 -0
- data/pom.xml +1 -1
- data/spec/payment_test/base_plugin_spec.rb +11 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dd0f0101a16fc924301d9374f79579b7e426323
|
4
|
+
data.tar.gz: 94beb0af3d84929338750441545b4294c4d45588
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c89ef3f1707be0df53f962fa8d2d600a42b3648fb7f5aff34dd419539f15d76442956c251bb4bdbf87a54bfa838a795f741e1e1ed6b384011889401a945de50
|
7
|
+
data.tar.gz: 843f10490a329c0d055d6ea469cce41b70bf4c2a8a8e6a0607a062df04097a0e90993dc9f2cdac9c51015d7f7ab32b5022ee01d2cc55422ebc4e36e4e6d213e4
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.8.
|
1
|
+
1.8.5
|
data/lib/payment_test/api.rb
CHANGED
@@ -1,16 +1,34 @@
|
|
1
1
|
require 'payment_test/api_beatrix'
|
2
2
|
require 'payment_test/api_control'
|
3
|
+
require 'payment_test/plugin_property_utils'
|
3
4
|
|
4
5
|
module PaymentTest
|
5
6
|
|
6
|
-
|
7
|
-
# Note we don't inherit Killbill::Plugin::Payment < Killbill::Plugin::PluginBase, but we inherit straight Killbill::Plugin::PluginBase
|
8
|
-
# to bypass the definition of all the APIs, which by default raise OperationUnsupportedByGatewayError. That way, any API call
|
9
|
-
# goes straight into method_missing, and the correct delegate dispatching can happen.
|
10
|
-
#
|
11
|
-
class PaymentPlugin < Killbill::Plugin::PluginBase
|
7
|
+
class PaymentPlugin < Killbill::Plugin::Payment
|
12
8
|
attr_reader :api_beatrix, :api_control
|
13
9
|
|
10
|
+
#
|
11
|
+
# undef all methods defined in Killbill::Plugin::Payment that throw by default OperationUnsupportedByGatewayError
|
12
|
+
# so we get directed straight to the method_missing handler
|
13
|
+
#
|
14
|
+
undef_method :authorize_payment
|
15
|
+
undef_method :capture_payment
|
16
|
+
undef_method :purchase_payment
|
17
|
+
undef_method :void_payment
|
18
|
+
undef_method :credit_payment
|
19
|
+
undef_method :refund_payment
|
20
|
+
undef_method :get_payment_info
|
21
|
+
undef_method :search_payments
|
22
|
+
undef_method :add_payment_method
|
23
|
+
undef_method :delete_payment_method
|
24
|
+
undef_method :get_payment_method_detail
|
25
|
+
undef_method :set_default_payment_method
|
26
|
+
undef_method :get_payment_methods
|
27
|
+
undef_method :search_payment_methods
|
28
|
+
undef_method :reset_payment_methods
|
29
|
+
undef_method :build_form_descriptor
|
30
|
+
undef_method :process_notification
|
31
|
+
|
14
32
|
def initialize
|
15
33
|
super
|
16
34
|
@api_beatrix = PaymentPluginBeatrix.new(self)
|
@@ -22,19 +40,21 @@ module PaymentTest
|
|
22
40
|
# properties is always the second last argument right before context
|
23
41
|
properties = args[args.length - 2]
|
24
42
|
|
25
|
-
|
26
|
-
|
27
|
-
|
43
|
+
# Let's be cautious..
|
44
|
+
PluginPropertyUtils.validate_properties(properties)
|
45
|
+
|
46
|
+
# Extract TEST_MODE property if it exists
|
47
|
+
test_prop = PluginPropertyUtils::get_property_or_nil(properties, 'TEST_MODE')
|
28
48
|
|
29
49
|
# Default to Beatrix (nil properties, no key specified, or explicit key)
|
30
|
-
if
|
31
|
-
|
32
|
-
properties['TEST_MODE'] == 'BEATRIX'
|
50
|
+
if test_prop.nil? ||
|
51
|
+
test_prop.value == 'BEATRIX'
|
33
52
|
@api_beatrix.send method, *args
|
34
53
|
else
|
35
54
|
@api_control.sleep_if_required properties
|
36
55
|
@api_control.send method, *args
|
37
56
|
end
|
38
57
|
end
|
58
|
+
|
39
59
|
end
|
40
60
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'payment_test/plugin_property_utils'
|
2
|
+
|
1
3
|
module PaymentTest
|
2
4
|
class PaymentPluginControl
|
3
5
|
|
@@ -96,14 +98,12 @@ module PaymentTest
|
|
96
98
|
|
97
99
|
|
98
100
|
def sleep_if_required(properties)
|
99
|
-
|
100
|
-
|
101
|
-
|
101
|
+
sleep_prop = PluginPropertyUtils::get_property_or_nil(properties, 'SLEEP_TIME_SEC')
|
102
|
+
if sleep_prop
|
103
|
+
sleep_time = sleep_prop.value.to_f
|
104
|
+
@parent.logger.info "PaymentPluginControl sleeping #{sleep_time}"
|
105
|
+
sleep sleep_time
|
102
106
|
end
|
103
|
-
|
104
|
-
sleep_time = properties['SLEEP_TIME_SEC']
|
105
|
-
@parent.logger "PaymentPluginControl sleeping #{sleep_time}"
|
106
|
-
sleep sleep_time
|
107
107
|
end
|
108
108
|
|
109
109
|
private
|
@@ -135,12 +135,8 @@ module PaymentTest
|
|
135
135
|
|
136
136
|
|
137
137
|
def status_from_properties(properties)
|
138
|
-
|
139
|
-
|
140
|
-
return :PROCESSED
|
141
|
-
else
|
142
|
-
properties['TRANSACTION_STATUS'].to_sym
|
143
|
-
end
|
138
|
+
status_prop = PluginPropertyUtils::get_property_or_nil(properties, 'TRANSACTION_STATUS')
|
139
|
+
status_prop.nil? ? :PROCESSED : status_prop.value.to_sym
|
144
140
|
end
|
145
141
|
end
|
146
142
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module PaymentTest
|
2
|
+
|
3
|
+
class PluginPropertyUtils
|
4
|
+
|
5
|
+
def self.get_property_or_nil(properties, key_name)
|
6
|
+
test_props = (properties || []).select { |e| e.key == key_name }
|
7
|
+
if test_props.size > 1
|
8
|
+
raise ArgumentError.new "multiple property with key #{key_name} is not allowed"
|
9
|
+
end
|
10
|
+
test_props.size == 1 ? test_props[0] : nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.validate_properties(properties)
|
14
|
+
if properties.nil?
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
18
|
+
if !properties.is_a? Array
|
19
|
+
raise ArgumentError.new "properties should be an Array"
|
20
|
+
end
|
21
|
+
|
22
|
+
properties.each do |p|
|
23
|
+
if !p.is_a? Killbill::Plugin::Model::PluginProperty
|
24
|
+
raise ArgumentError.new "Each property should be of type Killbill::Plugin::Model::PluginProperty"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/pom.xml
CHANGED
@@ -27,7 +27,7 @@
|
|
27
27
|
<groupId>org.kill-bill.billing.plugin.ruby</groupId>
|
28
28
|
<artifactId>payment-test-plugin</artifactId>
|
29
29
|
<packaging>pom</packaging>
|
30
|
-
<version>1.8.
|
30
|
+
<version>1.8.5</version>
|
31
31
|
<name>payment-test-plugin</name>
|
32
32
|
<description></description>
|
33
33
|
<scm>
|
@@ -38,8 +38,13 @@ describe PaymentTest::PaymentPlugin do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should test control api" do
|
41
|
-
|
42
|
-
properties
|
41
|
+
|
42
|
+
properties = []
|
43
|
+
prop_test_mode = Killbill::Plugin::Model::PluginProperty.new
|
44
|
+
prop_test_mode.key = 'TEST_MODE'
|
45
|
+
prop_test_mode.value = 'CONTROL'
|
46
|
+
properties << prop_test_mode
|
47
|
+
|
43
48
|
transaction1 = @plugin.authorize_payment(@kb_account_id, @kb_payment_id, @kb_payment_transaction_id, @kb_payment_method_id, @amount_in_cents, @currency, properties, @call_context)
|
44
49
|
|
45
50
|
transaction1.should be_an_instance_of Killbill::Plugin::Model::PaymentTransactionInfoPlugin
|
@@ -50,7 +55,10 @@ describe PaymentTest::PaymentPlugin do
|
|
50
55
|
transaction1.transaction_type.should == :AUTHORIZE
|
51
56
|
transaction1.status.should == :PROCESSED
|
52
57
|
|
53
|
-
|
58
|
+
prop_status = Killbill::Plugin::Model::PluginProperty.new
|
59
|
+
prop_status.key = 'TRANSACTION_STATUS'
|
60
|
+
prop_status.value = 'ERROR'
|
61
|
+
properties << prop_status
|
54
62
|
|
55
63
|
transaction2 = @plugin.capture_payment(@kb_account_id, @kb_payment_id, @kb_payment_transaction_id, @kb_payment_method_id, @amount_in_cents, @currency, properties, @call_context)
|
56
64
|
transaction2.kb_payment_id.should == @kb_payment_id
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: killbill-payment-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kill Bill core team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: killbill
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/payment_test/api.rb
|
86
86
|
- lib/payment_test/api_beatrix.rb
|
87
87
|
- lib/payment_test/api_control.rb
|
88
|
+
- lib/payment_test/plugin_property_utils.rb
|
88
89
|
- pom.xml
|
89
90
|
- release.sh
|
90
91
|
- spec/payment_test/base_plugin_spec.rb
|