invoicing_payments_processing 1.1.3 → 1.1.8

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: 1420b9edf46fb1b4e92f6d43b28a2544d0dc6cb9
4
- data.tar.gz: f9280d1bae724cd557ffa4af2e156f3ff83dc2fb
3
+ metadata.gz: 151f5edd003ddd2e88cedc7222761de649a78202
4
+ data.tar.gz: 7b1345402c7424ec9c7b9dd9350c5d4a8438cdb8
5
5
  SHA512:
6
- metadata.gz: 9e8a27a63d3f7e41ee6d6609ce5eb161e97c787bf021ac79c89d3c2afabc10d0deb5331580f5776acc04064c62cdf6961ec1dd5156bed034b229f79958701f1c
7
- data.tar.gz: b31408e6e7f5a1c0ddffdc757de682f4751c9944215b9c8eac31eccba4117c3703b97e40afc9433531cd37cb01e2f30b8f52963cd0752a8fd59ef0c1de807c68
6
+ metadata.gz: 568e022a591e4272e4f6ab92928a16a901f7dc6eaf6d186ad223c4fb34a0a3f10feec25442b032f196166b0251ac78de5070435dcae34c5537990c98907a1970
7
+ data.tar.gz: f734ddee71a72789691e231d6e79aae60d5bc4aa30da2f9b2d4e93e5e5747b4ecc7ad44f0e809db9b6f5eaaec86b637440f0fc9751fd3a74421ee864624d2e54
@@ -43,13 +43,19 @@ module BlackStack
43
43
  def get_client()
44
44
  # obtengo el cliente que machea con este perfil
45
45
  c = nil
46
- if (c == nil)
46
+ if c.nil?
47
+ if self.invoice.guid?
48
+ i = BlackStack::Invoice.where(:id=>self.invoice).first
49
+ c = i.client if !i.nil?
50
+ end
51
+ end
52
+ if c.nil?
47
53
  cid = self.invoice.split(".").first.to_s
48
54
  if cid.guid?
49
55
  c = BlackStack::Client.where(:id=>cid).first
50
56
  end
51
57
  end
52
- if (c == nil)
58
+ if c.nil?
53
59
  c = BlackStack::Client.where(:paypal_email=>self.payer_email).first
54
60
  if (c == nil)
55
61
  u = User.where(:email=>self.payer_email).first
@@ -58,13 +64,13 @@ module BlackStack
58
64
  end
59
65
  end
60
66
  end
61
- if (c == nil)
67
+ if c.nil?
62
68
  s = BlackStack::PayPalSubscription.where(:payer_email=>self.payer_email).first
63
69
  if (s!=nil)
64
70
  c = s.client
65
71
  end
66
72
  end
67
- if (c == nil)
73
+ if c.nil?
68
74
  # obtengo el cliente - poco elegante
69
75
  q =
70
76
  "SELECT TOP 1 i.id_client AS cid " +
@@ -363,6 +369,19 @@ module BlackStack
363
369
  raise 'Invoice already exists.'
364
370
  end
365
371
 
372
+ # obtengo la ultima factura pagada, vinculada a un IPN con el mismo codigo invoice
373
+ row = DB[
374
+ "SELECT TOP 1 i.id " +
375
+ "FROM buffer_paypal_notification b " +
376
+ "JOIN invoice i ON ( b.id=i.id_buffer_paypal_notification AND i.status=#{BlackStack::Invoice::STATUS_PAID.to_s} ) " +
377
+ "WHERE b.invoice='#{b.invoice}' " +
378
+ "ORDER BY i.create_time DESC "
379
+ ].first
380
+ if row.nil?
381
+ raise 'Previous Paid Invoice not found.'
382
+ end
383
+ k = BlackStack::Invoice.where(:id=>row[:id]).first
384
+
366
385
  # creo la factura por el reembolso
367
386
  i = BlackStack::Invoice.new()
368
387
  i.id = guid()
@@ -378,7 +397,7 @@ module BlackStack
378
397
  i.save()
379
398
 
380
399
  # parseo el reeembolso - creo el registro contable
381
- i.setup_refund(payment_gross, iid)
400
+ i.setup_refund(payment_gross, k.id)
382
401
 
383
402
  end
384
403
  else
@@ -99,17 +99,16 @@ module BlackStack
99
99
  end
100
100
 
101
101
  # calculo cuantos creditos tiene este cliente
102
- x = 0.to_f - BlackStack::Balance.new(m.client.id, p[:code]).credits.to_f
102
+ #x = 0.to_f - BlackStack::Balance.new(m.client.id, p[:code]).credits.to_f
103
+ # calculo los creditos de este movimiento que voy a cancelar
104
+ x = 0.to_f - m.credits.to_f
103
105
 
104
- # calculo el credito adquirido luego de este movimiento que voy a cancelar
106
+ # calculo el credito consumido luego de este movimiento que voy a cancelar
105
107
  y = m.client.movements.select { |o|
106
- (
107
- o.type == BlackStack::Movement::MOVEMENT_TYPE_ADD_PAYMENT ||
108
- o.type == BlackStack::Movement::MOVEMENT_TYPE_ADD_BONUS
109
- ) &&
108
+ o.credits.to_f > 0 &&
110
109
  o.product_code.upcase == p[:code].upcase &&
111
110
  o.create_time > m.create_time
112
- }.inject(0) { |sum, o| sum.to_f + (0.to_f - o.credits.to_f) }.to_f
111
+ }.inject(0) { |sum, o| sum.to_f + o.credits.to_f }.to_f
113
112
 
114
113
  # calculo el # de creditos no usados de este movimiento que ha expirado
115
114
  z = x-y>0 ? x-y : 0
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.3
4
+ version: 1.1.8
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-02-06 00:00:00.000000000 Z
11
+ date: 2020-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket