invoicing_payments_processing 1.1.45 → 1.1.50
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bufferpaypalnotification.rb +3 -1
- data/lib/extend_client_by_invoicing_payments_processing.rb +3 -3
- data/lib/invoice.rb +69 -13
- data/lib/movement.rb +34 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1d5cea3030eeebca8abd0f7cded9898a4a08dd5
|
4
|
+
data.tar.gz: cd33004f6351894488bed5230a70f563f4056a93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e031aa9fef8a49e27578d6f8394935a99b65ba3ee7493e181390dd1351c00eab3f7688ccb11453a4de830fbae625b26ff08c1f48044f0d3190a3e669136f60bc
|
7
|
+
data.tar.gz: 60a4e90521009931f1f71123c424b696fceb3aec9bcaf7078bd9a8791b0586739c7caafcc17261421963e76ef2284d2914053b700f5dd529360e17704ff8aa00
|
@@ -316,10 +316,12 @@ module BlackStack
|
|
316
316
|
j.next(i)
|
317
317
|
|
318
318
|
# creo el milestone con todo el credito pendiente que tiene esta subscripcion
|
319
|
+
=begin
|
320
|
+
# deprecated
|
319
321
|
buff_payment = i.buffer_paypal_notification
|
320
322
|
buff_signup = BlackStack::BufferPayPalNotification.where(:txn_type=>"subscr_signup", :subscr_id=>buff_payment.subscr_id).first
|
321
323
|
subs = buff_signup == nil ? nil : BlackStack::PayPalSubscription.where(:id_buffer_paypal_notification => buff_signup.id).first
|
322
|
-
|
324
|
+
=end
|
323
325
|
elsif (b.txn_type == BlackStack::BufferPayPalNotification::TXN_TYPE_SUBSCRIPTION_SIGNUP)
|
324
326
|
# crear un registro en la tabla paypal_subscriptions
|
325
327
|
if BlackStack::PayPalSubscription.load(b.to_hash) != 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
|
data/lib/invoice.rb
CHANGED
@@ -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, "
|
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,
|
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
|
-
|
628
|
-
|
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
|
632
|
-
adjust = self.client.adjustment(u.product_code.to_s, net_amount, net_credits,
|
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,
|
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,
|
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,
|
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
|
-
|
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
|
data/lib/movement.rb
CHANGED
@@ -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"
|
@@ -28,6 +41,10 @@ module BlackStack
|
|
28
41
|
return "Consumption"
|
29
42
|
elsif (t==MOVEMENT_TYPE_EXPIRATION)
|
30
43
|
return "Expiration"
|
44
|
+
elsif (t==MOVEMENT_TYPE_ADJUSTMENT)
|
45
|
+
return "Credit Adjustement"
|
46
|
+
elsif (t==MOVEMENT_TYPE_REFUND_ADJUSTMENT)
|
47
|
+
return "Refund Adjustement"
|
31
48
|
end
|
32
49
|
'(unknown)'
|
33
50
|
end
|
@@ -36,22 +53,30 @@ module BlackStack
|
|
36
53
|
BlackStack::Movement::typeName(self.type)
|
37
54
|
end
|
38
55
|
|
39
|
-
def typeColorName()
|
40
|
-
if (
|
56
|
+
def self.typeColorName(t)
|
57
|
+
if (t==MOVEMENT_TYPE_ADD_PAYMENT)
|
41
58
|
return "green"
|
42
|
-
elsif (
|
43
|
-
return "
|
44
|
-
elsif (
|
59
|
+
elsif (t==MOVEMENT_TYPE_ADD_BONUS)
|
60
|
+
return "green"
|
61
|
+
elsif (t==MOVEMENT_TYPE_REASSIGN_BALANCE)
|
45
62
|
return "black"
|
46
|
-
elsif (
|
63
|
+
elsif (t==MOVEMENT_TYPE_REFUND_BALANCE)
|
47
64
|
return "red"
|
48
|
-
elsif (
|
65
|
+
elsif (t==MOVEMENT_TYPE_CANCELATION)
|
49
66
|
return "blue"
|
50
|
-
elsif (
|
67
|
+
elsif (t==MOVEMENT_TYPE_EXPIRATION)
|
51
68
|
return "blue"
|
69
|
+
elsif (t==MOVEMENT_TYPE_ADJUSTMENT)
|
70
|
+
return "orange"
|
71
|
+
elsif (t==MOVEMENT_TYPE_REFUND_ADJUSTMENT)
|
72
|
+
return "orange"
|
52
73
|
end
|
53
74
|
end
|
54
|
-
|
75
|
+
|
76
|
+
def typeName()
|
77
|
+
BlackStack::Movement::typeColorName(self.type)
|
78
|
+
end
|
79
|
+
|
55
80
|
# actualiza el registro con los valores del item de una factura
|
56
81
|
# type may be either MOVEMENT_TYPE_ADD_PAYMENT or MOVEMENT_TYPE_ADD_BONUS or MOVEMENT_TYPE_REFUND_BALANCE, but not other value
|
57
82
|
def parse(item, type=MOVEMENT_TYPE_ADD_PAYMENT, description='n/a', payment_time=nil, id_item=nil)
|
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.
|
4
|
+
version: 1.1.50
|
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-
|
11
|
+
date: 2020-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket
|