invoicing_payments_processing 1.1.27 → 1.1.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/invoice.rb +39 -19
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d97ab4f8d1bbf4504ea494d1f4f0654c6dedac5
4
- data.tar.gz: d2aa430675b74c58792d858b9446b961152a31dd
3
+ metadata.gz: 5243e3335e6493c1a4ce19769c46730729576904
4
+ data.tar.gz: 068bb5e32c323da931510da9c205606a8778e645
5
5
  SHA512:
6
- metadata.gz: a19f653d1435378092a77cb576f8f92b21cf5f5fe68e03b349f16ae547ff93efe379de7d7cd4bd1509b3717cbe9d3d26a4cedba96b5a9e2e81fb1a671bb8f47f
7
- data.tar.gz: 9e6823c86dc08d36a8f629fd18eb605a105df7e8ad87603c40c6a199c448ca872daaa2725656376d0c594246af1872e95e21726f6620fbfaec4a5a029d1f8a49
6
+ metadata.gz: 5310182c911009e0e22aae4f5ceaacce08472298b9c4126953ba0831850a60cb161b6979b85d29e890b8da028620b71b657a2abbaf6e4656b901f85d8208f2a3
7
+ data.tar.gz: 2b86a7c418f70faa014d76e3025423b680c011eed88bb29c0176c1e0402fe67b647d83c5cdd20a77ee0a2e9a493ec48690da965c35c543eddd854af4bc26a572
@@ -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|
@@ -246,6 +253,15 @@ module BlackStack
246
253
  def canBePaid?
247
254
  self.status == nil || self.status == BlackStack::Invoice::STATUS_UNPAID
248
255
  end
256
+
257
+ # retorna true si el estado de la factura sea NULL o UNPAID
258
+ def canBeDeleted?
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?
264
+ end
249
265
 
250
266
  # actualiza el registro en la tabla invoice segun los parametros.
251
267
  # en este caso la factura se genera antes del pago.
@@ -298,6 +314,7 @@ module BlackStack
298
314
  end
299
315
  # marco la factura como pagada
300
316
  self.status = BlackStack::Invoice::STATUS_PAID
317
+ self.delete_time = nil
301
318
  self.save
302
319
  # expiracion de creditos de la factura anterior
303
320
  i = self.previous
@@ -325,19 +342,21 @@ module BlackStack
325
342
  # registro el pago
326
343
  BlackStack::Movement.new().parse(item, BlackStack::Movement::MOVEMENT_TYPE_ADD_PAYMENT, "Invoice Payment", payment_time, item.id).save()
327
344
  # agrego los bonos de este plan
328
- plan[:bonus_plans].each { |h|
329
- plan_bonus = BlackStack::InvoicingPaymentsProcessing.plan_descriptor(h[:item_number])
330
- raise "bonus plan not found" if plan_bonus.nil?
331
- bonus = BlackStack::InvoiceItem.new
332
- bonus.id = guid()
333
- bonus.id_invoice = self.id
334
- bonus.product_code = plan_bonus[:product_code]
335
- bonus.unit_price = 0
336
- bonus.units = plan_bonus[:credits] * item.number_of_packages # agrego los creditos del bono, multiplicado por la cantiad de paquetes
337
- bonus.amount = 0
338
- bonus.item_number = plan_bonus[:item_number]
339
- BlackStack::Movement.new().parse(bonus, BlackStack::Movement::MOVEMENT_TYPE_ADD_BONUS, 'Payment Bonus', payment_time, item.id).save()
340
- }
345
+ if !plan[:bonus_plans].nil?
346
+ plan[:bonus_plans].each { |h|
347
+ plan_bonus = BlackStack::InvoicingPaymentsProcessing.plan_descriptor(h[:item_number])
348
+ raise "bonus plan not found" if plan_bonus.nil?
349
+ bonus = BlackStack::InvoiceItem.new
350
+ bonus.id = guid()
351
+ bonus.id_invoice = self.id
352
+ bonus.product_code = plan_bonus[:product_code]
353
+ bonus.unit_price = 0
354
+ bonus.units = plan_bonus[:credits] * item.number_of_packages # agrego los creditos del bono, multiplicado por la cantiad de paquetes
355
+ bonus.amount = 0
356
+ bonus.item_number = plan_bonus[:item_number]
357
+ BlackStack::Movement.new().parse(bonus, BlackStack::Movement::MOVEMENT_TYPE_ADD_BONUS, 'Payment Bonus', payment_time, item.id).save()
358
+ }
359
+ end # if !plan[:bonus_plans].nil?
341
360
  #
342
361
  DB.disconnect
343
362
  GC.start
@@ -400,11 +419,12 @@ module BlackStack
400
419
 
401
420
  # le seteo la fecha de hoy
402
421
  self.billing_period_from = now()
403
-
422
+ #puts
423
+ #puts
404
424
  # si el plan tiene un primer trial, y
405
425
  # es la primer factura, entonces:
406
426
  # => se trata del primer pago por trial
407
- if h[:trial_fee] != nil && prev1.nil?
427
+ if h[:trial_fee] != nil && prev1.nil? && !self.disabled_for_trial_ssm
408
428
  #puts 'a'
409
429
  units = h[:trial_credits].to_i
410
430
  unit_price = h[:trial_fee].to_f / h[:trial_credits].to_f
@@ -420,13 +440,13 @@ module BlackStack
420
440
  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
421
441
 
422
442
  # si el plan tiene un fee, y
423
- elsif h[:fee].to_f != nil && !prev1.nil? && !prev2.nil?
443
+ elsif h[:fee].to_f != nil && h[:type] == BlackStack::InvoicingPaymentsProcessing::BasePlan::PAYMENT_SUBSCRIPTION
424
444
  #puts 'c'
425
445
  units = n.to_i * h[:credits].to_i
426
446
  unit_price = h[:fee].to_f / h[:credits].to_f
427
447
  billing_period_to = DB["SELECT DATEADD(#{h[:period].to_s}, +#{h[:units].to_s}, '#{self.billing_period_from.to_s}') AS [now]"].map(:now)[0].to_s
428
448
 
429
- elsif (!isSubscription && h[:fee].to_f != nil)
449
+ elsif h[:fee].to_f != nil && h[:type] == BlackStack::InvoicingPaymentsProcessing::BasePlan::PAYMENT_PAY_AS_YOU_GO
430
450
  #puts 'd'
431
451
  units = n.to_i * h[:credits].to_i
432
452
  unit_price = h[:fee].to_f / h[:credits].to_f
@@ -523,7 +543,7 @@ module BlackStack
523
543
  self.id_previous_invoice = i.id
524
544
  self.subscr_id = i.subscr_id
525
545
  self.disabled_for_add_remove_items = true
526
-
546
+
527
547
  i.items.each { |t|
528
548
  self.add_item(t.item_number, t.number_of_packages)
529
549
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invoicing_payments_processing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.27
4
+ version: 1.1.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Daniel Sardi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-21 00:00:00.000000000 Z
11
+ date: 2020-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket