killbill-paypal-express 5.0.6 → 5.0.7

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: 139032a64440a821aa18d1c0318b2dc5e4ea11ae
4
- data.tar.gz: 8fbea55f5942536f77a62844ca37c7587f79c0a4
3
+ metadata.gz: 676182610bc34593c024ec51d56c21085579e736
4
+ data.tar.gz: cbdb8f6786bdf4b0fb11447816895e239418028c
5
5
  SHA512:
6
- metadata.gz: 720423a7ebac4b0c91159520b3b8ba213418c9624ed8ccf012bc5dd801347b5423ea425879a8120c83ffd866782c45cef721c5103412021b0d370523529f2929
7
- data.tar.gz: c1c34495e9987498d6c9fc6d6e3f9c34bedcbb4a518632a5df45c6b71e03c8f52ced690c2e05f761e0d128826e728fd2f8a848047d1e53074262a8357023ef04
6
+ metadata.gz: 07ae4a47b367ee2957abb5dfa7f037c5890c1d854c9c2235b42d81d5eecdd1f885d70daa5008495290ef0f106f3aa1a996460a4e101fdb35bc41756cdb2939b6
7
+ data.tar.gz: 5259169b6b2c5e65279c74c608ebd9f07e971a6e3a69e6bd617a253b18daf3cc26628404ca8bd4083f61f1ae5f1be1c199feec20a6b38271a71097b720335055
@@ -2,8 +2,9 @@ module Killbill #:nodoc:
2
2
  module PaypalExpress #:nodoc:
3
3
  class PaymentPlugin < ::Killbill::Plugin::ActiveMerchant::PaymentPlugin
4
4
 
5
- THREE_HOURS_AGO = (3*3600)
6
- FIVE_MINUTES_AGO = 300
5
+ UNKNOWN_TRX_CANCEL_PERIOD = 3600
6
+ PENDING_TRX_CANCEL_PERIOD = (3*3600)
7
+ UNKNOWN_TRX_DELAY_FIX_PERIOD = 300
7
8
 
8
9
  def initialize
9
10
  gateway_builder = Proc.new do |config|
@@ -348,7 +349,7 @@ module Killbill #:nodoc:
348
349
  if ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :from_hpp)
349
350
  token = ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :token)
350
351
  message = {:payment_plugin_status => :PENDING,
351
- :token_expiration_period => ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :token_expiration_period) || THREE_HOURS_AGO.to_s}
352
+ :token_expiration_period => ::Killbill::Plugin::ActiveMerchant::Utils.normalized(properties_hash, :token_expiration_period) || PENDING_TRX_CANCEL_PERIOD.to_s}
352
353
  response = @response_model.create(:api_call => :build_form_descriptor,
353
354
  :kb_account_id => kb_account_id,
354
355
  :kb_payment_id => kb_payment_id,
@@ -446,9 +447,9 @@ module Killbill #:nodoc:
446
447
  response = PaypalExpressResponse.find_by(:id => paypal_response_id)
447
448
  begin
448
449
  message_details = JSON.parse response.message
449
- expiration_period = (message_details['token_expiration_period'] || THREE_HOURS_AGO).to_i
450
+ expiration_period = (message_details['token_expiration_period'] || PENDING_TRX_CANCEL_PERIOD).to_i
450
451
  rescue
451
- expiration_period = THREE_HOURS_AGO.to_i
452
+ expiration_period = PENDING_TRX_CANCEL_PERIOD.to_i
452
453
  end
453
454
  now = Time.parse(@clock.get_clock.get_utc_now.to_s)
454
455
  (now - transaction_plugin_info.created_date) >= expiration_period
@@ -574,7 +575,7 @@ module Killbill #:nodoc:
574
575
  delay_since_transaction = 0 if delay_since_transaction < 0
575
576
 
576
577
  # Do nothing before the delayed checking time
577
- janitor_delay_threshold = (Killbill::Plugin::ActiveMerchant::Utils.normalized(options, :janitor_delay_threshold) || FIVE_MINUTES_AGO).to_i
578
+ janitor_delay_threshold = (Killbill::Plugin::ActiveMerchant::Utils.normalized(options, :janitor_delay_threshold) || UNKNOWN_TRX_DELAY_FIX_PERIOD).to_i
578
579
  next unless delay_since_transaction >= janitor_delay_threshold
579
580
 
580
581
  paypal_response_id = find_value_from_properties(unknown_trx_info.properties, 'paypalExpressResponseId')
@@ -587,7 +588,7 @@ module Killbill #:nodoc:
587
588
  fixed = false
588
589
  begin
589
590
  gateway = lookup_gateway(payment_processor_account_id, context.tenant_id)
590
- fixed = @private_api.fix_unknown_transaction(response, unknown_trx_info, gateway, kb_account_id, context.tenant_id)
591
+ fixed = @private_api.fix_unknown_transaction(response, unknown_trx_info, gateway)
591
592
  logger.info("Unable to fix UNDEFINED kb_transaction_id='#{unknown_trx_info.kb_transaction_payment_id}' (not found in PayPal)") unless fixed
592
593
  rescue => e
593
594
  logger.warn("Unable to fix UNDEFINED kb_transaction_id='#{unknown_trx_info.kb_transaction_payment_id}': #{e.message}\n#{e.backtrace.join("\n")}")
@@ -595,7 +596,7 @@ module Killbill #:nodoc:
595
596
 
596
597
  if !fixed
597
598
  # hard expiration limit
598
- janitor_cancellation_threshold = (Killbill::Plugin::ActiveMerchant::Utils.normalized(options, :cancel_threshold) || THREE_HOURS_AGO).to_i
599
+ janitor_cancellation_threshold = (Killbill::Plugin::ActiveMerchant::Utils.normalized(options, :cancel_threshold) || UNKNOWN_TRX_CANCEL_PERIOD).to_i
599
600
  if delay_since_transaction >= janitor_cancellation_threshold
600
601
  response.transition_to_plugin_failure
601
602
  logger.info("Expire UNDEFINED kb_transaction_id='#{unknown_trx_info.kb_transaction_payment_id}' to CANCELED")
@@ -176,7 +176,7 @@ module Killbill #:nodoc:
176
176
  update!(updated_attributes)
177
177
  end
178
178
 
179
- def transition_to_success(transaction_id, trx_plugin_info)
179
+ def transition_to_success(transaction_id, amount, currency)
180
180
  begin
181
181
  new_message = JSON.parse(message)
182
182
  original_message = nil
@@ -198,11 +198,17 @@ module Killbill #:nodoc:
198
198
  # Update the response row
199
199
  update!(updated_attributes)
200
200
 
201
+ amount_in_cents = nil
202
+ unless amount.nil?
203
+ amount_in_cents = Monetize.from_numeric(amount.to_f, currency).cents.to_i
204
+ # Paypal search api returns a negative amount in case of successful refund
205
+ amount_in_cents = -amount_in_cents if amount_in_cents < 0
206
+ end
201
207
  # Create the transaction row if needed (cannot have been created before or the state wouldn't have been UNDEFINED)
202
208
  build_paypal_express_transaction(:kb_account_id => kb_account_id,
203
209
  :kb_tenant_id => kb_tenant_id,
204
- :amount_in_cents => trx_plugin_info.amount,
205
- :currency => trx_plugin_info.currency,
210
+ :amount_in_cents => amount_in_cents,
211
+ :currency => currency,
206
212
  :api_call => api_call,
207
213
  :kb_payment_id => kb_payment_id,
208
214
  :kb_payment_transaction_id => kb_payment_transaction_id,
@@ -49,17 +49,15 @@ module Killbill #:nodoc:
49
49
  kb_account_ids.map {|id| kb_apis.account_user_api.get_account_by_id(id, context).external_key }
50
50
  end
51
51
 
52
- def fix_unknown_transaction(plugin_response, trx_plugin_info, gateway, kb_account_id, kb_tenant_id)
53
- status, transaction_id, type = search_transaction(trx_plugin_info.created_date - ONE_HOUR_AGO,
54
- trx_plugin_info.amount,
55
- trx_plugin_info.currency,
56
- gateway,
57
- trx_plugin_info.kb_transaction_payment_id)
52
+ def fix_unknown_transaction(plugin_response, trx_plugin_info, gateway)
53
+ status, transaction_id, type, amount, currency = search_transaction(trx_plugin_info.created_date - ONE_HOUR_AGO,
54
+ gateway,
55
+ trx_plugin_info.kb_transaction_payment_id)
58
56
  return false if status.blank? || transaction_id.blank? || type.blank?
59
57
 
60
58
  if type == STATUS[trx_plugin_info.transaction_type][:type] &&
61
59
  status == STATUS[trx_plugin_info.transaction_type][:success_status]
62
- plugin_response.transition_to_success transaction_id, trx_plugin_info
60
+ plugin_response.transition_to_success transaction_id, amount, currency
63
61
  logger.info("Fixed UNDEFINED kb_transaction_id='#{trx_plugin_info.kb_transaction_payment_id}' to PROCESSED")
64
62
  return true
65
63
  end
@@ -67,10 +65,10 @@ module Killbill #:nodoc:
67
65
  false
68
66
  end
69
67
 
70
- def search_transaction(start_time, amount, currency, gateway, kb_payment_transaction_id)
71
- options = {:start_date => start_time, :invoice_id => kb_payment_transaction_id, :amount => amount, :currency => currency}
68
+ def search_transaction(start_time, gateway, kb_payment_transaction_id)
69
+ options = {:start_date => start_time, :invoice_id => kb_payment_transaction_id}
72
70
  response = gateway.transaction_search options
73
- [response.params['status'], response.authorization, response.params['type']]
71
+ [response.params['status'], response.authorization, response.params['type'], response.params['gross_amount'], response.params['gross_amount_currency_id']]
74
72
  end
75
73
  end
76
74
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: killbill-paypal-express
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.6
4
+ version: 5.0.7
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: 2017-11-23 00:00:00.000000000 Z
11
+ date: 2018-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement