killbill-payment-test 1.8.3 → 1.8.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c58a089b0e1054f39f3c674ca442797217d1872
4
- data.tar.gz: 7277e0b8ea2176d94ab9c7385b043efdf41f9ef6
3
+ metadata.gz: d15b07f1b2de9e55be2aa7410ef913d44efc7560
4
+ data.tar.gz: dd473f58c669eef5749980bd8a4b7ceb877ed6e5
5
5
  SHA512:
6
- metadata.gz: 9057caeec3e173541c224de8f7b1eea3e30bea09e1b4880675f3cd22998bfd4b872c7533fecad1f942d9b65a902f5ccf8b4df56b019a3f0629d86332ed7f3b5a
7
- data.tar.gz: 10a5732bbefd7367621c45bf2e420d73af8f1eb9ce2b6ac6367f8abbac8d0e169a0dc2ce5d57a63ed076eaff637e51379a936be37445064ebcae11c484d5f3bc
6
+ metadata.gz: e5d2781cd1fb3da583cae4d285d52989e9f540f0d40fbc3109e8ce457c5cff9df63053f51a6fcf584ab8d077faf0ada3a67f47816364f45415b15f703cdcc341
7
+ data.tar.gz: 2d59e5316912603f004a9d83a9153e520654918c6717a1eeea3f346b8c4fe29c16aaf975cff8c24bbc2cbf671380f8814fd81931e7e78bfccca1fda12fae67e0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.8.3
1
+ 1.8.4
@@ -1,79 +1,40 @@
1
- module PaymentTest
2
- class PaymentPlugin < Killbill::Plugin::Payment
3
-
4
- def purchase_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
5
- build_transaction_info :PURCHASE, kb_payment_id, kb_payment_transaction_id, amount, currency
6
- end
7
-
8
- def get_payment_info(kb_account_id, kb_payment_id, properties, context)
9
- [build_transaction_info(:PURCHASE, kb_payment_id)]
10
- end
11
-
12
- def refund_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
13
- build_transaction_info :REFUND, kb_payment_id, kb_payment_transaction_id, amount, currency
14
- end
15
-
16
- def get_refund_info(kb_account_id, kb_payment_id, properties, context)
17
- build_transaction_info :REFUND, kb_payment_id
18
- end
19
-
20
- def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, properties, context)
21
- end
1
+ require 'payment_test/api_beatrix'
2
+ require 'payment_test/api_control'
22
3
 
23
- def delete_payment_method(kb_account_id, kb_payment_method_id, properties, context)
24
- end
25
-
26
- def get_payment_method_detail(kb_account_id, kb_payment_method_id, properties, context)
27
- res = Killbill::Plugin::Model::PaymentMethodPlugin.new
28
- res.kb_payment_method_id = "9e3ff858-809d-4d12-a1fa-da789e0841d"
29
- res.external_payment_method_id = "external_payment_method_id"
30
- res.is_default_payment_method = true
31
- properties = []
32
- prop1 = Killbill::Plugin::Model::PluginProperty.new
33
- prop1.key = "key1"
34
- prop1.value = "value1"
35
- properties << prop1
36
- prop2 = Killbill::Plugin::Model::PluginProperty.new
37
- prop2.key = "key2"
38
- prop2.value = "value2"
39
- properties << prop2
40
- res.properties=properties
41
- res
42
- end
43
-
44
- def set_default_payment_method(kb_account_id, kb_payment_method_id, properties, context)
45
- end
46
-
47
- def get_payment_methods(kb_account_id, refresh_from_gateway, properties, context)
48
- res = Killbill::Plugin::Model::PaymentMethodInfoPlugin.new
49
- res.account_id = kb_account_id
50
- res.payment_method_id = kb_account_id
51
- res.is_default = true
52
- res.external_payment_method_id = "external_payment_method_id"
53
- [res]
54
- end
55
-
56
- def search_payment_methods(search_key, offset = 0, limit = 100, properties, context)
57
- [get_payment_method_detail(nil, nil, properties, context)]
58
- end
59
-
60
- private
4
+ module PaymentTest
61
5
 
62
- def build_transaction_info(transaction_type, kb_payment_id, kb_payment_transaction_id=nil, amount=0, currency=:USD)
63
- res = Killbill::Plugin::Model::PaymentTransactionInfoPlugin.new
64
- res.kb_payment_id = kb_payment_id
65
- res.kb_transaction_payment_id = kb_payment_transaction_id
66
- res.transaction_type = transaction_type
67
- res.amount = amount
68
- res.currency = currency
69
- res.created_date = DateTime.now
70
- res.effective_date = DateTime.now
71
- res.status = :PROCESSED
72
- res.gateway_error = "gateway_error"
73
- res.gateway_error_code = "gateway_error_code"
74
- res.first_payment_reference_id = "first_payment_reference_id"
75
- res.second_payment_reference_id = "second_payment_reference_id"
76
- res
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
12
+ attr_reader :api_beatrix, :api_control
13
+
14
+ def initialize
15
+ super
16
+ @api_beatrix = PaymentPluginBeatrix.new(self)
17
+ @api_control = PaymentPluginControl.new(self)
18
+ end
19
+
20
+
21
+ def method_missing(method, *args, &block)
22
+ # properties is always the second last argument right before context
23
+ properties = args[args.length - 2]
24
+
25
+ if properties && (!properties.is_a? Hash)
26
+ raise ArgumentError.new "properties should be a Hash"
27
+ end
28
+
29
+ # Default to Beatrix (nil properties, no key specified, or explicit key)
30
+ if properties.nil? ||
31
+ (!properties.has_key? 'TEST_MODE') ||
32
+ properties['TEST_MODE'] == 'BEATRIX'
33
+ @api_beatrix.send method, *args
34
+ else
35
+ @api_control.sleep_if_required properties
36
+ @api_control.send method, *args
37
+ end
77
38
  end
78
39
  end
79
40
  end
@@ -0,0 +1,108 @@
1
+ module PaymentTest
2
+ class PaymentPluginBeatrix
3
+
4
+ attr_reader :parent
5
+
6
+ def initialize(parent)
7
+ @parent = parent
8
+ end
9
+
10
+
11
+ def authorize_payment(kb_account_id, kb_payment_id, kb_transaction_id, kb_payment_method_id, amount, currency, properties, context)
12
+ end
13
+
14
+ def capture_payment(kb_account_id, kb_payment_id, kb_transaction_id, kb_payment_method_id, amount, currency, properties, context)
15
+ end
16
+
17
+ def purchase_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
18
+ build_transaction_info :PURCHASE, kb_payment_id, kb_payment_transaction_id, amount, currency
19
+ end
20
+
21
+ def void_payment(kb_account_id, kb_payment_id, kb_transaction_id, kb_payment_method_id, properties, context)
22
+ end
23
+
24
+ def credit_payment(kb_account_id, kb_payment_id, kb_transaction_id, kb_payment_method_id, amount, currency, properties, context)
25
+ end
26
+
27
+ def refund_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
28
+ build_transaction_info :REFUND, kb_payment_id, kb_payment_transaction_id, amount, currency
29
+ end
30
+
31
+ def get_payment_info(kb_account_id, kb_payment_id, properties, context)
32
+ [build_transaction_info(:PURCHASE, kb_payment_id)]
33
+ end
34
+
35
+ def search_payments(searchKey, offset, limit, properties, context)
36
+ [get_payment_method_detail(nil, nil, properties, context)]
37
+ end
38
+
39
+ def add_payment_method(kb_account_id, kb_payment_method_id, paymentMethodProps, setDefault, properties, context)
40
+ end
41
+
42
+ def delete_payment_method(kb_account_id, kb_payment_method_id, properties, context)
43
+ end
44
+
45
+ def get_payment_method_detail(kb_account_id, kb_payment_method_id, properties, context)
46
+ res = Killbill::Plugin::Model::PaymentMethodPlugin.new
47
+ res.kb_payment_method_id = "9e3ff858-809d-4d12-a1fa-da789e0841d"
48
+ res.external_payment_method_id = "external_payment_method_id"
49
+ res.is_default_payment_method = true
50
+ properties = []
51
+ prop1 = Killbill::Plugin::Model::PluginProperty.new
52
+ prop1.key = "key1"
53
+ prop1.value = "value1"
54
+ properties << prop1
55
+ prop2 = Killbill::Plugin::Model::PluginProperty.new
56
+ prop2.key = "key2"
57
+ prop2.value = "value2"
58
+ properties << prop2
59
+ res.properties=properties
60
+ res
61
+ end
62
+
63
+ def set_default_payment_method(kb_account_id, kb_payment_method_id, properties, context)
64
+ end
65
+
66
+ def get_payment_methods(kb_account_id, refreshFromGateway, properties, context)
67
+ res = Killbill::Plugin::Model::PaymentMethodInfoPlugin.new
68
+ res.account_id = kb_account_id
69
+ res.payment_method_id = kb_account_id
70
+ res.is_default = true
71
+ res.external_payment_method_id = "external_payment_method_id"
72
+ [res]
73
+ end
74
+
75
+ def search_payment_methods(searchKey, offset, limit, properties, context)
76
+ [Killbill::Plugin::Model::PaymentMethodInfoPlugin.new]
77
+ end
78
+
79
+ def reset_payment_methods(kb_account_id, paymentMethods, properties, context)
80
+ end
81
+
82
+ def build_form_descriptor(kb_account_id, customFields, properties, context)
83
+ end
84
+
85
+ def process_notification(notification, properties, context)
86
+ end
87
+
88
+
89
+ private
90
+
91
+ def build_transaction_info(transaction_type, kb_payment_id, kb_payment_transaction_id=nil, amount=0, currency=:USD)
92
+ res = Killbill::Plugin::Model::PaymentTransactionInfoPlugin.new
93
+ res.kb_payment_id = kb_payment_id
94
+ res.kb_transaction_payment_id = kb_payment_transaction_id
95
+ res.transaction_type = transaction_type
96
+ res.amount = amount
97
+ res.currency = currency
98
+ res.created_date = DateTime.now
99
+ res.effective_date = DateTime.now
100
+ res.status = :PROCESSED
101
+ res.gateway_error = "gateway_error"
102
+ res.gateway_error_code = "gateway_error_code"
103
+ res.first_payment_reference_id = "first_payment_reference_id"
104
+ res.second_payment_reference_id = "second_payment_reference_id"
105
+ res
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,146 @@
1
+ module PaymentTest
2
+ class PaymentPluginControl
3
+
4
+
5
+ class Payment
6
+ attr_reader :kb_account_id, :kb_payment_id, :transactions
7
+
8
+ def initialize(kb_account_id, kb_payment_id)
9
+ @kb_account_id = kb_account_id
10
+ @kb_payment_id = kb_payment_id
11
+ @transactions = Array.new
12
+ end
13
+
14
+ def add_transaction(transaction)
15
+ @transactions << transaction
16
+ end
17
+ end
18
+
19
+ attr_reader :parent, :payments
20
+
21
+ def initialize(parent)
22
+ @parent = parent
23
+ @payments = Hash.new
24
+ end
25
+
26
+ def authorize_payment(kb_account_id, kb_payment_id, kb_transaction_id, kb_payment_method_id, amount, currency, properties, context)
27
+ add_transaction(kb_account_id, kb_payment_id, kb_transaction_id, :AUTHORIZE, amount, currency, properties)
28
+ end
29
+
30
+ def capture_payment(kb_account_id, kb_payment_id, kb_transaction_id, kb_payment_method_id, amount, currency, properties, context)
31
+ add_transaction(kb_account_id, kb_payment_id, kb_transaction_id, :CAPTURE, amount, currency, properties)
32
+ end
33
+
34
+ def purchase_payment(kb_account_id, kb_payment_id, kb_transaction_id, kb_payment_method_id, amount, currency, properties, context)
35
+ add_transaction(kb_account_id, kb_payment_id, kb_transaction_id, :PURCHASE, amount, currency, properties)
36
+ end
37
+
38
+ def void_payment(kb_account_id, kb_payment_id, kb_transaction_id, kb_payment_method_id, properties, context)
39
+ add_transaction(kb_account_id, kb_payment_id, kb_transaction_id, :VOID, amount, currency, properties)
40
+ end
41
+
42
+ def credit_payment(kb_account_id, kb_payment_id, kb_transaction_id, kb_payment_method_id, amount, currency, properties, context)
43
+ add_transaction(kb_account_id, kb_payment_id, kb_transaction_id, :CREDIT, amount, currency, properties)
44
+ end
45
+
46
+ def refund_payment(kb_account_id, kb_payment_id, kb_transaction_id, kb_payment_method_id, amount, currency, properties, context)
47
+ add_transaction(kb_account_id, kb_payment_id, kb_transaction_id, :REFUND, amount, currency, properties)
48
+ end
49
+
50
+ def get_payment_info(kb_account_id, kb_payment_id, properties, context)
51
+ @payments[kb_payment_id].transactions
52
+ end
53
+
54
+ def search_payments(search_key, offset, limit, properties, context)
55
+ raise NotImplementedError.new("search_payments not implemented")
56
+ end
57
+
58
+ def add_payment_method(kb_account_id, kb_payment_method_id, payment_method_props, set_default, properties, context)
59
+ # Noop
60
+ end
61
+
62
+ def delete_payment_method(kb_account_id, kb_payment_method_id, properties, context)
63
+ # Noop
64
+ end
65
+
66
+ def get_payment_method_detail(kb_account_id, kb_payment_method_id, properties, context)
67
+ payment_method = ::Killbill::Plugin::Model::PaymentMethodInfoPlugin.new
68
+ payment_method.account_id = kb_account_id
69
+ payment_method.payment_method_id = kb_payment_method_id
70
+ payment_method
71
+ end
72
+
73
+ def set_default_payment_method(kb_account_id, kb_payment_method_id, properties, context)
74
+ # Noop
75
+ end
76
+
77
+ def get_payment_methods(kb_account_id, refresh_from_gateway, properties, context)
78
+ raise NotImplementedError.new("get_payment_methods not implemented")
79
+ end
80
+
81
+ def search_payment_methods(search_key, offset, limit, properties, context)
82
+ raise NotImplementedError.new("search_payment_methods not implemented")
83
+ end
84
+
85
+ def reset_payment_methods(kb_account_id, payment_methods, properties, context)
86
+ # Noop
87
+ end
88
+
89
+ def build_form_descriptor(kb_account_id, customFields, properties, context)
90
+ raise NotImplementedError.new("build_form_descriptor not implemented")
91
+ end
92
+
93
+ def process_notification(notification, properties, context)
94
+ # Noop
95
+ end
96
+
97
+
98
+ def sleep_if_required(properties)
99
+ if properties.nil? ||
100
+ (!properties.has_key? 'SLEEP_TIME_SEC')
101
+ return
102
+ end
103
+
104
+ sleep_time = properties['SLEEP_TIME_SEC']
105
+ @parent.logger "PaymentPluginControl sleeping #{sleep_time}"
106
+ sleep sleep_time
107
+ end
108
+
109
+ private
110
+
111
+ def get_or_create_payment(kb_account_id, kb_payment_id)
112
+ if !@payments.has_key? kb_payment_id
113
+ new_payment = Payment.new(kb_account_id, kb_payment_id)
114
+ @payments[kb_payment_id] = new_payment
115
+ end
116
+ @payments[kb_payment_id]
117
+ end
118
+
119
+ def add_transaction(kb_account_id, kb_payment_id, kb_transaction_id, transaction_type, amount, currency, properties)
120
+
121
+ payment = get_or_create_payment(kb_account_id, kb_payment_id)
122
+
123
+ transaction = ::Killbill::Plugin::Model::PaymentTransactionInfoPlugin.new
124
+ transaction.kb_payment_id = kb_payment_id
125
+ transaction.kb_transaction_payment_id = kb_transaction_id
126
+
127
+ transaction.transaction_type = transaction_type
128
+ transaction.amount = amount
129
+ transaction.currency = currency
130
+ transaction.status = status_from_properties(properties)
131
+
132
+ payment.add_transaction(transaction)
133
+ transaction
134
+ end
135
+
136
+
137
+ def status_from_properties(properties)
138
+ if properties.nil? ||
139
+ (!properties.has_key? 'TRANSACTION_STATUS')
140
+ return :PROCESSED
141
+ else
142
+ properties['TRANSACTION_STATUS'].to_sym
143
+ end
144
+ end
145
+ end
146
+ 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.3</version>
30
+ <version>1.8.4</version>
31
31
  <name>payment-test-plugin</name>
32
32
  <description></description>
33
33
  <scm>
@@ -5,6 +5,7 @@ require 'payment_test'
5
5
 
6
6
  describe PaymentTest::PaymentPlugin do
7
7
  before(:each) do
8
+
8
9
  kb_apis = Killbill::Plugin::KillbillApi.new("killbill-payment-test", {})
9
10
  @plugin = PaymentTest::PaymentPlugin.new
10
11
  @plugin.logger = Logger.new(STDOUT)
@@ -25,7 +26,7 @@ describe PaymentTest::PaymentPlugin do
25
26
  end
26
27
 
27
28
  it "should test charge" do
28
- output = @plugin.purchase_payment(@kb_account_id, @kb_payment_id, @kb_payment_transaction_id, @kb_payment_method_id, @amount_in_cents, @currency, [], @call_context)
29
+ output = @plugin.purchase_payment(@kb_account_id, @kb_payment_id, @kb_payment_transaction_id, @kb_payment_method_id, @amount_in_cents, @currency, nil, @call_context)
29
30
 
30
31
  output.should be_an_instance_of Killbill::Plugin::Model::PaymentTransactionInfoPlugin
31
32
  output.amount.should == @amount_in_cents
@@ -35,4 +36,32 @@ describe PaymentTest::PaymentPlugin do
35
36
  it "should test search" do
36
37
  @plugin.search_payment_methods("blah", 0, 100, nil, @call_context).size.should == 1
37
38
  end
39
+
40
+ it "should test control api" do
41
+ properties = Hash.new
42
+ properties['TEST_MODE'] = 'CONTROL'
43
+ 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
+
45
+ transaction1.should be_an_instance_of Killbill::Plugin::Model::PaymentTransactionInfoPlugin
46
+ transaction1.kb_payment_id.should == @kb_payment_id
47
+ transaction1.kb_transaction_payment_id.should == @kb_payment_transaction_id
48
+ transaction1.amount.should == @amount_in_cents
49
+ transaction1.currency.should == @currency
50
+ transaction1.transaction_type.should == :AUTHORIZE
51
+ transaction1.status.should == :PROCESSED
52
+
53
+ properties['TRANSACTION_STATUS'] = 'ERROR'
54
+
55
+ 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
+ transaction2.kb_payment_id.should == @kb_payment_id
57
+ transaction2.kb_transaction_payment_id.should == @kb_payment_transaction_id
58
+ transaction2.amount.should == @amount_in_cents
59
+ transaction2.currency.should == @currency
60
+ transaction2.transaction_type.should == :CAPTURE
61
+ transaction2.status.should == :ERROR
62
+
63
+ transactions = @plugin.get_payment_info(@kb_account_id, @kb_payment_id, properties, @call_context)
64
+ transactions.size.should == 2
65
+ end
66
+
38
67
  end
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.3
4
+ version: 1.8.4
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-12 00:00:00.000000000 Z
11
+ date: 2014-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: killbill
@@ -83,6 +83,8 @@ files:
83
83
  - killbill.properties
84
84
  - lib/payment_test.rb
85
85
  - lib/payment_test/api.rb
86
+ - lib/payment_test/api_beatrix.rb
87
+ - lib/payment_test/api_control.rb
86
88
  - pom.xml
87
89
  - release.sh
88
90
  - spec/payment_test/base_plugin_spec.rb