killbill-paypal-express 5.0.17 → 6.0.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/lib/paypal_express/api.rb +47 -172
- data/lib/paypal_express/models/response.rb +1 -0
- data/lib/paypal_express/private_api.rb +2 -2
- metadata +26 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef211332b6640d41c9bbd87f64705c56ecec9b10
|
4
|
+
data.tar.gz: 7d7830ee4c7612520817e43fa36dea798fc0ebbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61050da6f063c77bc5f6f092336349ab0fad7a4798d976ed560b8171008409818be031edca47edecc1f73f5d90cae74d13611f96050cea9e8a260418cd2509dd
|
7
|
+
data.tar.gz: 30b3d2eddc0043a449d3edb547bded37078279f31aedc46ffe17858ef395c26bac65dcde8325a9fd0ea00013d058c5895622990809b78fd94988deae9768a89d
|
data/lib/paypal_express/api.rb
CHANGED
@@ -195,6 +195,7 @@ module Killbill #:nodoc:
|
|
195
195
|
|
196
196
|
kb_account = ::Killbill::Plugin::ActiveMerchant::Utils::LazyEvaluator.new { @kb_apis.account_user_api.get_account_by_id(kb_account_id, jcontext) }
|
197
197
|
amount = (options[:amount] || '0').to_f
|
198
|
+
effective_date = options[:effective_date] || Time.now.utc
|
198
199
|
currency = options[:currency] || kb_account.currency
|
199
200
|
|
200
201
|
response = initiate_express_checkout(kb_account_id, amount, currency, all_properties, context)
|
@@ -216,7 +217,7 @@ module Killbill #:nodoc:
|
|
216
217
|
payment_external_key = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(options, :payment_external_key)
|
217
218
|
transaction_external_key = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(options, :transaction_external_key)
|
218
219
|
|
219
|
-
kb_payment_method = (@kb_apis.payment_api.get_account_payment_methods(kb_account_id, false, [], jcontext).find { |pm| pm.plugin_name == 'killbill-paypal-express' })
|
220
|
+
kb_payment_method = (@kb_apis.payment_api.get_account_payment_methods(kb_account_id, false, false, [], jcontext).find { |pm| pm.plugin_name == 'killbill-paypal-express' })
|
220
221
|
|
221
222
|
auth_mode = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(options, :auth_mode)
|
222
223
|
# By default, the SALE mode is used.
|
@@ -227,6 +228,7 @@ module Killbill #:nodoc:
|
|
227
228
|
nil,
|
228
229
|
amount,
|
229
230
|
currency,
|
231
|
+
effective_date,
|
230
232
|
payment_external_key,
|
231
233
|
transaction_external_key,
|
232
234
|
custom_props,
|
@@ -238,6 +240,7 @@ module Killbill #:nodoc:
|
|
238
240
|
nil,
|
239
241
|
amount,
|
240
242
|
currency,
|
243
|
+
effective_date,
|
241
244
|
payment_external_key,
|
242
245
|
transaction_external_key,
|
243
246
|
custom_props,
|
@@ -301,59 +304,28 @@ module Killbill #:nodoc:
|
|
301
304
|
response
|
302
305
|
end
|
303
306
|
|
304
|
-
def
|
305
|
-
kb_account_id,
|
306
|
-
kb_tenant_id,
|
307
|
-
payment_processor_account_id,
|
308
|
-
kb_payment_id = nil,
|
309
|
-
kb_payment_transaction_id = nil,
|
310
|
-
transaction_type = nil)
|
311
|
-
raise 'Could create billing aggrement: the token is missing' if token.blank?
|
312
|
-
|
313
|
-
# Go to Paypal to create the billing aggrement
|
314
|
-
payment_processor_account_id = payment_processor_account_id || :default
|
315
|
-
gateway = lookup_gateway(payment_processor_account_id, kb_tenant_id)
|
316
|
-
gw_response = gateway.store(token)
|
317
|
-
|
318
|
-
response = @response_model.create_response(:store, kb_account_id, kb_payment_id, kb_payment_transaction_id, transaction_type, payment_processor_account_id, kb_tenant_id, gw_response)
|
319
|
-
|
320
|
-
raise response.message unless response.success?
|
321
|
-
raise "Could not create billing aggrement for token #{token}" if response.billing_agreement_id.blank?
|
322
|
-
|
323
|
-
response
|
324
|
-
end
|
325
|
-
|
326
|
-
def add_default_options(kb_payment_transaction_id, options)
|
327
|
-
options[:payment_type] ||= 'Any'
|
328
|
-
options[:invoice_id] ||= kb_payment_transaction_id
|
329
|
-
options[:ip] ||= @ip
|
330
|
-
end
|
331
|
-
|
332
|
-
def add_payment_method_options(kb_account_id, kb_payment_method_id, context, options, properties_hash)
|
333
|
-
options[:token] = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :token) || find_last_token(kb_account_id, context.tenant_id)
|
334
|
-
options[:reference_id] = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :baid)
|
335
|
-
|
307
|
+
def add_required_options(kb_payment_transaction_id, kb_payment_method_id, context, options)
|
336
308
|
payment_method = @payment_method_model.from_kb_payment_method_id(kb_payment_method_id, context.tenant_id)
|
337
309
|
|
338
310
|
options[:payer_id] ||= payment_method.paypal_express_payer_id.presence
|
339
311
|
options[:token] ||= payment_method.paypal_express_token.presence
|
340
312
|
options[:reference_id] ||= payment_method.token.presence # baid
|
313
|
+
|
314
|
+
options[:payment_type] ||= 'Any'
|
315
|
+
options[:invoice_id] ||= kb_payment_transaction_id
|
316
|
+
options[:ip] ||= @ip
|
341
317
|
end
|
342
318
|
|
343
319
|
def initiate_express_checkout(kb_account_id, amount, currency, properties, context)
|
344
320
|
properties_hash = properties_to_hash(properties)
|
345
321
|
|
322
|
+
with_baid = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :with_baid)
|
323
|
+
|
346
324
|
options = {}
|
347
325
|
options[:return_url] = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :return_url)
|
348
326
|
options[:cancel_return_url] = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :cancel_return_url)
|
349
327
|
options[:payment_processor_account_id] = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :payment_processor_account_id)
|
350
328
|
|
351
|
-
with_baid = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :with_baid)
|
352
|
-
if with_baid
|
353
|
-
options[:payment_processor_account_id] = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :payment_master_processor_account_id)
|
354
|
-
[:billing_agreement_type, :billing_agreement_description].each { |sym| options[sym] = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, sym) }
|
355
|
-
end
|
356
|
-
|
357
329
|
add_optional_parameters options, properties_hash, currency
|
358
330
|
|
359
331
|
amount_in_cents = amount.nil? ? nil : to_cents(amount, currency)
|
@@ -372,15 +344,7 @@ module Killbill #:nodoc:
|
|
372
344
|
|
373
345
|
def authorize_or_purchase_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context, is_authorize = false)
|
374
346
|
properties_hash = properties_to_hash properties
|
375
|
-
with_baid = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :with_baid)
|
376
|
-
logger.info("withBaidFlag=#{with_baid}")
|
377
|
-
|
378
347
|
payment_processor_account_id = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :payment_processor_account_id)
|
379
|
-
logger.info("paymentProcessorAccountId=#{payment_processor_account_id}")
|
380
|
-
|
381
|
-
payment_master_processor_account_id = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :payment_master_processor_account_id)
|
382
|
-
logger.info("paymentMasterProcessorAccountId=#{payment_master_processor_account_id}")
|
383
|
-
|
384
348
|
transaction_type = is_authorize ? :AUTHORIZE : :PURCHASE
|
385
349
|
api_call_type = is_authorize ? :authorize : :purchase
|
386
350
|
|
@@ -407,79 +371,14 @@ module Killbill #:nodoc:
|
|
407
371
|
transaction
|
408
372
|
else
|
409
373
|
options = {}
|
410
|
-
|
411
|
-
add_payment_method_options(kb_account_id, kb_payment_method_id, context, options, properties_hash)
|
374
|
+
add_required_options(kb_payment_transaction_id, kb_payment_method_id, context, options)
|
412
375
|
options[:token] = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :token) || find_last_token(kb_account_id, context.tenant_id)
|
413
376
|
# Find the payment_processor_id if not provided
|
414
377
|
payment_processor_account_id ||= find_payment_processor_id_from_initial_call(kb_account_id, context.tenant_id, options[:token])
|
415
378
|
options[:payment_processor_account_id] = payment_processor_account_id
|
416
|
-
options[:payer_id] = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :payer_id)
|
417
|
-
|
418
|
-
if with_baid
|
419
|
-
baid_payment_processor_account_id = payment_master_processor_account_id
|
420
|
-
else
|
421
|
-
baid_payment_processor_account_id = payment_processor_account_id
|
422
|
-
end
|
423
|
-
|
424
|
-
if with_baid
|
425
|
-
if options.has_key?(:token) && options[:reference_id].nil?
|
426
|
-
# Retrieve payer_id and payer_email
|
427
|
-
begin
|
428
|
-
|
429
|
-
payer_info = get_payer_info(options[:token],
|
430
|
-
kb_account_id,
|
431
|
-
context.tenant_id,
|
432
|
-
baid_payment_processor_account_id,
|
433
|
-
kb_payment_id,
|
434
|
-
kb_payment_transaction_id,
|
435
|
-
transaction_type)
|
436
|
-
rescue => e
|
437
|
-
# Maybe invalid token?
|
438
|
-
response = @response_model.create(:api_call => api_call_type,
|
439
|
-
:kb_account_id => kb_account_id,
|
440
|
-
:kb_payment_id => kb_payment_id,
|
441
|
-
:kb_payment_transaction_id => kb_payment_transaction_id,
|
442
|
-
:transaction_type => transaction_type,
|
443
|
-
:authorization => nil,
|
444
|
-
:payment_processor_account_id => baid_payment_processor_account_id,
|
445
|
-
:kb_tenant_id => context.tenant_id,
|
446
|
-
:success => false,
|
447
|
-
:created_at => Time.now.utc,
|
448
|
-
:updated_at => Time.now.utc,
|
449
|
-
:message => { :payment_plugin_status => :CANCELED, :exception_class => e.class.to_s, :exception_message => e.message }.to_json)
|
450
|
-
return response.to_transaction_info_plugin(nil)
|
451
|
-
end
|
452
|
-
if options[:payer_id].nil?
|
453
|
-
options[:payer_id] = payer_info.payer_id
|
454
|
-
end
|
455
|
-
options[:payer_email] = payer_info.payer_email
|
456
|
-
|
457
|
-
begin
|
458
|
-
options[:reference_id] = create_billing_aggrement(options[:token],
|
459
|
-
kb_account_id,
|
460
|
-
context.tenant_id,
|
461
|
-
baid_payment_processor_account_id,
|
462
|
-
kb_payment_id,
|
463
|
-
kb_payment_transaction_id,
|
464
|
-
transaction_type).billing_agreement_id
|
465
|
-
rescue => e
|
466
|
-
# Maybe invalid token?
|
467
|
-
response = @response_model.create(:api_call => api_call_type,
|
468
|
-
:kb_account_id => kb_account_id,
|
469
|
-
:kb_payment_id => kb_payment_id,
|
470
|
-
:kb_payment_transaction_id => kb_payment_transaction_id,
|
471
|
-
:transaction_type => transaction_type,
|
472
|
-
:authorization => nil,
|
473
|
-
:payment_processor_account_id => baid_payment_processor_account_id,
|
474
|
-
:kb_tenant_id => context.tenant_id,
|
475
|
-
:success => false,
|
476
|
-
:created_at => Time.now.utc,
|
477
|
-
:updated_at => Time.now.utc,
|
478
|
-
:message => { :payment_plugin_status => :CANCELED, :exception_class => e.class.to_s, :exception_message => e.message }.to_json)
|
479
|
-
return response.to_transaction_info_plugin(nil)
|
480
|
-
end
|
481
|
-
end
|
482
379
|
|
380
|
+
# We have a baid on file
|
381
|
+
if options[:reference_id]
|
483
382
|
if is_authorize
|
484
383
|
gateway_call_proc = Proc.new do |gateway, linked_transaction, payment_source, amount_in_cents, options|
|
485
384
|
# Can't use default implementation: the purchase signature is for one-off payments only
|
@@ -492,39 +391,37 @@ module Killbill #:nodoc:
|
|
492
391
|
end
|
493
392
|
end
|
494
393
|
else
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
options[:payer_id] = payer_info.payer_id
|
525
|
-
end
|
526
|
-
options[:payer_email] = payer_info.payer_email
|
394
|
+
# One-off payment
|
395
|
+
# Retrieve payer_id and payer_email
|
396
|
+
begin
|
397
|
+
payer_info = get_payer_info(options[:token],
|
398
|
+
kb_account_id,
|
399
|
+
context.tenant_id,
|
400
|
+
payment_processor_account_id,
|
401
|
+
kb_payment_id,
|
402
|
+
kb_payment_transaction_id,
|
403
|
+
transaction_type)
|
404
|
+
rescue => e
|
405
|
+
# Maybe invalid token?
|
406
|
+
response = @response_model.create(:api_call => api_call_type,
|
407
|
+
:kb_account_id => kb_account_id,
|
408
|
+
:kb_payment_id => kb_payment_id,
|
409
|
+
:kb_payment_transaction_id => kb_payment_transaction_id,
|
410
|
+
:transaction_type => transaction_type,
|
411
|
+
:authorization => nil,
|
412
|
+
:payment_processor_account_id => payment_processor_account_id,
|
413
|
+
:kb_tenant_id => context.tenant_id,
|
414
|
+
:success => false,
|
415
|
+
:created_at => Time.now.utc,
|
416
|
+
:updated_at => Time.now.utc,
|
417
|
+
:message => { :payment_plugin_status => :CANCELED, :exception_class => e.class.to_s, :exception_message => e.message }.to_json)
|
418
|
+
return response.to_transaction_info_plugin(nil)
|
419
|
+
end
|
420
|
+
options[:payer_id] = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :payer_id)
|
421
|
+
if options[:payer_id].nil?
|
422
|
+
options[:payer_id] = payer_info.payer_id
|
527
423
|
end
|
424
|
+
options[:payer_email] = payer_info.payer_email
|
528
425
|
|
529
426
|
if is_authorize
|
530
427
|
gateway_call_proc = Proc.new do |gateway, linked_transaction, payment_source, amount_in_cents, options|
|
@@ -717,19 +614,15 @@ module Killbill #:nodoc:
|
|
717
614
|
end
|
718
615
|
|
719
616
|
def get_raw_payment_info(kb_payment_id, context)
|
617
|
+
ignored_api_calls = [:details_for]
|
720
618
|
responses = @response_model.from_kb_payment_id(@transaction_model, kb_payment_id, context.tenant_id)
|
721
|
-
details_for_response = responses.select {|r| r.api_call.to_sym == :details_for}.last
|
722
|
-
details_for_plugin_info = details_for_response.nil? ? nil : details_for_response.to_transaction_info_plugin
|
723
|
-
|
724
619
|
responses = responses.reject do |response|
|
725
|
-
response
|
620
|
+
ignored_api_calls.include?(response.api_call.to_sym)
|
726
621
|
end
|
727
622
|
t_info_plugins = responses.collect do |response|
|
728
623
|
response.to_transaction_info_plugin(response.send("#{@identifier}_transaction"))
|
729
624
|
end
|
730
625
|
|
731
|
-
merge_selected_properties_from_details_call(t_info_plugins, details_for_plugin_info, [:payerEmail])
|
732
|
-
|
733
626
|
# Completed purchases/authorizations will have two rows in the responses table (one for api_call 'build_form_descriptor', one for api_call 'purchase/authorize')
|
734
627
|
# Other transaction types don't support the :PENDING state
|
735
628
|
target_transaction_types = [:PURCHASE, :AUTHORIZE]
|
@@ -737,25 +630,7 @@ module Killbill #:nodoc:
|
|
737
630
|
|
738
631
|
# Filter out the pending transaction if there is already a response tied with the same transaction but indicating a final state
|
739
632
|
t_info_plugins_without_pending = t_info_plugins.reject { |t_info_plugin| target_transaction_types.include?(t_info_plugin.transaction_type) && t_info_plugin.status == :PENDING }
|
740
|
-
|
741
|
-
result
|
742
|
-
end
|
743
|
-
|
744
|
-
def merge_selected_properties_from_details_call(plugin_infos, to_merge_plugin_info, merge_properties)
|
745
|
-
unless to_merge_plugin_info.nil?
|
746
|
-
plugin_infos.each do |trx_plugin_info|
|
747
|
-
merge_properties.each do |p|
|
748
|
-
p_value = find_value_from_properties(to_merge_plugin_info.properties, p)
|
749
|
-
unless p_value.blank?
|
750
|
-
if trx_plugin_info.properties.detect {|mp| mp.key.to_s == p.to_s}.nil?
|
751
|
-
trx_plugin_info.properties << create_plugin_property(p.to_s, p_value)
|
752
|
-
else
|
753
|
-
trx_plugin_info.properties.detect {|mp| mp.key.to_s == p.to_s} .value = p_value
|
754
|
-
end
|
755
|
-
end
|
756
|
-
end
|
757
|
-
end
|
758
|
-
end
|
633
|
+
[with_only_pending_trx ? t_info_plugins : t_info_plugins_without_pending, t_info_plugins, with_only_pending_trx]
|
759
634
|
end
|
760
635
|
end
|
761
636
|
end
|
@@ -25,8 +25,8 @@ module Killbill #:nodoc:
|
|
25
25
|
|
26
26
|
if with_baid
|
27
27
|
options[:billing_agreement] ||= {}
|
28
|
-
options[:billing_agreement][:type] ||=
|
29
|
-
options[:billing_agreement][:description] ||=
|
28
|
+
options[:billing_agreement][:type] ||= 'MerchantInitiatedBilling'
|
29
|
+
options[:billing_agreement][:description] ||= 'Kill Bill billing agreement'
|
30
30
|
end
|
31
31
|
|
32
32
|
# Go to Paypal (SetExpressCheckout call)
|
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: killbill-paypal-express
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
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:
|
11
|
+
date: 2018-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: '
|
18
|
+
version: '9.4'
|
19
19
|
name: killbill
|
20
20
|
prerelease: false
|
21
21
|
type: :runtime
|
@@ -23,7 +23,7 @@ dependencies:
|
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '9.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
@@ -237,7 +237,7 @@ dependencies:
|
|
237
237
|
requirements:
|
238
238
|
- - "~>"
|
239
239
|
- !ruby/object:Gem::Version
|
240
|
-
version:
|
240
|
+
version: 3.5.0
|
241
241
|
name: rspec
|
242
242
|
prerelease: false
|
243
243
|
type: :development
|
@@ -245,7 +245,7 @@ dependencies:
|
|
245
245
|
requirements:
|
246
246
|
- - "~>"
|
247
247
|
- !ruby/object:Gem::Version
|
248
|
-
version:
|
248
|
+
version: 3.5.0
|
249
249
|
- !ruby/object:Gem::Dependency
|
250
250
|
requirement: !ruby/object:Gem::Requirement
|
251
251
|
requirements:
|
@@ -260,6 +260,26 @@ dependencies:
|
|
260
260
|
- - "~>"
|
261
261
|
- !ruby/object:Gem::Version
|
262
262
|
version: 2.53.0
|
263
|
+
- !ruby/object:Gem::Dependency
|
264
|
+
requirement: !ruby/object:Gem::Requirement
|
265
|
+
requirements:
|
266
|
+
- - "~>"
|
267
|
+
- !ruby/object:Gem::Version
|
268
|
+
version: '1.2'
|
269
|
+
- - "<="
|
270
|
+
- !ruby/object:Gem::Version
|
271
|
+
version: 1.2.4
|
272
|
+
name: websocket
|
273
|
+
prerelease: false
|
274
|
+
type: :development
|
275
|
+
version_requirements: !ruby/object:Gem::Requirement
|
276
|
+
requirements:
|
277
|
+
- - "~>"
|
278
|
+
- !ruby/object:Gem::Version
|
279
|
+
version: '1.2'
|
280
|
+
- - "<="
|
281
|
+
- !ruby/object:Gem::Version
|
282
|
+
version: 1.2.4
|
263
283
|
- !ruby/object:Gem::Dependency
|
264
284
|
requirement: !ruby/object:Gem::Requirement
|
265
285
|
requirements:
|