invoicing_payments_processing 1.1.49 → 1.1.54

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: b54f5254b078b2e18fe430630b15c7d9502fdf72
4
- data.tar.gz: d593f97003a360802f912eb1299229ba267430c3
3
+ metadata.gz: ed522b59c5d199f4304b6f8f0a67d53402653d0e
4
+ data.tar.gz: b0e657864ba63e02298a5b867ca7b01c2093c721
5
5
  SHA512:
6
- metadata.gz: f24b1584bcf525b37792d216078f7668bc42aa47ca5cb0e9b65f06d152c60a4e0bcec376933f2f420dab27d55992e8823ac9bebf65e8f230e49e81c59562265e
7
- data.tar.gz: 635caf0ccb9cdec3b0a3552020c90940a01f99f9fdc8c7e16330e2f9846fe7dd54a41e12ad96a4963f5cde17ba31046fc309acf46267f6d1bcc000a3e8a41a0e
6
+ metadata.gz: 1de7badcf5dc5d5f8065564b57369417a8510086de4f16904cfdd886f83d33ffdc59f26574adf0b352cec4f7b0d402bd46f716a6523799be81df2a9294e9e4f5
7
+ data.tar.gz: da28758cc4d633a73fb9abf63cfe743a3f5dc4da7c0a633a2831e3c6f433d7ee1df225f70487afe23a0cfc7ecdee10dd475884d1cd8b1c86416287804384212d
@@ -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)
@@ -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
@@ -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
+ # hago el reembolso de este item
628
+ # si el balance quedo en negativo, entonces aplico otro ajuste
627
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()
628
- # si el balance quedo en negativo, entonces aplico otro ajuste
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
+ if net_amount <= 0 && net_credits < 0
632
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
@@ -675,9 +701,39 @@ module BlackStack
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
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.49
4
+ version: 1.1.54
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-25 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