killbill-paypal-express 5.0.4 → 5.0.5

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.
@@ -1,365 +0,0 @@
1
- require 'spec_helper'
2
- require_relative 'browser_helpers'
3
-
4
- module Killbill
5
- module PaypalExpress
6
- module HppSpecHelpers
7
-
8
- include ::Killbill::PaypalExpress::BrowserHelpers
9
-
10
- def hpp_setup
11
- @call_context = build_call_context
12
- @amount = BigDecimal.new('100')
13
- @currency = 'USD'
14
- @form_fields = @plugin.hash_to_properties(
15
- :order_id => '1234',
16
- :amount => @amount,
17
- :currency => @currency
18
- )
19
- kb_account_id = SecureRandom.uuid
20
- create_kb_account(kb_account_id, @plugin.kb_apis.proxied_services[:account_user_api])
21
- @pm = create_payment_method(::Killbill::PaypalExpress::PaypalExpressPaymentMethod, kb_account_id, @call_context.tenant_id)
22
- verify_payment_method kb_account_id
23
- end
24
-
25
- def validate_form(form)
26
- form.kb_account_id.should == @pm.kb_account_id
27
- form.form_url.should start_with('https://www.sandbox.paypal.com/cgi-bin/webscr')
28
- form.form_method.should == 'GET'
29
- end
30
-
31
- def validate_nil_form_property(form, key)
32
- key_properties = form.properties.select { |prop| prop.key == key }
33
- key_properties.size.should == 0
34
- end
35
-
36
- def validate_form_property(form, key, value=nil)
37
- key_properties = form.properties.select { |prop| prop.key == key }
38
- key_properties.size.should == 1
39
- key = key_properties.first.value
40
- value.nil? ? key.should_not(be_nil) : key.should == value
41
- key
42
- end
43
-
44
- def validate_token(form)
45
- login_and_confirm form.form_url
46
- end
47
-
48
- def purchase_and_refund(kb_payment_id, purchase_payment_external_key, purchase_properties)
49
- # Trigger the purchase
50
- payment_response = @plugin.purchase_payment(@pm.kb_account_id, kb_payment_id, purchase_payment_external_key, @pm.kb_payment_method_id, @amount, @currency, purchase_properties, @call_context)
51
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
52
- payment_response.amount.should == @amount
53
- payment_response.transaction_type.should == :PURCHASE
54
- payer_id = find_value_from_properties(payment_response.properties, 'payerId')
55
- payer_id.should_not be_nil
56
-
57
- validate_details_for(kb_payment_id, :PURCHASE, payer_id)
58
- # Verify GET API
59
- payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, [], @call_context)
60
- payment_infos.size.should == 1
61
- # purchase
62
- payment_infos[0].kb_payment_id.should == kb_payment_id
63
- payment_infos[0].transaction_type.should == :PURCHASE
64
- payment_infos[0].amount.should == @amount
65
- payment_infos[0].currency.should == @currency
66
- payment_infos[0].status.should == :PROCESSED
67
- payment_infos[0].gateway_error.should == 'Success'
68
- payment_infos[0].gateway_error_code.should be_nil
69
- find_value_from_properties(payment_infos[0].properties, 'payerId').should == payer_id
70
-
71
- # Try a full refund
72
- refund_response = @plugin.refund_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, [], @call_context)
73
- refund_response.status.should eq(:PROCESSED), refund_response.gateway_error
74
- refund_response.amount.should == @amount
75
- refund_response.transaction_type.should == :REFUND
76
-
77
- # Verify GET API
78
- payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, [], @call_context)
79
- payment_infos.size.should == 2
80
- # refund
81
- payment_infos[1].kb_payment_id.should.should == kb_payment_id
82
- payment_infos[1].transaction_type.should == :REFUND
83
- payment_infos[1].amount.should == @amount
84
- payment_infos[1].currency.should == @currency
85
- payment_infos[1].status.should == :PROCESSED
86
- payment_infos[1].gateway_error.should == 'Success'
87
- payment_infos[1].gateway_error_code.should be_nil
88
- end
89
-
90
- def authorize_capture_and_refund(kb_payment_id, payment_external_key, properties, payment_processor_account_id)
91
- # Trigger the authorize
92
- payment_response = @plugin.authorize_payment(@pm.kb_account_id, kb_payment_id, payment_external_key, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
93
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
94
- payment_response.amount.should == @amount
95
- payment_response.transaction_type.should == :AUTHORIZE
96
- payer_id = find_value_from_properties(payment_response.properties, 'payerId')
97
- payer_id.should_not be_nil
98
-
99
- validate_details_for(kb_payment_id, :AUTHORIZE, payer_id)
100
- # Verify GET AUTHORIZED PAYMENT
101
- payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, properties, @call_context)
102
- payment_infos.size.should == 1
103
- # authorize
104
- payment_infos[0].kb_payment_id.should == kb_payment_id
105
- payment_infos[0].transaction_type.should == :AUTHORIZE
106
- payment_infos[0].amount.should == @amount
107
- payment_infos[0].currency.should == @currency
108
- payment_infos[0].status.should == :PROCESSED
109
- payment_infos[0].gateway_error.should == 'Success'
110
- payment_infos[0].gateway_error_code.should be_nil
111
- find_value_from_properties(payment_infos[0].properties, 'payerId').should == payer_id
112
- find_value_from_properties(payment_infos[0].properties, 'paymentInfoPaymentStatus').should == 'Pending'
113
- find_value_from_properties(payment_infos[0].properties, 'paymentInfoPendingReason').should == 'authorization'
114
- find_value_from_properties(payment_infos[0].properties, 'payment_processor_account_id').should == payment_processor_account_id
115
-
116
- # Trigger the capture
117
- payment_response = @plugin.capture_payment(@pm.kb_account_id, kb_payment_id, payment_external_key, @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 == :CAPTURE
121
-
122
- # Verify GET CAPTURED PAYMENT
123
- payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, properties, @call_context)
124
- # Two expected transactions: one auth and one capture
125
- payment_infos.size.should == 2
126
- # capture
127
- payment_infos[1].kb_payment_id.should == kb_payment_id
128
- payment_infos[1].transaction_type.should == :CAPTURE
129
- payment_infos[1].amount.should == @amount
130
- payment_infos[1].currency.should == @currency
131
- payment_infos[1].status.should == :PROCESSED
132
- payment_infos[1].gateway_error.should == 'Success'
133
- payment_infos[1].gateway_error_code.should be_nil
134
- find_value_from_properties(payment_infos[1].properties, 'paymentInfoPaymentStatus').should == 'Completed'
135
- find_value_from_properties(payment_infos[1].properties, 'payment_processor_account_id').should == payment_processor_account_id
136
-
137
- # Try a full refund
138
- refund_response = @plugin.refund_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, [], @call_context)
139
- refund_response.status.should eq(:PROCESSED), refund_response.gateway_error
140
- refund_response.amount.should == @amount
141
- refund_response.transaction_type.should == :REFUND
142
-
143
- # Verify GET API
144
- payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, properties, @call_context)
145
- payment_infos.size.should == 3
146
- # refund
147
- payment_infos[2].kb_payment_id.should.should == kb_payment_id
148
- payment_infos[2].transaction_type.should == :REFUND
149
- payment_infos[2].amount.should == @amount
150
- payment_infos[2].currency.should == @currency
151
- payment_infos[2].status.should == :PROCESSED
152
- payment_infos[2].gateway_error.should == 'Success'
153
- payment_infos[2].gateway_error_code.should be_nil
154
- find_value_from_properties(payment_infos[2].properties, 'payment_processor_account_id').should == payment_processor_account_id
155
- end
156
-
157
- def authorize_and_double_capture(kb_payment_id, payment_external_key, properties)
158
- # Trigger the authorize
159
- payment_response = @plugin.authorize_payment(@pm.kb_account_id, kb_payment_id, payment_external_key, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
160
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
161
- payment_response.amount.should == @amount
162
- payment_response.transaction_type.should == :AUTHORIZE
163
- payer_id = find_value_from_properties(payment_response.properties, 'payerId')
164
- payer_id.should_not be_nil
165
-
166
- validate_details_for(kb_payment_id, :AUTHORIZE, payer_id)
167
- payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, properties, @call_context)
168
- payment_infos.size.should == 1
169
- # autorize
170
- payment_infos[0].kb_payment_id.should == kb_payment_id
171
- payment_infos[0].transaction_type.should == :AUTHORIZE
172
- payment_infos[0].amount.should == @amount
173
- payment_infos[0].currency.should == @currency
174
- payment_infos[0].status.should == :PROCESSED
175
- payment_infos[0].gateway_error.should == 'Success'
176
- payment_infos[0].gateway_error_code.should be_nil
177
-
178
- # Trigger the capture
179
- payment_response = @plugin.capture_payment(@pm.kb_account_id, kb_payment_id, payment_external_key, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
180
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
181
- payment_response.amount.should == @amount
182
- payment_response.transaction_type.should == :CAPTURE
183
-
184
- payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, properties, @call_context)
185
- payment_infos.size.should == 2
186
- # capture
187
- payment_infos[1].kb_payment_id.should == kb_payment_id
188
- payment_infos[1].transaction_type.should == :CAPTURE
189
- payment_infos[1].amount.should == @amount
190
- payment_infos[1].currency.should == @currency
191
- payment_infos[1].status.should == :PROCESSED
192
- payment_infos[1].gateway_error.should == 'Success'
193
- payment_infos[1].gateway_error_code.should be_nil
194
-
195
- # Trigger a capture again with full amount
196
- payment_response = @plugin.capture_payment(@pm.kb_account_id, kb_payment_id, payment_external_key, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
197
- payment_response.status.should eq(:ERROR), payment_response.gateway_error
198
- payment_response.amount.should == nil
199
- payment_response.transaction_type.should == :CAPTURE
200
-
201
- payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, properties, @call_context)
202
- payment_infos.size.should == 3
203
- # capture again
204
- payment_infos[2].kb_payment_id.should.should == kb_payment_id
205
- payment_infos[2].transaction_type.should == :CAPTURE
206
- payment_infos[2].amount.should be_nil
207
- payment_infos[2].currency.should be_nil
208
- payment_infos[2].status.should == :ERROR
209
- payment_infos[2].gateway_error.should == 'Authorization has already been completed.'
210
- payment_infos[2].gateway_error_code.should == "10602"
211
- end
212
-
213
- def authorize_and_void(kb_payment_id, payment_external_key, properties, payment_processor_account_id)
214
- # Trigger the authorize
215
- payment_response = @plugin.authorize_payment(@pm.kb_account_id, kb_payment_id, payment_external_key, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
216
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
217
- payment_response.amount.should == @amount
218
- payment_response.transaction_type.should == :AUTHORIZE
219
- payer_id = find_value_from_properties(payment_response.properties, 'payerId')
220
- payer_id.should_not be_nil
221
-
222
- validate_details_for(kb_payment_id, :AUTHORIZE, payer_id)
223
- # Verify get_payment_info
224
- payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, properties, @call_context)
225
- payment_infos.size.should == 1
226
- # authorize
227
- payment_infos[0].kb_payment_id.should == kb_payment_id
228
- payment_infos[0].transaction_type.should == :AUTHORIZE
229
- payment_infos[0].amount.should == @amount
230
- payment_infos[0].currency.should == @currency
231
- payment_infos[0].status.should == :PROCESSED
232
- payment_infos[0].gateway_error.should == 'Success'
233
- payment_infos[0].gateway_error_code.should be_nil
234
- find_value_from_properties(payment_infos[0].properties, 'payment_processor_account_id').should == payment_processor_account_id
235
-
236
- # Trigger the void
237
- payment_response = @plugin.void_payment(@pm.kb_account_id, kb_payment_id, payment_external_key, @pm.kb_payment_method_id, properties, @call_context)
238
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
239
- payment_response.transaction_type.should == :VOID
240
-
241
- # Verify get_payment_info
242
- payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, properties, @call_context)
243
- # Two expected transactions: one auth and one capture, plus the details call
244
- payment_infos.size.should == 2
245
- # void
246
- payment_infos[1].kb_payment_id.should == kb_payment_id
247
- payment_infos[1].transaction_type.should == :VOID
248
- payment_infos[1].status.should == :PROCESSED
249
- payment_infos[1].gateway_error.should == 'Success'
250
- payment_infos[1].gateway_error_code.should be_nil
251
- find_value_from_properties(payment_infos[1].properties, 'payment_processor_account_id').should == payment_processor_account_id
252
- end
253
-
254
- def purchase_with_missing_token
255
- failed_purchase([], :CANCELED, 'Could not retrieve the payer info: the token is missing', 'RuntimeError')
256
- end
257
-
258
- def authorize_with_missing_token
259
- failed_authorize([], :CANCELED, 'Could not retrieve the payer info: the token is missing', 'RuntimeError')
260
- end
261
-
262
- def purchase_with_invalid_token(purchase_properties)
263
- failed_purchase(purchase_properties, :CANCELED, "Could not retrieve the payer info for token #{properties_to_hash(purchase_properties)[:token]}", 'RuntimeError')
264
- end
265
-
266
- def authorize_with_invalid_token(authorize_properties)
267
- failed_authorize(authorize_properties, :CANCELED, "Could not retrieve the payer info for token #{properties_to_hash(authorize_properties)[:token]}", 'RuntimeError')
268
- end
269
-
270
- def subsequent_purchase(purchase_properties)
271
- failed_purchase(purchase_properties, :ERROR, 'A successful transaction has already been completed for this token.', '11607')
272
- end
273
-
274
- def failed_authorize(authorize_properties, status, msg, gateway_error_code=nil)
275
- kb_payment_id = SecureRandom.uuid
276
-
277
- payment_response = @plugin.authorize_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, authorize_properties, @call_context)
278
- payment_response.status.should eq(status), payment_response.gateway_error
279
- payment_response.amount.should be_nil
280
- payment_response.transaction_type.should == :AUTHORIZE
281
-
282
- # Verify GET API
283
- payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, [], @call_context)
284
- payment_infos.size.should == 1
285
- payment_infos[0].kb_payment_id.should == kb_payment_id
286
- payment_infos[0].transaction_type.should == :AUTHORIZE
287
- payment_infos[0].amount.should be_nil
288
- payment_infos[0].currency.should be_nil
289
- payment_infos[0].status.should == status
290
- payment_infos[0].gateway_error.should == msg
291
- payment_infos[0].gateway_error_code.should == gateway_error_code
292
- end
293
-
294
- def failed_purchase(purchase_properties, status, msg, gateway_error_code=nil)
295
- kb_payment_id = SecureRandom.uuid
296
-
297
- payment_response = @plugin.purchase_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, purchase_properties, @call_context)
298
- payment_response.status.should eq(status), payment_response.gateway_error
299
- payment_response.amount.should be_nil
300
- payment_response.transaction_type.should == :PURCHASE
301
-
302
- # Verify GET API
303
- payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, [], @call_context)
304
- token = find_value_from_properties(purchase_properties, 'token')
305
- payment_infos.size.should == 1
306
- payment_infos[0].kb_payment_id.should == kb_payment_id
307
- payment_infos[0].transaction_type.should == :PURCHASE
308
- payment_infos[0].amount.should be_nil
309
- payment_infos[0].currency.should be_nil
310
- payment_infos[0].status.should == status
311
- payment_infos[0].gateway_error.should == msg
312
- payment_infos[0].gateway_error_code.should == gateway_error_code
313
- end
314
-
315
- def transition_last_response_to_UNDEFINED(expected_nb_transactions, kb_payment_id, delete_last_trx = true)
316
- Killbill::PaypalExpress::PaypalExpressTransaction.last.delete if delete_last_trx
317
- response = Killbill::PaypalExpress::PaypalExpressResponse.last
318
- initial_auth = response.authorization
319
- response.update(:authorization => nil, :message => {:payment_plugin_status => 'UNDEFINED'}.to_json)
320
-
321
- skip_gw = Killbill::Plugin::Model::PluginProperty.new
322
- skip_gw.key = 'skip_gw'
323
- skip_gw.value = 'true'
324
- properties_with_skip_gw = [skip_gw]
325
-
326
- # Set skip_gw=true, to avoid calling the report API
327
- transaction_info_plugins = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, properties_with_skip_gw, @call_context)
328
- transaction_info_plugins.size.should == expected_nb_transactions
329
- transaction_info_plugins.last.status.should eq(:UNDEFINED)
330
-
331
- [response, initial_auth]
332
- end
333
-
334
- def verify_janitor_transition(nb_trx_plugin_info, trx_type, trx_status, kb_payment_id, delete_last_trx = true, hard_expiration_date = 0, janitor_delay = 0)
335
- transition_last_response_to_UNDEFINED(nb_trx_plugin_info, kb_payment_id, delete_last_trx)
336
- # wait 5 sec for PayPal to populate the record in search endpoint
337
- sleep 5
338
- janitor_delay_threshold = Killbill::Plugin::Model::PluginProperty.new
339
- janitor_delay_threshold.key = 'janitor_delay_threshold'
340
- janitor_delay_threshold.value = janitor_delay
341
- cancel_threshold = Killbill::Plugin::Model::PluginProperty.new
342
- cancel_threshold.key = 'cancel_threshold'
343
- cancel_threshold.value = hard_expiration_date
344
- transaction_info_plugins = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, [janitor_delay_threshold, cancel_threshold], @call_context)
345
- transaction_info_plugins.size.should == nb_trx_plugin_info
346
- transaction_info_plugins.last.status.should eq(trx_status)
347
- transaction_info_plugins.last.transaction_type.should eq(trx_type)
348
- end
349
-
350
- private
351
-
352
- def verify_payment_method(kb_account_id = nil)
353
- # Verify our table directly
354
- kb_account_id = @pm.kb_account_id if kb_account_id.nil?
355
- payment_methods = ::Killbill::PaypalExpress::PaypalExpressPaymentMethod.from_kb_account_id(kb_account_id, @call_context.tenant_id)
356
- payment_methods.size.should == 1
357
- payment_method = payment_methods.first
358
- payment_method.should_not be_nil
359
- payment_method.paypal_express_payer_id.should be_nil
360
- payment_method.token.should be_nil
361
- payment_method.kb_payment_method_id.should == @pm.kb_payment_method_id
362
- end
363
- end
364
- end
365
- end
@@ -1,79 +0,0 @@
1
- require 'spec_helper'
2
- require 'nokogiri'
3
-
4
- describe Killbill::PaypalExpress::PaypalExpressResponse do
5
-
6
- def load_paypal_response(action, suffix)
7
- @spec_root ||= File.expand_path(File.join(File.dirname(__FILE__), ".."))
8
- xml = IO.read(File.join(@spec_root, "fixtures", action + "-" + suffix + ".xml"))
9
- ActiveMerchant::Billing::PaypalGateway.any_instance.stub(:build_request).and_return(nil)
10
- ActiveMerchant::Billing::PaypalGateway.any_instance.stub(:ssl_post).and_return(xml)
11
- api = ActiveMerchant::Billing::PaypalGateway.new(:login => "dummy", :password => "password", :signature => "dummy")
12
- api.send(:commit, action, nil)
13
- end
14
-
15
- it 'should read a successful GetExpressCheckoutDetails response correctly' do
16
- action = "GetExpressCheckoutDetails"
17
- response = ::Killbill::PaypalExpress::PaypalExpressResponse.from_response(
18
- action, # api_call
19
- "account1", # kb_account_id
20
- "payment1", # kb_payment_id
21
- nil, # kb_payment_transaction_id
22
- nil, # transaction_type
23
- "account2", # payment_processor_account_id
24
- "tenant1", # kb_tenant_id
25
- load_paypal_response(action, "success")
26
- )
27
- expect(response.api_call).to eq(action)
28
- expect(response.kb_account_id).to eq("account1")
29
- expect(response.kb_payment_id).to eq("payment1")
30
- expect(response.kb_payment_transaction_id).to be_nil
31
- expect(response.transaction_type).to be_nil
32
- expect(response.payment_processor_account_id).to eq("account2")
33
- expect(response.kb_tenant_id).to eq("tenant1")
34
- # data from the fixture as parsed by PaypalCommonAPI and PaypalExpressResponse
35
- expect(response.message).to eq("Success")
36
- expect(response.authorization).to be_nil
37
- expect(response.fraud_review).to eq(false)
38
- expect(response.success).to eq(true)
39
-
40
- expect(response.token).to eq("EC-MY_TOKEN")
41
- expect(response.payer_id).to eq("MY_PAYER_ID")
42
- expect(response.payment_info_reasoncode).to be_nil
43
-
44
- expect(response.gateway_error_code).to be_nil
45
- end
46
-
47
- it 'should read a DoExpressCheckoutPayment response with an error code correctly' do
48
- action = "DoExpressCheckoutPayment"
49
- response = ::Killbill::PaypalExpress::PaypalExpressResponse.from_response(
50
- action, # api_call
51
- "account1", # kb_account_id
52
- "payment1", # kb_payment_id
53
- "transaction1", # kb_payment_transaction_id
54
- :purchase, # transaction_type
55
- "account2", # payment_processor_account_id
56
- "tenant1", # kb_tenant_id
57
- load_paypal_response(action, "duplicate")
58
- )
59
- expect(response.api_call).to eq(action)
60
- expect(response.kb_account_id).to eq("account1")
61
- expect(response.kb_payment_id).to eq("payment1")
62
- expect(response.kb_payment_transaction_id).to eq("transaction1")
63
- expect(response.transaction_type).to eq(:purchase)
64
- expect(response.payment_processor_account_id).to eq("account2")
65
- expect(response.kb_tenant_id).to eq("tenant1")
66
- # data from the fixture as parsed by PaypalCommonAPI and PaypalExpressResponse
67
- expect(response.message).to eq("A successful transaction has already been completed for this token.")
68
- expect(response.authorization).to eq("3K289148GS508731G")
69
- expect(response.fraud_review).to eq(false)
70
- expect(response.success).to eq(false)
71
-
72
- expect(response.token).to eq("EC-MY_TOKEN")
73
- expect(response.payer_id).to be_nil
74
- expect(response.payment_info_reasoncode).to eq("11607")
75
-
76
- expect(response.gateway_error_code).to eq("11607")
77
- end
78
-
79
- end
@@ -1,67 +0,0 @@
1
- require 'bundler'
2
- require 'paypal_express'
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
-
25
-
26
- def validate_details_for(kb_payment_id, transaction_type, payer_id)
27
- details_for = ::Killbill::PaypalExpress::PaypalExpressResponse.where(:kb_payment_id => kb_payment_id).where(:api_call => :details_for).last
28
- details_for.message.should == "Success"
29
- details_for.transaction_type.to_sym.should == transaction_type.to_sym
30
- details_for.payer_id.should == payer_id
31
- details_for.payer_name.should_not be_nil
32
- end
33
-
34
-
35
- class PaypalExpressJavaPaymentApi < ::Killbill::Plugin::ActiveMerchant::RSpec::FakeJavaPaymentApi
36
-
37
- def initialize(plugin)
38
- super()
39
- @plugin = plugin
40
- end
41
-
42
- def get_account_payment_methods(kb_account_id, plugin_info, properties, context)
43
- [OpenStruct.new(:plugin_name => 'killbill-paypal-express', :id => SecureRandom.uuid)]
44
- end
45
-
46
- def create_purchase(kb_account, kb_payment_method_id, kb_payment_id, amount, currency, payment_external_key, payment_transaction_external_key, properties, context)
47
- kb_payment = add_payment(kb_payment_id || SecureRandom.uuid, SecureRandom.uuid, payment_transaction_external_key, :PURCHASE)
48
-
49
- rcontext = context.to_ruby(context)
50
- @plugin.purchase_payment(kb_account.id, kb_payment.id, kb_payment.transactions.last.id, kb_payment_method_id, amount, currency, properties, rcontext)
51
-
52
- kb_payment
53
- end
54
-
55
- def create_authorization(kb_account, kb_payment_method_id, kb_payment_id, amount, currency, payment_external_key, payment_transaction_external_key, properties, context)
56
- kb_payment = add_payment(kb_payment_id || SecureRandom.uuid, SecureRandom.uuid, payment_transaction_external_key, :AUTHORIZE)
57
-
58
- rcontext = context.to_ruby(context)
59
- @plugin.authorize_payment(kb_account.id, kb_payment.id, kb_payment.transactions.last.id, kb_payment_method_id, amount, currency, properties, rcontext)
60
-
61
- kb_payment
62
- end
63
-
64
- def delete_all_payments
65
- @payments = []
66
- end
67
- end