invoicing_payments_processing 1.1.47 → 1.1.52

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: f3f824917a87ee4d35bcc8033c4cf6697d9aaef5
4
- data.tar.gz: d07e483979caf36ea1b09a7c947dbd56eca8f8be
3
+ metadata.gz: a041204eaed01ab7a77e725d80a2097b8483304c
4
+ data.tar.gz: 8fb9df52feccc39824f57a4275541f8d40fe300f
5
5
  SHA512:
6
- metadata.gz: aca60368b308f9f06cc8b5ca4e72f257db428b709652f8112cc404a07609b7bb07e704ce02caf66b1ba29659dab19616d32e80648338d0ffa45e85400ace6777
7
- data.tar.gz: 7a281e9f26c5111adae3c82ed3424a82e2d6b8287e409ec1d2809fadb219ab58c2d888eaf0ef7925595f4167e2c283a43c8f25255986dc82ae9348c0bcbf4f46
6
+ metadata.gz: 429e8b18fcea87ba90503ce9080cce97dc26e9814ea3302fdf4aa20d5f1aa2a5839f76b20178d3e876ce2d40e994adba1f8a5b636a3bb088514d7149258a28f6
7
+ data.tar.gz: 2b1f92d1d307dba79c5db11f15a78fc99c1e457bba6b32d2fcb86db569ff20c6d5aae493753d027897b2a8babd1cf70dfa2e9178feccb89962cfb094e1f10c33
@@ -41,6 +41,10 @@ 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?
@@ -49,12 +53,24 @@ module BlackStack
49
53
  c = i.client if !i.nil?
50
54
  end
51
55
  end
56
+ if c.nil?
57
+ iid = self.invoice.split(".").last.to_s
58
+ if iid.guid?
59
+ i = BlackStack::Invoice.where(:id=>iid).first
60
+ c = i.client if !i.nil?
61
+ end
62
+ end
52
63
  if c.nil?
53
64
  cid = self.invoice.split(".").first.to_s
54
65
  if cid.guid?
55
66
  c = BlackStack::Client.where(:id=>cid).first
56
67
  end
57
68
  end
69
+ =begin
70
+ # deprecated: debe obtenerse la factura (invoice), y de ahi el cliente,
71
+ # => porque un mismo cuente puede usar su cuenta paypal en varias cuantas
72
+ # => de usuario.
73
+ #
58
74
  if c.nil?
59
75
  c = BlackStack::Client.where(:paypal_email=>self.payer_email).first
60
76
  if (c == nil)
@@ -83,6 +99,7 @@ module BlackStack
83
99
  c = BlackStack::Client.where(:id=>row[:cid]).first
84
100
  end
85
101
  end
102
+ =end
86
103
  c
87
104
  end
88
105
 
@@ -316,10 +333,12 @@ module BlackStack
316
333
  j.next(i)
317
334
 
318
335
  # creo el milestone con todo el credito pendiente que tiene esta subscripcion
336
+ =begin
337
+ # deprecated
319
338
  buff_payment = i.buffer_paypal_notification
320
339
  buff_signup = BlackStack::BufferPayPalNotification.where(:txn_type=>"subscr_signup", :subscr_id=>buff_payment.subscr_id).first
321
340
  subs = buff_signup == nil ? nil : BlackStack::PayPalSubscription.where(:id_buffer_paypal_notification => buff_signup.id).first
322
-
341
+ =end
323
342
  elsif (b.txn_type == BlackStack::BufferPayPalNotification::TXN_TYPE_SUBSCRIPTION_SIGNUP)
324
343
  # crear un registro en la tabla paypal_subscriptions
325
344
  if BlackStack::PayPalSubscription.load(b.to_hash) != nil
@@ -336,7 +355,7 @@ module BlackStack
336
355
  s.save
337
356
 
338
357
  # obtengo la factura que se creo con esta suscripcion
339
- i = BlackStack::Invoice.where(:id=>b.item_number).first
358
+ i = BlackStack::Invoice.where(:id=>b.invoice.split(".").last.to_s).first
340
359
 
341
360
  # vinculo esta suscripcion a la factura que la genero, y a todas las facturas siguientes
342
361
  i.set_subscription(s)
@@ -384,7 +403,7 @@ module BlackStack
384
403
  "SELECT TOP 1 i.id " +
385
404
  "FROM buffer_paypal_notification b " +
386
405
  "JOIN invoice i ON ( b.id=i.id_buffer_paypal_notification AND i.status=#{BlackStack::Invoice::STATUS_PAID.to_s} ) " +
387
- "WHERE b.invoice='#{b.invoice}' " +
406
+ "WHERE b.invoice='#{b.invoice.invoice.split(".").last.to_s}' " +
388
407
  "ORDER BY i.create_time DESC "
389
408
  ].first
390
409
  if row.nil?
@@ -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
@@ -42,9 +42,9 @@ module BlackStack
42
42
  elsif (t==MOVEMENT_TYPE_EXPIRATION)
43
43
  return "Expiration"
44
44
  elsif (t==MOVEMENT_TYPE_ADJUSTMENT)
45
- return "Adjustement"
45
+ return "Credit Adjustement"
46
46
  elsif (t==MOVEMENT_TYPE_REFUND_ADJUSTMENT)
47
- return "Adjustement"
47
+ return "Refund Adjustement"
48
48
  end
49
49
  '(unknown)'
50
50
  end
@@ -57,7 +57,7 @@ module BlackStack
57
57
  if (t==MOVEMENT_TYPE_ADD_PAYMENT)
58
58
  return "green"
59
59
  elsif (t==MOVEMENT_TYPE_ADD_BONUS)
60
- return "orange"
60
+ return "green"
61
61
  elsif (t==MOVEMENT_TYPE_REASSIGN_BALANCE)
62
62
  return "black"
63
63
  elsif (t==MOVEMENT_TYPE_REFUND_BALANCE)
@@ -67,9 +67,9 @@ module BlackStack
67
67
  elsif (t==MOVEMENT_TYPE_EXPIRATION)
68
68
  return "blue"
69
69
  elsif (t==MOVEMENT_TYPE_ADJUSTMENT)
70
- return "green"
70
+ return "orange"
71
71
  elsif (t==MOVEMENT_TYPE_REFUND_ADJUSTMENT)
72
- return "green"
72
+ return "orange"
73
73
  end
74
74
  end
75
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.47
4
+ version: 1.1.52
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