invoicing_payments_processing 1.1.46 → 1.1.51

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: 47ac3657106765a3007b2e0c911f2d6a5cd18ce5
4
- data.tar.gz: c1bc83fe3b6f7d73131bf19927fa99f8087b9768
3
+ metadata.gz: 624069067ef76f9401f22e552151eb438e6d82f9
4
+ data.tar.gz: 3d628ef7f38ef8d9a0810295393df5673ebcb2d4
5
5
  SHA512:
6
- metadata.gz: bf3dbb3323b05a383925f958f20a6402ed4f5ccc17de7d96ffccdac5066149f92a26c6da1357d7769dcadf87a0f1d56f1aad04b3e3664155f68b378e6bc76f08
7
- data.tar.gz: cc0474ff9ac7f199036f20161a781a092396dc1deccfadba46f8b181073a9be3f5b1bcfb534a3e7d82442c78352bf403a37b5e5616d726cbbc4efad30d4d3beb
6
+ metadata.gz: dc95fb5484a6809daa6df41676dcae565378f4f8cdaf1db0de386a954b0cc5484c458f34205583230120fbfa131fb4a28181383987b89e76ea86bf36a610fbed
7
+ data.tar.gz: f446b933246ea93c568826197ea3c3f00dc7dc176817cc125e4948038b12e967ec52c783eb95a0418d092a245aaf146daa89d2f3615572fbb389bd90d27600e5
@@ -41,20 +41,34 @@ module BlackStack
41
41
  # 3) haciendo coincidir el campo payer_email de alguna suscripcion existente con el BlackStack::BufferPayPalNotification.payer_email
42
42
  # 3) haciendo coincidir el primer guid en el codigo de invoice, con el id del cliente
43
43
  def get_client()
44
+ puts
45
+ puts "BlackStack::BufferPayPalNotification::get_client"
46
+ puts 'debug info:'
47
+ puts "self.invoice:#{self.invoice.to_s}:."
44
48
  # obtengo el cliente que machea con este perfil
45
49
  c = nil
46
50
  if c.nil?
51
+ puts 'a'
47
52
  if self.invoice.guid?
53
+ puts 'b'
48
54
  i = BlackStack::Invoice.where(:id=>self.invoice).first
49
55
  c = i.client if !i.nil?
50
56
  end
51
57
  end
52
58
  if c.nil?
59
+ puts 'c'
53
60
  cid = self.invoice.split(".").first.to_s
61
+ puts "c:#{cid}:."
54
62
  if cid.guid?
63
+ puts 'd'
55
64
  c = BlackStack::Client.where(:id=>cid).first
56
65
  end
57
66
  end
67
+ =begin
68
+ # deprecated: debe obtenerse la factura (invoice), y de ahi el cliente,
69
+ # => porque un mismo cuente puede usar su cuenta paypal en varias cuantas
70
+ # => de usuario.
71
+ #
58
72
  if c.nil?
59
73
  c = BlackStack::Client.where(:paypal_email=>self.payer_email).first
60
74
  if (c == nil)
@@ -83,6 +97,7 @@ module BlackStack
83
97
  c = BlackStack::Client.where(:id=>row[:cid]).first
84
98
  end
85
99
  end
100
+ =end
86
101
  c
87
102
  end
88
103
 
@@ -316,10 +331,12 @@ module BlackStack
316
331
  j.next(i)
317
332
 
318
333
  # creo el milestone con todo el credito pendiente que tiene esta subscripcion
334
+ =begin
335
+ # deprecated
319
336
  buff_payment = i.buffer_paypal_notification
320
337
  buff_signup = BlackStack::BufferPayPalNotification.where(:txn_type=>"subscr_signup", :subscr_id=>buff_payment.subscr_id).first
321
338
  subs = buff_signup == nil ? nil : BlackStack::PayPalSubscription.where(:id_buffer_paypal_notification => buff_signup.id).first
322
-
339
+ =end
323
340
  elsif (b.txn_type == BlackStack::BufferPayPalNotification::TXN_TYPE_SUBSCRIPTION_SIGNUP)
324
341
  # crear un registro en la tabla paypal_subscriptions
325
342
  if BlackStack::PayPalSubscription.load(b.to_hash) != nil
@@ -336,7 +353,7 @@ module BlackStack
336
353
  s.save
337
354
 
338
355
  # obtengo la factura que se creo con esta suscripcion
339
- i = BlackStack::Invoice.where(:id=>b.item_number).first
356
+ i = BlackStack::Invoice.where(:id=>b.invoice).first
340
357
 
341
358
  # vinculo esta suscripcion a la factura que la genero, y a todas las facturas siguientes
342
359
  i.set_subscription(s)
@@ -35,7 +35,7 @@ module BlackStack
35
35
  total_amount = 0.to_f - BlackStack::Balance.new(self.id, product_code).amount.to_f
36
36
  sleep(2) # delay to ensure the time of the bonus movement will be later than the time of the consumption movement
37
37
  if total_credits < 0
38
- self.adjustment(product_code, total_amount, total_credits, 'Adjustment Because Quota Has Been Exceeded.')
38
+ self.adjustment(product_code, total_amount, total_credits, 'Adjustment Because Quota Has Been Exceeded (1).')
39
39
  end
40
40
  # recaculate amounts in both consumptions and expirations - CANCELADO - Se debe hacer offline
41
41
  #self.recalculate(product_code)
@@ -97,7 +97,7 @@ module BlackStack
97
97
 
98
98
  self.movements.select { |o|
99
99
  o.product_code.upcase == product_code.upcase
100
- }.sort_by { |o| o.create_time }.each { |o|
100
+ }.sort_by { |o| [o.create_time, o.type] }.each { |o| # se ordena por o.create_time, pero tmabien por o.type para procesar primero los pagos y bonos
101
101
  #if o.credits.to_f < 0 # payment or bonus
102
102
  # if o.credits.to_f > 0 && ( o.type==BlackStack::Movement::MOVEMENT_TYPE_CANCELATION || o.type==BlackStack::Movement::MOVEMENT_TYPE_EXPIRATION ) # consumption or expiration
103
103
  # consumption or expiration or bonus
@@ -118,7 +118,7 @@ module BlackStack
118
118
  total_credits = credits_paid
119
119
  total_amount = amount_paid
120
120
  if total_credits < 0
121
- self.adjustment(product_code, total_amount, total_credits, 'Adjustment Because Quota Has Been Exceeded.', BlackStack::Movement::MOVEMENT_TYPE_ADJUSTMENT, o.create_time)
121
+ self. adjustment(product_code, total_amount, total_credits, 'Adjustment Because Quota Has Been Exceeded (2).', BlackStack::Movement::MOVEMENT_TYPE_ADJUSTMENT, o.create_time)
122
122
  amount_paid = 0.to_f
123
123
  credits_paid = 0.to_i
124
124
  end
@@ -328,7 +328,7 @@ module BlackStack
328
328
  #
329
329
  BlackStack::Movement.where(:id_invoice_item => item.id).all { |mov|
330
330
  #
331
- mov.expire(self.billing_period_from) if mov.expiration_on_next_payment == true
331
+ mov.expire(self.billing_period_from, "Expiration of <a href='/member/record?rid=#{mov.id.to_guid}'>record:#{mov.id.to_guid}</a> because subscription renewal.") if mov.expiration_on_next_payment == true
332
332
  #
333
333
  DB.disconnect
334
334
  GC.start
@@ -345,7 +345,7 @@ module BlackStack
345
345
  # obtengo descriptor del producto
346
346
  prod = BlackStack::InvoicingPaymentsProcessing.product_descriptor(plan[:product_code])
347
347
  # registro el pago
348
- BlackStack::Movement.new().parse(item, BlackStack::Movement::MOVEMENT_TYPE_ADD_PAYMENT, "Invoice Payment", payment_time, item.id).save()
348
+ BlackStack::Movement.new().parse(item, BlackStack::Movement::MOVEMENT_TYPE_ADD_PAYMENT, "Payment of <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.", payment_time, item.id).save()
349
349
  # agrego los bonos de este plan
350
350
  if !plan[:bonus_plans].nil?
351
351
  plan[:bonus_plans].each { |h|
@@ -359,7 +359,7 @@ module BlackStack
359
359
  bonus.units = plan_bonus[:credits] * item.number_of_packages # agrego los creditos del bono, multiplicado por la cantiad de paquetes
360
360
  bonus.amount = 0
361
361
  bonus.item_number = plan_bonus[:item_number]
362
- BlackStack::Movement.new().parse(bonus, BlackStack::Movement::MOVEMENT_TYPE_ADD_BONUS, 'Payment Bonus', payment_time, item.id).save()
362
+ BlackStack::Movement.new().parse(bonus, BlackStack::Movement::MOVEMENT_TYPE_ADD_BONUS, "Bonus from the <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.", payment_time, item.id).save()
363
363
  }
364
364
  end # if !plan[:bonus_plans].nil?
365
365
  #
@@ -624,21 +624,47 @@ module BlackStack
624
624
  item1.detail = u.detail.to_s
625
625
  item1.description = u.description.to_s
626
626
  item1.save()
627
- BlackStack::Movement.new().parse(item1, BlackStack::Movement::MOVEMENT_TYPE_REFUND_BALANCE, 'Full Refund').save()
628
- # si el balance quedo en negativo, entonces aplico otro ajuste
627
+ # hago el reembolso de este item
628
+ # si el balance quedo en negativo, entonces aplico otro ajuste
629
+ BlackStack::Movement.new().parse(item1, BlackStack::Movement::MOVEMENT_TYPE_REFUND_BALANCE, "Full Refund of <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.").save()
629
630
  net_amount = 0.to_f - BlackStack::Balance.new(self.client.id, u.product_code.to_s).amount.to_f
630
631
  net_credits = 0.to_f - BlackStack::Balance.new(self.client.id, u.product_code.to_s).credits.to_f
631
- if net_amount < 0 && net_credits < 0
632
- adjust = self.client.adjustment(u.product_code.to_s, net_amount, net_credits, 'Adjustment for Negative Balance after Refund')
632
+ if net_amount <= 0 && net_credits < 0
633
+ adjust = self.client.adjustment(u.product_code.to_s, net_amount, net_credits, "Adjustment for Negative Balance After Refund of <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.")
633
634
  adjust.id_invoice_item = item1.id
634
635
  adjust.save
635
636
  end # if net_amount < 0
637
+ # hago el reembolso de cada bono de este item
638
+ # si el balance quedo en negativo, entonces aplico otro ajuste
639
+ h[:bonus_plans].each { |bonus|
640
+ i = BlackStack::InvoicingPaymentsProcessing::plans_descriptor.select { |obj| obj[:item_number] == bonus[:item_number] }.first
641
+ j = BlackStack::InvoicingPaymentsProcessing::products_descriptor.select { |obj| obj[:code] == i[:product_code] }.first
642
+ item2 = BlackStack::InvoiceItem.new()
643
+ item2.id = guid()
644
+ item2.id_invoice = self.id
645
+ item2.unit_price = 0
646
+ item2.units = -i[:credits]
647
+ item2.amount = 0
648
+ item2.product_code = i[:product_code].to_s
649
+ item2.item_number = i[:item_number].to_s
650
+ item2.detail = 'Bonus Refund'
651
+ item2.description = j[:description].to_s
652
+ item2.save()
653
+ BlackStack::Movement.new().parse(item2, BlackStack::Movement::MOVEMENT_TYPE_REFUND_BALANCE, "Bonus Refund of <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.").save()
654
+ net_amount = 0.to_f - BlackStack::Balance.new(self.client.id, i[:product_code].to_s).amount.to_f
655
+ net_credits = 0.to_f - BlackStack::Balance.new(self.client.id, i[:product_code].to_s).credits.to_f
656
+ if net_amount <= 0 && net_credits < 0
657
+ adjust = self.client.adjustment(i[:product_code].to_s, net_amount, net_credits, "Adjustment for Negative Balance After Bonus Refund of <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.")
658
+ adjust.id_invoice_item = item1.id
659
+ adjust.save
660
+ end # if net_amount < 0
661
+ }
636
662
  # release resources
637
663
  DB.disconnect
638
664
  GC.start
639
665
  } # i.items.each { |u|
640
666
  # reembolso parcial de una factura con un unico item
641
- elsif i.items.size == 1
667
+ elsif i.items.size == 1 # and we know that: total < -payment_gross, so it is a partial refund
642
668
  t = i.items.first
643
669
  #
644
670
  amount = -payment_gross.to_f
@@ -659,11 +685,11 @@ module BlackStack
659
685
  item1.detail = t.detail.to_s
660
686
  item1.description = t.description.to_s
661
687
  item1.save()
662
- BlackStack::Movement.new().parse(item1, BlackStack::Movement::MOVEMENT_TYPE_REFUND_BALANCE, 'Partial Refund').save()
688
+ BlackStack::Movement.new().parse(item1, BlackStack::Movement::MOVEMENT_TYPE_REFUND_BALANCE, "Partial Refund of <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.").save()
663
689
  # agrego un ajuste por el redondeo a una cantidad entera de creditos
664
690
  if float_units.to_f != units.to_f
665
691
  adjustment_amount = unit_price.to_f * (units.to_f - float_units.to_f)
666
- adjust = self.client.adjustment(t.product_code.to_s, adjustment_amount, 0, 'Adjustment for Partial Refund', BlackStack::Movement::MOVEMENT_TYPE_REFUND_ADJUSTMENT)
692
+ adjust = self.client.adjustment(t.product_code.to_s, adjustment_amount, 0, "Adjustment for Refund of <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.", BlackStack::Movement::MOVEMENT_TYPE_REFUND_ADJUSTMENT)
667
693
  adjust.id_invoice_item = item1.id
668
694
  adjust.save
669
695
  end
@@ -671,13 +697,43 @@ module BlackStack
671
697
  net_amount = 0.to_f - BlackStack::Balance.new(self.client.id, t.product_code.to_s).amount.to_f
672
698
  net_credits = 0.to_f - BlackStack::Balance.new(self.client.id, t.product_code.to_s).credits.to_f
673
699
  if net_amount < 0 && net_credits < 0
674
- adjust = self.client.adjustment(t.product_code.to_s, net_amount, net_credits, 'Adjustment for Negative Balance')
700
+ adjust = self.client.adjustment(t.product_code.to_s, net_amount, net_credits, "Adjustment for Negative Balance After Refund of <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.")
675
701
  adjust.id_invoice_item = item1.id
676
702
  adjust.save
677
703
  end # if net_amount < 0
704
+
678
705
  # recalculo todos los consumos y expiraciones - CANCELADO - Debe hacerse offline
679
- # self.client.recalculate(t.product_code.to_s)
680
- else
706
+ # => self.client.recalculate(t.product_code.to_s)
707
+
708
+ # si el cliente se quedo sin saldo luego del reembolso parcial
709
+ if net_amount <= 0
710
+ # hago el reembolso de cada bono de este item
711
+ # si el balance quedo en negativo, entonces aplico otro ajuste
712
+ h[:bonus_plans].each { |bonus|
713
+ i = BlackStack::InvoicingPaymentsProcessing::plans_descriptor.select { |obj| obj[:item_number] == bonus[:item_number] }.first
714
+ j = BlackStack::InvoicingPaymentsProcessing::products_descriptor.select { |obj| obj[:code] == i[:product_code] }.first
715
+ item2 = BlackStack::InvoiceItem.new()
716
+ item2.id = guid()
717
+ item2.id_invoice = self.id
718
+ item2.unit_price = 0
719
+ item2.units = -i[:credits]
720
+ item2.amount = 0
721
+ item2.product_code = i[:product_code].to_s
722
+ item2.item_number = i[:item_number].to_s
723
+ item2.detail = 'Bonus Refund'
724
+ item2.description = j[:description].to_s
725
+ item2.save()
726
+ BlackStack::Movement.new().parse(item2, BlackStack::Movement::MOVEMENT_TYPE_REFUND_BALANCE, "Bonus Refund of <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.").save()
727
+ net_amount = 0.to_f - BlackStack::Balance.new(self.client.id, i[:product_code].to_s).amount.to_f
728
+ net_credits = 0.to_f - BlackStack::Balance.new(self.client.id, i[:product_code].to_s).credits.to_f
729
+ if net_amount <= 0 && net_credits < 0
730
+ adjust = self.client.adjustment(i[:product_code].to_s, net_amount, net_credits, "Adjustment for Negative Balance After Bonus Refund of <a href='/member/invoice?iid=#{self.id.to_guid}'>invoice:#{self.id.to_guid}</a>.")
731
+ adjust.id_invoice_item = item1.id
732
+ adjust.save
733
+ end # if net_amount < 0
734
+ }
735
+ end
736
+ else # we know that: i.items.size > 1 && total < -payment_gross
681
737
  raise "Refund amount is not matching with the invoice total (#{total.to_s}) and the invoice has more than 1 item."
682
738
  end
683
739
  # release resources
@@ -15,6 +15,19 @@ module BlackStack
15
15
  MOVEMENT_TYPE_ADJUSTMENT = 6 # it can be recalculated
16
16
  MOVEMENT_TYPE_REFUND_ADJUSTMENT = 7 # it cannot be recalculated
17
17
 
18
+ def self.types()
19
+ [
20
+ MOVEMENT_TYPE_ADD_PAYMENT,
21
+ MOVEMENT_TYPE_ADD_BONUS,
22
+ MOVEMENT_TYPE_REASSIGN_BALANCE,
23
+ MOVEMENT_TYPE_REFUND_BALANCE,
24
+ MOVEMENT_TYPE_CANCELATION,
25
+ MOVEMENT_TYPE_EXPIRATION,
26
+ MOVEMENT_TYPE_ADJUSTMENT,
27
+ MOVEMENT_TYPE_REFUND_ADJUSTMENT
28
+ ]
29
+ end
30
+
18
31
  def self.typeName(t)
19
32
  if (t==MOVEMENT_TYPE_ADD_PAYMENT)
20
33
  return "Payment"
@@ -29,9 +42,9 @@ module BlackStack
29
42
  elsif (t==MOVEMENT_TYPE_EXPIRATION)
30
43
  return "Expiration"
31
44
  elsif (t==MOVEMENT_TYPE_ADJUSTMENT)
32
- return "Adjustement"
45
+ return "Credit Adjustement"
33
46
  elsif (t==MOVEMENT_TYPE_REFUND_ADJUSTMENT)
34
- return "Adjustement"
47
+ return "Refund Adjustement"
35
48
  end
36
49
  '(unknown)'
37
50
  end
@@ -44,7 +57,7 @@ module BlackStack
44
57
  if (t==MOVEMENT_TYPE_ADD_PAYMENT)
45
58
  return "green"
46
59
  elsif (t==MOVEMENT_TYPE_ADD_BONUS)
47
- return "orange"
60
+ return "green"
48
61
  elsif (t==MOVEMENT_TYPE_REASSIGN_BALANCE)
49
62
  return "black"
50
63
  elsif (t==MOVEMENT_TYPE_REFUND_BALANCE)
@@ -54,9 +67,9 @@ module BlackStack
54
67
  elsif (t==MOVEMENT_TYPE_EXPIRATION)
55
68
  return "blue"
56
69
  elsif (t==MOVEMENT_TYPE_ADJUSTMENT)
57
- return "green"
70
+ return "orange"
58
71
  elsif (t==MOVEMENT_TYPE_REFUND_ADJUSTMENT)
59
- return "green"
72
+ return "orange"
60
73
  end
61
74
  end
62
75
 
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.46
4
+ version: 1.1.51
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-10-22 00:00:00.000000000 Z
11
+ date: 2020-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket