killbill-orbital 0.1.16 → 0.1.17

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/orbital/api.rb +14 -0
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91350a421679b6f95e4962578817e7c0f0df4752
4
- data.tar.gz: d4a57c435bd04c18aec2e350a82840860c507173
3
+ metadata.gz: f14e1ae4b7b2bde781ca5fbe6e4dac361db5ca3d
4
+ data.tar.gz: fd8982890fde3ff7a24a514a625aecc65421783e
5
5
  SHA512:
6
- metadata.gz: 910086570f85138191317e400c3418dee367cde8f924d2ee12dd4460feb2e6daccf6765cde51ed3369246f715bef6d49aac438db3b705be0fa1746401377f552
7
- data.tar.gz: cc81b8b0ee456cae8f15cabafb7e2cebc066b16ba30fe496de9f1f85b04f674e3e250b481cc072e2e9973a7547f0581a554405f2739707342c9210ac756f67df
6
+ metadata.gz: 685653b258fee88041ddbcd2e407bef5b12bb0511bf4a17a63300e65f9fed5c5c1764c1cc33bc85d2fed816bc58fae57c875b2e3fdf29ad98787bb670efbb67a
7
+ data.tar.gz: eb071378582c5f1c88419c0dd2d442700f4a3516ab10496fe5c8d68abcc6e7c392b45b4da40dfb00d8e230b9d2280e71d8b7f3414b21dbf81b1cff307f67ecf0
data/lib/orbital/api.rb CHANGED
@@ -3,6 +3,7 @@ module Killbill #:nodoc:
3
3
  class PaymentPlugin < ::Killbill::Plugin::ActiveMerchant::PaymentPlugin
4
4
  FIVE_MINUTES_AGO = (5 * 60)
5
5
  ONE_HOUR_AGO = (1 * 3600)
6
+ THIRTEEN_MONTHS_AGO = (24 * 60 * 60 * 30 * 13)
6
7
 
7
8
  def initialize
8
9
  gateway_builder = Proc.new do |config|
@@ -73,6 +74,10 @@ module Killbill #:nodoc:
73
74
  end
74
75
 
75
76
  def refund_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
77
+ if should_credit?(kb_payment_id, context, properties)
78
+ # Note: from the plugin perspective, this transaction is a CREDIT but Kill Bill doesn't care about PaymentTransactionInfoPlugin#TransactionType
79
+ return credit_payment(kb_account_id, kb_payment_id, kb_payment_transaction_id, kb_payment_method_id, amount, currency, properties, context)
80
+ end
76
81
  # Pass extra parameters for the gateway here
77
82
  options = {}
78
83
 
@@ -144,6 +149,15 @@ module Killbill #:nodoc:
144
149
  super
145
150
  end
146
151
 
152
+ def should_credit?(kb_payment_id, context, options = {})
153
+ transaction = @transaction_model.find_candidate_transaction_for_refund(kb_payment_id, context.tenant_id)
154
+ return false if transaction.nil?
155
+
156
+ threshold = (Killbill::Plugin::ActiveMerchant::Utils.normalized(options, :janitor_delay_threshold) || THIRTEEN_MONTHS_AGO).to_i
157
+ options[:payment_processor_account_id] ||= transaction.payment_processor_account_id
158
+ (now - transaction.created_at) >= threshold
159
+ end
160
+
147
161
  private
148
162
 
149
163
  def try_fix_undefined_trxs(plugin_trxs_info, options, context)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: killbill-orbital
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: 0.1.17
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: 2019-01-02 00:00:00.000000000 Z
11
+ date: 2019-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement