invoicing_payments_processing 1.1.30 → 1.1.36

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/invoice.rb +36 -16
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 212a2966346ed12f4de648a737a3ddeaea9b4886
4
- data.tar.gz: 891852dc15b535c8eff5bfbdcc1f5b79b3f209b8
3
+ metadata.gz: 965a8f6366881eb0e4bc2bfc47bc1afe2ce09e11
4
+ data.tar.gz: a9b9c23cfed343171d9e815574cb56659e652bf4
5
5
  SHA512:
6
- metadata.gz: 1630c612e2036f822aa5d8540a86a9279f337b93fee1419899cd56c119d165474b765b9c75a52eee8b4b3d94ba4a5e8d1c61ba7c0a7ad9eac02b14d058604781
7
- data.tar.gz: 9e26f1b23afa365b8a09aea64d166affab51e9d15cf9e3228fa121072c3869c18a6ac75d9714e5e10c74280cd4cc18b5a106767769393282ef5e1ae6ee94c781
6
+ metadata.gz: 261a8ac7175609664b8580f69259a96e39cc8f495ed448ed6dcc4d8e1ad8e87e7f9f297e1b4ff461b21c0d95ea92a9f958b39199977ff9c73c11a0448a08ae9a
7
+ data.tar.gz: aee9ab4c785dcc5072b008ed1547debd27763a5283b6088dc7013f9f92649cc7856a79cd1be54446e92115dfc333e91e09bc0635e2634172c7143f180e879170
@@ -10,10 +10,16 @@ module BlackStack
10
10
 
11
11
  many_to_one :buffer_paypal_notification, :class=>:'BlackStack::BufferPayPalNotification', :key=>:id_buffer_paypal_notification
12
12
  many_to_one :client, :class=>:'BlackStack::Client', :key=>:id_client
13
- many_to_one :paypal_subscription, :class=>:'BlackStack::PayPalSubscription', :key=>:id_paypal_subscription
13
+ #many_to_one :paypal_subscription, :class=>:'BlackStack::PayPalSubscription', :key=>:id_paypal_subscription
14
14
  many_to_one :previous, :class=>:'BlackStack::Invoice', :key=>:id_previous_invoice
15
15
  one_to_many :items, :class=>:'BlackStack::InvoiceItem', :key=>:id_invoice
16
16
 
17
+ def paypal_subscription
18
+ return nil if self.subscr_id.nil?
19
+ return nil if self.subscr_id.to_s.size == 0
20
+ return BlackStack::PayPalSubscription.where(:subscr_id=>self.subscr_id.to_s).first
21
+ end
22
+
17
23
  # compara 2 planes, y retorna TRUE si ambos pueden coexistir en una misma facutra, con un mismo enlace de PayPal
18
24
  def self.compatibility?(h, i)
19
25
  return false if h[:type]!=i[:type]
@@ -60,6 +66,7 @@ module BlackStack
60
66
  #
61
67
  def set_subscription(s)
62
68
  self.subscr_id = s.subscr_id
69
+ self.delete_time = nil
63
70
  self.save
64
71
  # aplico la mismam modificacion a todas las factuas que le siguieron a esta
65
72
  BlackStack::Invoice.where(:id_previous_invoice=>self.id).all { |j|
@@ -204,8 +211,8 @@ module BlackStack
204
211
  trial2 = allow_trials && plan_descriptor[:trial2_fee]!=nil && plan_descriptor[:trial2_period]!=nil && plan_descriptor[:trial2_units]!=nil
205
212
 
206
213
  values[:a3] = 0
207
- self.items.each { |i|
208
- if trial1 && i.units!=i.plan_descriptor[:trial_credits]
214
+ self.items.each { |i|
215
+ if ( !trial2 && trial1 && i.units!=i.plan_descriptor[:trial_credits] ) || ( trial2 && trial1 && i.units!=i.plan_descriptor[:trial2_credits] )
209
216
  raise 'Cannot order more than 1 package and trial in the same invoice'
210
217
  elsif trial1
211
218
  values[:a3] += i.plan_descriptor[:fee].to_f
@@ -249,7 +256,11 @@ module BlackStack
249
256
 
250
257
  # retorna true si el estado de la factura sea NULL o UNPAID
251
258
  def canBeDeleted?
252
- self.status == nil || self.status == BlackStack::Invoice::STATUS_UNPAID
259
+ if self.paypal_subscription.nil?
260
+ return self.status == nil || self.status == BlackStack::Invoice::STATUS_UNPAID
261
+ else # !self.paypal_subscription.nil?
262
+ return (self.status == nil || self.status == BlackStack::Invoice::STATUS_UNPAID) && !self.paypal_subscription.active
263
+ end # if self.paypal_subscription.nil?
253
264
  end
254
265
 
255
266
  # actualiza el registro en la tabla invoice segun los parametros.
@@ -409,25 +420,34 @@ module BlackStack
409
420
  # le seteo la fecha de hoy
410
421
  self.billing_period_from = now()
411
422
  #puts
412
- #puts
423
+ #puts
424
+ # si el plan tiene un segundo trial, y
425
+ # es la primer factura, entonces:
426
+ # => se trata del segundo pago por segundo trial
427
+ if h[:trial2_fee] != nil && prev1.nil?
428
+ #puts 'b'
429
+ units = h[:trial2_credits].to_i
430
+ unit_price = h[:trial2_fee].to_f / h[:trial2_credits].to_f
431
+ billing_period_to = DB["SELECT DATEADD(#{h[:trial2_period].to_s}, +#{h[:trial2_units].to_s}, '#{self.billing_period_from.to_s}') AS [now]"].map(:now)[0].to_s
432
+
433
+ # si el plan tiene un segundo trial, y
434
+ # es la segunda factura, entonces:
435
+ # => se trata del segundo pago por segundo trial
436
+ elsif h[:trial2_fee] != nil && !prev1.nil? && prev2.nil?
437
+ #puts 'b'
438
+ units = h[:trial_credits].to_i
439
+ unit_price = h[:trial_fee].to_f / h[:trial_credits].to_f
440
+ billing_period_to = DB["SELECT DATEADD(#{h[:trial_period].to_s}, +#{h[:trial_units].to_s}, '#{self.billing_period_from.to_s}') AS [now]"].map(:now)[0].to_s
441
+
413
442
  # si el plan tiene un primer trial, y
414
443
  # es la primer factura, entonces:
415
444
  # => se trata del primer pago por trial
416
- if h[:trial_fee] != nil && prev1.nil? && !self.disabled_for_trial_ssm
445
+ elsif h[:trial_fee] != nil && prev1.nil? && !self.disabled_for_trial_ssm
417
446
  #puts 'a'
418
447
  units = h[:trial_credits].to_i
419
448
  unit_price = h[:trial_fee].to_f / h[:trial_credits].to_f
420
449
  billing_period_to = DB["SELECT DATEADD(#{h[:trial_period].to_s}, +#{h[:trial_units].to_s}, '#{self.billing_period_from.to_s}') AS [now]"].map(:now)[0].to_s
421
-
422
- # si el plan tiene un segundo trial, y
423
- # es la segunda factura, entonces:
424
- # => se trata del segundo pago por segundo trial
425
- elsif h[:trial2_fee] != nil && !prev1.nil? && prev2.nil?
426
- #puts 'b'
427
- units = h[:trial2_credits].to_i
428
- unit_price = h[:trial2_fee].to_f / h[:trial2_credits].to_f
429
- billing_period_to = DB["SELECT DATEADD(#{h[:trial2_period].to_s}, +#{h[:trial2_units].to_s}, '#{self.billing_period_from.to_s}') AS [now]"].map(:now)[0].to_s
430
-
450
+
431
451
  # si el plan tiene un fee, y
432
452
  elsif h[:fee].to_f != nil && h[:type] == BlackStack::InvoicingPaymentsProcessing::BasePlan::PAYMENT_SUBSCRIPTION
433
453
  #puts 'c'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invoicing_payments_processing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.30
4
+ version: 1.1.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Daniel Sardi