invoicing_payments_processing 1.1.20 → 1.1.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bufferpaypalnotification.rb +7 -16
- data/lib/extend_client_by_invoicing_payments_processing.rb +58 -6
- data/lib/invoice.rb +57 -33
- data/lib/invoiceitem.rb +10 -0
- data/lib/paypalsubscription.rb +1 -1
- 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: 5d97ab4f8d1bbf4504ea494d1f4f0654c6dedac5
|
4
|
+
data.tar.gz: d2aa430675b74c58792d858b9446b961152a31dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a19f653d1435378092a77cb576f8f92b21cf5f5fe68e03b349f16ae547ff93efe379de7d7cd4bd1509b3717cbe9d3d26a4cedba96b5a9e2e81fb1a671bb8f47f
|
7
|
+
data.tar.gz: 9e6823c86dc08d36a8f629fd18eb605a105df7e8ad87603c40c6a199c448ca872daaa2725656376d0c594246af1872e95e21726f6620fbfaec4a5a029d1f8a49
|
@@ -331,6 +331,12 @@ module BlackStack
|
|
331
331
|
s.id_client = c.id
|
332
332
|
s.active = true
|
333
333
|
s.save
|
334
|
+
|
335
|
+
# obtengo la factura que se creo con esta suscripcion
|
336
|
+
i = BlackStack::Invoice.where(:id=>b.item_number).first
|
337
|
+
|
338
|
+
# vinculo esta suscripcion a la factura que la genero, y a todas las facturas siguientes
|
339
|
+
i.set_subscription(s)
|
334
340
|
end
|
335
341
|
|
336
342
|
elsif (
|
@@ -384,22 +390,7 @@ module BlackStack
|
|
384
390
|
k = BlackStack::Invoice.where(:id=>row[:id]).first
|
385
391
|
|
386
392
|
# creo la factura por el reembolso
|
387
|
-
|
388
|
-
i.id = guid()
|
389
|
-
i.id_client = c.id
|
390
|
-
i.create_time = now()
|
391
|
-
i.disabled_for_trial_ssm = c.disabled_for_trial_ssm
|
392
|
-
i.id_buffer_paypal_notification = b.id
|
393
|
-
i.status = BlackStack::Invoice::STATUS_REFUNDED
|
394
|
-
i.billing_period_from = b.create_time
|
395
|
-
i.billing_period_to = b.create_time
|
396
|
-
i.paypal_url = nil
|
397
|
-
i.disabled_for_add_remove_items = true
|
398
|
-
i.save()
|
399
|
-
|
400
|
-
# parseo el reeembolso - creo el registro contable
|
401
|
-
i.setup_refund(payment_gross, k.id)
|
402
|
-
|
393
|
+
k.refund(payment_gross)
|
403
394
|
end
|
404
395
|
else
|
405
396
|
# unknown
|
@@ -162,13 +162,65 @@ module BlackStack
|
|
162
162
|
if from_time > to_time
|
163
163
|
raise "From time must be earlier than To time"
|
164
164
|
end
|
165
|
-
if to_time.prev_year > from_time
|
166
|
-
|
167
|
-
end
|
165
|
+
#if to_time.prev_year > from_time
|
166
|
+
# raise "The time frame cannot be longer than 1 year."
|
167
|
+
#end
|
168
168
|
to_time += 1
|
169
|
-
|
170
|
-
|
171
|
-
|
169
|
+
=begin
|
170
|
+
:id => movement.id,
|
171
|
+
:id_client => movement.id_client,
|
172
|
+
:product_code => movement.product_code,
|
173
|
+
:create_time => movement.create_time,
|
174
|
+
:type => movement.type.to_i,
|
175
|
+
:description => movement.description,
|
176
|
+
:paypal1_amount => movement.paypal1_amount.to_f,
|
177
|
+
:bonus_amount => movement.bonus_amount.to_f,
|
178
|
+
:amount => movement.amount.to_f,
|
179
|
+
:credits => movement.credits.to_f,
|
180
|
+
:profits_amount => movement.profits_amount.to_f,
|
181
|
+
:expiration_time => movement.expiration_time,
|
182
|
+
:expiration_description => movement.expiration_time.nil? ? '-' : ((movement.expiration_time - Time.now()).to_f / 60.to_f).to_i.to_time_spent
|
183
|
+
=end
|
184
|
+
q =
|
185
|
+
"SELECT " +
|
186
|
+
" m.id_client, " +
|
187
|
+
" YEAR(m.create_time) AS creation_year, " +
|
188
|
+
" MONTH(m.create_time) AS creation_month, " +
|
189
|
+
" DAY(m.create_time) AS creation_day, " +
|
190
|
+
" YEAR(m.expiration_time) AS expiration_year, " +
|
191
|
+
" MONTH(m.expiration_time) AS expiration_month, " +
|
192
|
+
" DAY(m.expiration_time) AS expiration_day, " +
|
193
|
+
" m.type, " +
|
194
|
+
" m.product_code, " +
|
195
|
+
" CAST(m.description AS VARCHAR(500)) AS description, " +
|
196
|
+
" CAST(m.expiration_description AS VARCHAR(500)) AS expiration_description, " +
|
197
|
+
" SUM(ISNULL(m.paypal1_amount,0)) AS paypal1_amount, " +
|
198
|
+
" SUM(ISNULL(m.bonus_amount,0)) AS bonus_amount, " +
|
199
|
+
" SUM(ISNULL(m.amount,0)) AS amount, " +
|
200
|
+
" SUM(ISNULL(m.credits,0)) AS credits, " +
|
201
|
+
" SUM(ISNULL(m.profits_amount,0)) AS profits_amount " +
|
202
|
+
"FROM movement m WITH (NOLOCK) " +
|
203
|
+
"WHERE m.id_client = '#{self.id}' "
|
204
|
+
|
205
|
+
q += "AND m.product_code = '#{product_code}' " if !product_code.nil?
|
206
|
+
|
207
|
+
q +=
|
208
|
+
"AND create_time >= '#{from_time.to_sql}' " +
|
209
|
+
"AND create_time <= '#{to_time.to_sql}' " +
|
210
|
+
"GROUP BY " +
|
211
|
+
" m.id_client, " +
|
212
|
+
" YEAR(m.create_time), " +
|
213
|
+
" MONTH(m.create_time), " +
|
214
|
+
" DAY(m.create_time), " +
|
215
|
+
" YEAR(m.expiration_time), " +
|
216
|
+
" MONTH(m.expiration_time), " +
|
217
|
+
" DAY(m.expiration_time), " +
|
218
|
+
" m.type, " +
|
219
|
+
" m.product_code, " +
|
220
|
+
" CAST(m.description AS VARCHAR(500)), " +
|
221
|
+
" CAST(m.expiration_description AS VARCHAR(500)) "
|
222
|
+
|
223
|
+
DB[q].all
|
172
224
|
end
|
173
225
|
|
174
226
|
#
|
data/lib/invoice.rb
CHANGED
@@ -56,7 +56,19 @@ module BlackStack
|
|
56
56
|
raise "Unknown Invoice Status (#{status.to_s})"
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
|
+
#
|
61
|
+
def set_subscription(s)
|
62
|
+
self.subscr_id = s.subscr_id
|
63
|
+
self.save
|
64
|
+
# aplico la mismam modificacion a todas las factuas que le siguieron a esta
|
65
|
+
BlackStack::Invoice.where(:id_previous_invoice=>self.id).all { |j|
|
66
|
+
j.set_subscription(s)
|
67
|
+
DB.disconnect
|
68
|
+
GC.start
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
60
72
|
#
|
61
73
|
def deserve_trial?
|
62
74
|
return self.disabled_for_trial_ssm == false || self.disabled_for_trial_ssm == nil
|
@@ -321,7 +333,7 @@ module BlackStack
|
|
321
333
|
bonus.id_invoice = self.id
|
322
334
|
bonus.product_code = plan_bonus[:product_code]
|
323
335
|
bonus.unit_price = 0
|
324
|
-
bonus.units = plan_bonus[:credits]
|
336
|
+
bonus.units = plan_bonus[:credits] * item.number_of_packages # agrego los creditos del bono, multiplicado por la cantiad de paquetes
|
325
337
|
bonus.amount = 0
|
326
338
|
bonus.item_number = plan_bonus[:item_number]
|
327
339
|
BlackStack::Movement.new().parse(bonus, BlackStack::Movement::MOVEMENT_TYPE_ADD_BONUS, 'Payment Bonus', payment_time, item.id).save()
|
@@ -371,62 +383,51 @@ module BlackStack
|
|
371
383
|
end
|
372
384
|
end
|
373
385
|
end
|
374
|
-
|
386
|
+
|
375
387
|
# configura la factura, segun el importe que pagara el cliente, la configuracion del plan en el descriptor h, y si el clietne merece un trial o no
|
376
|
-
def create_item(item_number, n=1, validate_items_compatibility=true)
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
# busco el primer item de esta factura, si es que existe
|
381
|
-
item0 = self.items.sort_by {|obj| obj.create_time}.first
|
382
|
-
|
383
|
-
# numero de facturas previas a esta factura
|
384
|
-
subs = BlackStack::PayPalSubscription.where(:subscr_id=>self.subscr_id).first
|
385
|
-
nSubscriptionInvoices = 0 if subs.nil?
|
386
|
-
nSubscriptionInvoices = subs.invoices.count if !subs.nil?
|
387
|
-
|
388
|
+
def create_item(item_number, n=1, validate_items_compatibility=true)
|
389
|
+
prev1 = self.previous
|
390
|
+
prev2 = prev1.nil? ? nil : prev1.previous
|
391
|
+
|
388
392
|
# encuentro el descriptor del plan
|
389
393
|
# el descriptor del plan tambien es necesario para la llamada a paypal_link
|
390
394
|
h = self.client.plans.select { |j| j[:item_number].to_s == item_number.to_s }.first
|
391
395
|
|
392
396
|
# mapeo variables
|
393
|
-
c = self.client
|
394
397
|
amount = 0.to_f
|
395
398
|
unit_price = 0.to_f
|
396
399
|
units = 0.to_i
|
397
|
-
|
398
|
-
# decido si se trata de una suscripcion
|
399
|
-
isSubscription = false
|
400
|
-
isSubscription = true if h[:type] == "S"
|
401
|
-
|
400
|
+
|
402
401
|
# le seteo la fecha de hoy
|
403
402
|
self.billing_period_from = now()
|
404
403
|
|
405
|
-
# si es una suscripcion, y
|
406
404
|
# si el plan tiene un primer trial, y
|
407
|
-
# es primer
|
408
|
-
# => se trata del primer pago por trial
|
409
|
-
if
|
405
|
+
# es la primer factura, entonces:
|
406
|
+
# => se trata del primer pago por trial
|
407
|
+
if h[:trial_fee] != nil && prev1.nil?
|
408
|
+
#puts 'a'
|
410
409
|
units = h[:trial_credits].to_i
|
411
410
|
unit_price = h[:trial_fee].to_f / h[:trial_credits].to_f
|
412
411
|
billing_period_to = DB["SELECT DATEADD(#{h[:trial_period].to_s}, +#{h[:trial_units].to_s}, '#{self.billing_period_from.to_s}') AS [now]"].map(:now)[0].to_s
|
413
412
|
|
414
|
-
# si es una suscripcion, y
|
415
413
|
# si el plan tiene un segundo trial, y
|
416
|
-
# es
|
417
|
-
# => se trata del segundo pago por trial
|
418
|
-
elsif
|
414
|
+
# es la segunda factura, entonces:
|
415
|
+
# => se trata del segundo pago por segundo trial
|
416
|
+
elsif h[:trial2_fee] != nil && !prev1.nil? && prev2.nil?
|
417
|
+
#puts 'b'
|
419
418
|
units = h[:trial2_credits].to_i
|
420
419
|
unit_price = h[:trial2_fee].to_f / h[:trial2_credits].to_f
|
421
420
|
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
|
422
421
|
|
423
422
|
# si el plan tiene un fee, y
|
424
|
-
elsif
|
423
|
+
elsif h[:fee].to_f != nil && !prev1.nil? && !prev2.nil?
|
424
|
+
#puts 'c'
|
425
425
|
units = n.to_i * h[:credits].to_i
|
426
426
|
unit_price = h[:fee].to_f / h[:credits].to_f
|
427
427
|
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
428
|
|
429
429
|
elsif (!isSubscription && h[:fee].to_f != nil)
|
430
|
+
#puts 'd'
|
430
431
|
units = n.to_i * h[:credits].to_i
|
431
432
|
unit_price = h[:fee].to_f / h[:credits].to_f
|
432
433
|
billing_period_to = billing_period_from
|
@@ -435,7 +436,8 @@ module BlackStack
|
|
435
436
|
raise "Plan is specified wrong"
|
436
437
|
|
437
438
|
end
|
438
|
-
|
439
|
+
|
440
|
+
|
439
441
|
#
|
440
442
|
amount = units.to_f * unit_price.to_f
|
441
443
|
|
@@ -523,7 +525,7 @@ module BlackStack
|
|
523
525
|
self.disabled_for_add_remove_items = true
|
524
526
|
|
525
527
|
i.items.each { |t|
|
526
|
-
self.add_item(t.item_number)
|
528
|
+
self.add_item(t.item_number, t.number_of_packages)
|
527
529
|
#
|
528
530
|
DB.disconnect
|
529
531
|
GC.start
|
@@ -657,6 +659,28 @@ module BlackStack
|
|
657
659
|
DB.disconnect
|
658
660
|
GC.start
|
659
661
|
end # def setup_refund
|
660
|
-
|
662
|
+
|
663
|
+
def refund(amount)
|
664
|
+
c = self.client
|
665
|
+
# creo la factura por el reembolso
|
666
|
+
j = BlackStack::Invoice.new()
|
667
|
+
j.id = guid()
|
668
|
+
j.id_client = c.id
|
669
|
+
j.create_time = now()
|
670
|
+
j.disabled_for_trial_ssm = c.disabled_for_trial_ssm
|
671
|
+
j.id_buffer_paypal_notification = nil
|
672
|
+
j.status = BlackStack::Invoice::STATUS_REFUNDED
|
673
|
+
j.billing_period_from = self.billing_period_from
|
674
|
+
j.billing_period_to = self.billing_period_to
|
675
|
+
j.paypal_url = nil
|
676
|
+
j.disabled_for_add_remove_items = true
|
677
|
+
j.subscr_id = self.subscr_id
|
678
|
+
j.id_previous_invoice = self.id
|
679
|
+
j.save()
|
680
|
+
|
681
|
+
# parseo el reeembolso - creo el registro contable
|
682
|
+
j.setup_refund(amount, self.id)
|
683
|
+
end # refund
|
684
|
+
|
661
685
|
end # class Invoice
|
662
686
|
end # module BlackStack
|
data/lib/invoiceitem.rb
CHANGED
@@ -7,5 +7,15 @@ module BlackStack
|
|
7
7
|
BlackStack::InvoicingPaymentsProcessing::plan_descriptor(self.item_number)
|
8
8
|
end
|
9
9
|
|
10
|
+
# Returns the number of plans ordered in this item
|
11
|
+
def number_of_packages()
|
12
|
+
plan = BlackStack::InvoicingPaymentsProcessing.plan_descriptor(self.item_number)
|
13
|
+
if self.amount.to_f == plan[:trial_fee].to_f || self.amount.to_f == plan[:trial2_fee].to_f
|
14
|
+
return 1.to_i
|
15
|
+
else
|
16
|
+
return (self.units.to_f / plan[:credits].to_f).to_i
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
10
20
|
end # class LocalInvoiceItem
|
11
21
|
end # module BlackStack
|
data/lib/paypalsubscription.rb
CHANGED
@@ -116,7 +116,7 @@ module BlackStack
|
|
116
116
|
DB[
|
117
117
|
"SELECT DISTINCT i.id " +
|
118
118
|
"FROM invoice i WITH (NOLOCK) " +
|
119
|
-
"
|
119
|
+
"WHERE i.subscr_id='#{self.subscr_id.to_s}' "
|
120
120
|
].all { |row|
|
121
121
|
a << BlackStack::Invoice.where(:id=>row[:id]).first
|
122
122
|
# 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.
|
4
|
+
version: 1.1.27
|
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-
|
11
|
+
date: 2020-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket
|