killbill-braintree_blue 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Killbill::BraintreeBlue::BraintreeBlueResponse do
4
+ before :all do
5
+ Killbill::BraintreeBlue::BraintreeBlueResponse.delete_all
6
+ end
7
+
8
+ it 'should search all fields' do
9
+ kb_account_id = '33-44-55-66'
10
+ kb_tenant_id = '77-88-99-00'
11
+
12
+ do_search('foo', kb_tenant_id).size.should == 0
13
+
14
+ pm = Killbill::BraintreeBlue::BraintreeBlueResponse.create :api_call => 'charge',
15
+ :kb_payment_id => '11-22-33-44',
16
+ :kb_account_id => kb_account_id,
17
+ :kb_tenant_id => kb_tenant_id,
18
+ :authorization => 'aa-bb-cc-dd',
19
+ :params_braintree_customer_id => '123456',
20
+ :params_braintree_customer_credit_card_token => '38102343',
21
+ :success => true
22
+ # Not successful
23
+ ignored2 = Killbill::BraintreeBlue::BraintreeBlueResponse.create :api_call => 'charge',
24
+ :kb_payment_id => pm.kb_payment_id,
25
+ :kb_account_id => kb_account_id,
26
+ :kb_tenant_id => kb_tenant_id,
27
+ :authorization => pm.authorization,
28
+ :params_braintree_customer_id => pm.params_braintree_customer_id,
29
+ :params_braintree_customer_credit_card_token => pm.params_braintree_customer_credit_card_token,
30
+ :success => false
31
+
32
+ do_search('foo', kb_tenant_id).size.should == 0
33
+ do_search(pm.authorization, kb_tenant_id).size.should == 1
34
+ do_search(pm.params_braintree_customer_id, kb_tenant_id).size.should == 1
35
+ do_search(pm.params_braintree_customer_credit_card_token, kb_tenant_id).size.should == 1
36
+
37
+ pm2 = Killbill::BraintreeBlue::BraintreeBlueResponse.create :api_call => 'charge',
38
+ :kb_payment_id => '11-22-33-44',
39
+ :kb_account_id => kb_account_id,
40
+ :kb_tenant_id => kb_tenant_id,
41
+ :authorization => 'AA-BB-CC-DD',
42
+ :params_braintree_customer_id => '1234567',
43
+ :params_braintree_customer_credit_card_token => pm.params_braintree_customer_credit_card_token,
44
+ :success => true
45
+
46
+ do_search('foo', kb_tenant_id).size.should == 0
47
+ do_search(pm.authorization, kb_tenant_id).size.should == 1
48
+ do_search(pm.params_braintree_customer_id, kb_tenant_id).size.should == 1
49
+ do_search(pm.params_braintree_customer_credit_card_token, kb_tenant_id).size.should == 2
50
+ do_search(pm2.authorization, kb_tenant_id).size.should == 1
51
+ do_search(pm2.params_braintree_customer_id, kb_tenant_id).size.should == 1
52
+ do_search(pm2.params_braintree_customer_credit_card_token, kb_tenant_id).size.should == 2
53
+ end
54
+
55
+ private
56
+
57
+ def do_search(search_key, kb_tenant_id)
58
+ pagination = Killbill::BraintreeBlue::BraintreeBlueResponse.search(search_key, kb_tenant_id)
59
+ pagination.current_offset.should == 0
60
+ results = pagination.iterator.to_a
61
+ pagination.total_nb_records.should == results.size
62
+ results
63
+ end
64
+ end
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+
3
+ ActiveMerchant::Billing::Base.mode = :test
4
+
5
+ describe Killbill::BraintreeBlue::PaymentPlugin do
6
+
7
+ include ::Killbill::Plugin::ActiveMerchant::RSpec
8
+
9
+ before(:each) do
10
+ @plugin = Killbill::BraintreeBlue::PaymentPlugin.new
11
+
12
+ @account_api = ::Killbill::Plugin::ActiveMerchant::RSpec::FakeJavaUserAccountApi.new
13
+ @payment_api = ::Killbill::Plugin::ActiveMerchant::RSpec::FakeJavaPaymentApi.new
14
+ svcs = {:account_user_api => @account_api, :payment_api => @payment_api}
15
+ @plugin.kb_apis = Killbill::Plugin::KillbillApi.new('braintree_blue', svcs)
16
+
17
+ @call_context = ::Killbill::Plugin::Model::CallContext.new
18
+ @call_context.tenant_id = '00000011-0022-0033-0044-000000000055'
19
+ @call_context = @call_context.to_ruby(@call_context)
20
+
21
+ @plugin.logger = Logger.new(STDOUT)
22
+ @plugin.logger.level = Logger::INFO
23
+ @plugin.conf_dir = File.expand_path(File.dirname(__FILE__) + '../../../../')
24
+ @plugin.start_plugin
25
+
26
+ @properties = []
27
+ @pm = create_payment_method(::Killbill::BraintreeBlue::BraintreeBluePaymentMethod, nil, @call_context.tenant_id, @properties)
28
+ @amount = BigDecimal.new('100')
29
+ @currency = 'USD'
30
+
31
+ kb_payment_id = SecureRandom.uuid
32
+ 1.upto(6) do
33
+ @kb_payment = @payment_api.add_payment(kb_payment_id)
34
+ end
35
+ end
36
+
37
+ after(:each) do
38
+ @plugin.stop_plugin
39
+ end
40
+
41
+ it 'should be able to charge a Credit Card directly' do
42
+ properties = build_pm_properties
43
+
44
+ # We created the payment method, hence the rows
45
+ Killbill::BraintreeBlue::BraintreeBlueResponse.all.size.should == 1
46
+ Killbill::BraintreeBlue::BraintreeBlueTransaction.all.size.should == 0
47
+
48
+ payment_response = @plugin.purchase_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
49
+ payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
50
+ payment_response.amount.should == @amount
51
+ payment_response.transaction_type.should == :PURCHASE
52
+
53
+ responses = Killbill::BraintreeBlue::BraintreeBlueResponse.all
54
+ responses.size.should == 2
55
+ responses[0].api_call.should == 'add_payment_method'
56
+ responses[0].message.should == 'Successful transaction'
57
+ responses[1].api_call.should == 'purchase'
58
+ responses[1].message.should == 'Successful transaction'
59
+ transactions = Killbill::BraintreeBlue::BraintreeBlueTransaction.all
60
+ transactions.size.should == 1
61
+ transactions[0].api_call.should == 'purchase'
62
+ end
63
+
64
+ it 'should be able to charge and refund' do
65
+ payment_response = @plugin.purchase_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context)
66
+ payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
67
+ payment_response.amount.should == @amount
68
+ payment_response.transaction_type.should == :PURCHASE
69
+
70
+ # Try a full refund
71
+ refund_response = @plugin.refund_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[1].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context)
72
+ refund_response.status.should eq(:PROCESSED), refund_response.gateway_error
73
+ refund_response.amount.should == @amount
74
+ refund_response.transaction_type.should == :REFUND
75
+ end
76
+
77
+ it 'should be able to auth, capture and refund' do
78
+ payment_response = @plugin.authorize_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context)
79
+ payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
80
+ payment_response.amount.should == @amount
81
+ payment_response.transaction_type.should == :AUTHORIZE
82
+
83
+ # Try multiple partial captures
84
+ partial_capture_amount = BigDecimal.new('10')
85
+ 1.upto(3) do |i|
86
+ payment_response = @plugin.capture_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[i].id, @pm.kb_payment_method_id, partial_capture_amount, @currency, @properties, @call_context)
87
+ payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
88
+ payment_response.amount.should == partial_capture_amount
89
+ payment_response.transaction_type.should == :CAPTURE
90
+ end
91
+
92
+ # Try a partial refund
93
+ refund_response = @plugin.refund_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[4].id, @pm.kb_payment_method_id, partial_capture_amount, @currency, @properties, @call_context)
94
+ refund_response.status.should eq(:PROCESSED), refund_response.gateway_error
95
+ refund_response.amount.should == partial_capture_amount
96
+ refund_response.transaction_type.should == :REFUND
97
+
98
+ # Try to capture again
99
+ payment_response = @plugin.capture_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[5].id, @pm.kb_payment_method_id, partial_capture_amount, @currency, @properties, @call_context)
100
+ payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
101
+ payment_response.amount.should == partial_capture_amount
102
+ payment_response.transaction_type.should == :CAPTURE
103
+ end
104
+
105
+ it 'should be able to auth and void' do
106
+ payment_response = @plugin.authorize_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context)
107
+ payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
108
+ payment_response.amount.should == @amount
109
+ payment_response.transaction_type.should == :AUTHORIZE
110
+
111
+ payment_response = @plugin.void_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[1].id, @pm.kb_payment_method_id, @properties, @call_context)
112
+ payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
113
+ payment_response.transaction_type.should == :VOID
114
+ end
115
+
116
+ it 'should be able to auth, partial capture and void' do
117
+ payment_response = @plugin.authorize_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context)
118
+ payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
119
+ payment_response.amount.should == @amount
120
+ payment_response.transaction_type.should == :AUTHORIZE
121
+
122
+ partial_capture_amount = BigDecimal.new('10')
123
+ payment_response = @plugin.capture_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[1].id, @pm.kb_payment_method_id, partial_capture_amount, @currency, @properties, @call_context)
124
+ payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
125
+ payment_response.amount.should == partial_capture_amount
126
+ payment_response.transaction_type.should == :CAPTURE
127
+
128
+ payment_response = @plugin.void_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[2].id, @pm.kb_payment_method_id, @properties, @call_context)
129
+ payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
130
+ payment_response.transaction_type.should == :VOID
131
+ end
132
+ end
@@ -0,0 +1,24 @@
1
+ require 'bundler'
2
+ require 'braintree_blue'
3
+ require 'killbill/helpers/active_merchant/killbill_spec_helper'
4
+
5
+ require 'logger'
6
+
7
+ require 'rspec'
8
+
9
+ RSpec.configure do |config|
10
+ config.color_enabled = true
11
+ config.tty = true
12
+ config.formatter = 'documentation'
13
+ end
14
+
15
+ require 'active_record'
16
+ ActiveRecord::Base.establish_connection(
17
+ :adapter => 'sqlite3',
18
+ :database => 'test.db'
19
+ )
20
+ # For debugging
21
+ #ActiveRecord::Base.logger = Logger.new(STDOUT)
22
+ # Create the schema
23
+ require File.expand_path(File.dirname(__FILE__) + '../../db/schema.rb')
24
+
metadata ADDED
@@ -0,0 +1,318 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: killbill-braintree_blue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kill Bill core team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: killbill
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.11
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 3.1.11
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemerchant
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.44.1
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 1.44.1
39
+ prerelease: false
40
+ type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ name: offsite_payments
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.1
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ~>
51
+ - !ruby/object:Gem::Version
52
+ version: 2.0.1
53
+ prerelease: false
54
+ type: :runtime
55
+ - !ruby/object:Gem::Dependency
56
+ name: activerecord
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 4.1.0
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: 4.1.0
67
+ prerelease: false
68
+ type: :runtime
69
+ - !ruby/object:Gem::Dependency
70
+ name: actionpack
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 4.1.0
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ version: 4.1.0
81
+ prerelease: false
82
+ type: :runtime
83
+ - !ruby/object:Gem::Dependency
84
+ name: actionview
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 4.1.0
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: 4.1.0
95
+ prerelease: false
96
+ type: :runtime
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 4.1.0
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ version: 4.1.0
109
+ prerelease: false
110
+ type: :runtime
111
+ - !ruby/object:Gem::Dependency
112
+ name: money
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 6.1.1
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ~>
121
+ - !ruby/object:Gem::Version
122
+ version: 6.1.1
123
+ prerelease: false
124
+ type: :runtime
125
+ - !ruby/object:Gem::Dependency
126
+ name: monetize
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 0.3.0
132
+ requirement: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ~>
135
+ - !ruby/object:Gem::Version
136
+ version: 0.3.0
137
+ prerelease: false
138
+ type: :runtime
139
+ - !ruby/object:Gem::Dependency
140
+ name: sinatra
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: 1.3.4
146
+ requirement: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ~>
149
+ - !ruby/object:Gem::Version
150
+ version: 1.3.4
151
+ prerelease: false
152
+ type: :runtime
153
+ - !ruby/object:Gem::Dependency
154
+ name: activerecord-jdbcmysql-adapter
155
+ version_requirements: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ~>
158
+ - !ruby/object:Gem::Version
159
+ version: 1.3.7
160
+ requirement: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ~>
163
+ - !ruby/object:Gem::Version
164
+ version: 1.3.7
165
+ prerelease: false
166
+ type: :runtime
167
+ - !ruby/object:Gem::Dependency
168
+ name: jruby-openssl
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: 0.9.4
174
+ requirement: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ~>
177
+ - !ruby/object:Gem::Version
178
+ version: 0.9.4
179
+ prerelease: false
180
+ type: :runtime
181
+ - !ruby/object:Gem::Dependency
182
+ name: jbundler
183
+ version_requirements: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ~>
186
+ - !ruby/object:Gem::Version
187
+ version: 0.4.1
188
+ requirement: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ~>
191
+ - !ruby/object:Gem::Version
192
+ version: 0.4.1
193
+ prerelease: false
194
+ type: :development
195
+ - !ruby/object:Gem::Dependency
196
+ name: rake
197
+ version_requirements: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '>='
200
+ - !ruby/object:Gem::Version
201
+ version: 10.0.0
202
+ requirement: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - '>='
205
+ - !ruby/object:Gem::Version
206
+ version: 10.0.0
207
+ prerelease: false
208
+ type: :development
209
+ - !ruby/object:Gem::Dependency
210
+ name: rspec
211
+ version_requirements: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ~>
214
+ - !ruby/object:Gem::Version
215
+ version: 2.12.0
216
+ requirement: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ~>
219
+ - !ruby/object:Gem::Version
220
+ version: 2.12.0
221
+ prerelease: false
222
+ type: :development
223
+ - !ruby/object:Gem::Dependency
224
+ name: activerecord-jdbcsqlite3-adapter
225
+ version_requirements: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ~>
228
+ - !ruby/object:Gem::Version
229
+ version: 1.3.7
230
+ requirement: !ruby/object:Gem::Requirement
231
+ requirements:
232
+ - - ~>
233
+ - !ruby/object:Gem::Version
234
+ version: 1.3.7
235
+ prerelease: false
236
+ type: :development
237
+ - !ruby/object:Gem::Dependency
238
+ name: braintree
239
+ version_requirements: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ~>
242
+ - !ruby/object:Gem::Version
243
+ version: '2.0'
244
+ requirement: !ruby/object:Gem::Requirement
245
+ requirements:
246
+ - - ~>
247
+ - !ruby/object:Gem::Version
248
+ version: '2.0'
249
+ prerelease: false
250
+ type: :runtime
251
+ description: Kill Bill payment plugin for BraintreeBlue.
252
+ email: killbilling-users@googlegroups.com
253
+ executables: []
254
+ extensions: []
255
+ extra_rdoc_files: []
256
+ files:
257
+ - .gitignore
258
+ - .travis.yml
259
+ - Gemfile
260
+ - Jarfile
261
+ - LICENSE
262
+ - NEWS
263
+ - README.md
264
+ - Rakefile
265
+ - VERSION
266
+ - braintree_blue.yml
267
+ - config.ru
268
+ - db/ddl.sql
269
+ - db/schema.rb
270
+ - killbill-braintree_blue.gemspec
271
+ - killbill.properties
272
+ - lib/braintree_blue.rb
273
+ - lib/braintree_blue/api.rb
274
+ - lib/braintree_blue/application.rb
275
+ - lib/braintree_blue/models/payment_method.rb
276
+ - lib/braintree_blue/models/response.rb
277
+ - lib/braintree_blue/models/transaction.rb
278
+ - lib/braintree_blue/private_api.rb
279
+ - lib/braintree_blue/views/form.erb
280
+ - pom.xml
281
+ - release.sh
282
+ - spec/braintree_blue/base_plugin_spec.rb
283
+ - spec/braintree_blue/braintree_blue_payment_method_spec.rb
284
+ - spec/braintree_blue/braintree_blue_response_spec.rb
285
+ - spec/braintree_blue/remote/integration_spec.rb
286
+ - spec/spec_helper.rb
287
+ homepage: http://kill-bill.org
288
+ licenses:
289
+ - Apache License (2.0)
290
+ metadata: {}
291
+ post_install_message:
292
+ rdoc_options:
293
+ - --exclude
294
+ - .
295
+ require_paths:
296
+ - lib
297
+ required_ruby_version: !ruby/object:Gem::Requirement
298
+ requirements:
299
+ - - '>='
300
+ - !ruby/object:Gem::Version
301
+ version: 1.9.3
302
+ required_rubygems_version: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - '>='
305
+ - !ruby/object:Gem::Version
306
+ version: '0'
307
+ requirements: []
308
+ rubyforge_project:
309
+ rubygems_version: 2.2.2
310
+ signing_key:
311
+ specification_version: 4
312
+ summary: Plugin to use BraintreeBlue as a gateway.
313
+ test_files:
314
+ - spec/braintree_blue/base_plugin_spec.rb
315
+ - spec/braintree_blue/braintree_blue_payment_method_spec.rb
316
+ - spec/braintree_blue/braintree_blue_response_spec.rb
317
+ - spec/braintree_blue/remote/integration_spec.rb
318
+ - spec/spec_helper.rb