Class: BlackStack::PayPalSubscription

Inherits:
Object
  • Object
show all
Defined in:
lib/paypalsubscription.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(params) ⇒ Object

crea un nuevo objeto BufferPayPalNotification, y le mapea los atributos en el hash params. no guarda el objeto en la base de datos. retorna el objeto creado.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/paypalsubscription.rb', line 22

def self.create(params)
    s = BlackStack::PayPalSubscription.new()
    s.subscr_id = params['subscr_id'].to_s
    s.last_name = params['last_name'].to_s
    s.residence_country = params['residence_country'].to_s
    s.mc_currency = params['mc_currency'].to_s
    #s.item_name = params['item_name'].to_s
    s.amount1 = params['amount1'].to_s
    s.business = params['business'].to_s
    s.amount3 = params['amount3'].to_s
    s.recurring = params['recurring'].to_s
    s.verify_sign = params['verify_sign'].to_s
    s.payer_status = params['payer_status'].to_s
    s.test_ipn = params['test_ipn'].to_s
    s.payer_email = params['payer_email'].to_s
    s.first_name = params['first_name'].to_s
    s.receiver_email = params['receiver_email'].to_s
    s.payer_id = params['payer_id'].to_s
    s.invoice = params['invoice'].to_s
    s.reattempt = params['reattempt'].to_s
    #s.item_number = params['item_number'].to_s
    s.subscr_date = params['subscr_date'].to_s
    s.charset = params['charset'].to_s
    s.notify_version = params['notify_version'].to_s
    s.period1 = params['period1'].to_s
    s.mc_amount1 = params['mc_amount1'].to_s
    s.period3 = params['period3'].to_s
    s.mc_amount3 = params['mc_amount3'].to_s
    s.ipn_track_id = params['ipn_track_id'].to_s
    s
end

.load(params) ⇒ Object

retorna true si existe un registro en :payPal_subscription con el mismo valor subscr_id. sin retorna false.



15
16
17
# File 'lib/paypalsubscription.rb', line 15

def self.load(params)
  BlackStack::PayPalSubscription.where(:subscr_id=>params['subscr_id']).first
end

Instance Method Details

#assignedObjectObject

TODO: deprecated Retorna el objeto vinculado a esta suscripcion



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/paypalsubscription.rb', line 100

def assignedObject()
  if (self.item_number =~ /^#{PRODUCT_SSM}\./)
    return self.pipeline
  elsif (self.item_number =~ /^#{PRODUCT_FLD}\./)
    return self.crmlist
  elsif (self.item_number =~ /^#{PRODUCT_IPJ}\./)
    return self.lngroup
  else # unknown
    return nil
  end
end

#invoicesObject

retorna un array con facturas de esta suscripcion



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/paypalsubscription.rb', line 113

def invoices()
  a = []
  if self.subscr_id.to_s.size > 0
    DB[
    "SELECT DISTINCT i.id " +
    "FROM invoice i WITH (NOLOCK) " + 
    "WHERE i.subscr_id='#{self.subscr_id.to_s}' "
    ].all { |row|
      a << BlackStack::Invoice.where(:id=>row[:id]).first
      # release resources 
      DB.disconnect
      GC.start
    }      
  end
  a
end

#to_hashObject

retorna un hash descriptor de este objecto



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/paypalsubscription.rb', line 55

def to_hash()
  ret = {}
  # campos de uso interno
  ret['id'] = self.id 
  ret['create_time'] = self.create_time.datetime_sql_to_api 
  ret['id_client'] = self.id_client 
  ret['id_buffer_paypal_notification'] = self.id_buffer_paypal_notification 
  ret['active'] = self.active 
  # vinculacion a objetos
  ret['id_pipeline'] = self.id_pipeline 
  ret['id_lngroup'] = self.id_lngroup 
  ret['id_crmlist'] = self.id_crmlist
  # campos replicados del ipn
  ret['subscr_id'] = self.subscr_id 
  ret['last_name'] = self.last_name 
  ret['residence_country'] = self.residence_country 
  ret['mc_currency'] = self.mc_currency
  #ret['item_name'] = self.item_name
  ret['amount1'] = self.amount1
  ret['business'] = self.business 
  ret['amount3'] = self.amount3 
  ret['recurring'] = self.recurring 
  ret['verify_sign'] = self.verify_sign 
  ret['payer_status'] = self.payer_status 
  ret['test_ipn'] = self.test_ipn
  ret['payer_email'] = self.payer_email 
  ret['first_name'] = self.first_name 
  ret['receiver_email'] = self.receiver_email 
  ret['payer_id'] = self.payer_id
  ret['invoice'] = self.invoice 
  ret['reattempt'] = self.reattempt 
  #ret['item_number'] = self.item_number 
  ret['subscr_date'] = self.subscr_date 
  ret['charset'] = self.charset
  ret['notify_version'] = self.notify_version 
  ret['period1'] = self.period1
  ret['mc_amount1'] = self.mc_amount1 
  ret['period3'] = self.period3
  ret['mc_amount3'] = self.mc_amount3 
  ret['ipn_track_id'] = self.ipn_track_id 
  ret
end