Class: PagSeguro::Payment

Inherits:
Object
  • Object
show all
Extended by:
ConvertFieldToDigit
Includes:
ActiveModel::Validations
Defined in:
lib/pag_seguro/payment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ConvertFieldToDigit

attr_reader_as_digit

Constructor Details

#initialize(email = nil, token = nil, options = {}) ⇒ Payment

Returns a new instance of Payment.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pag_seguro/payment.rb', line 20

def initialize(email = nil, token = nil, options = {})
  @email        = email unless email.nil?
  @token        = token unless token.nil?
  @id           = options[:id] || options[:reference]
  @sender       = options[:sender] || Sender.new
  @shipping     = options[:shipping]
  @items        = options[:items] || []
  @extra_amount = options[:extra_amount]
  @redirect_url = options[:redirect_url]
  @notification_url  = options[:notification_url]
  @max_uses     = options[:max_uses]
  @max_age      = options[:max_age]
  @pre_approval = options[:pre_approval]
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



6
7
8
# File 'lib/pag_seguro/payment.rb', line 6

def email
  @email
end

#extra_amountObject

Returns the value of attribute extra_amount.



6
7
8
# File 'lib/pag_seguro/payment.rb', line 6

def extra_amount
  @extra_amount
end

#idObject Also known as: reference

Returns the value of attribute id.



6
7
8
# File 'lib/pag_seguro/payment.rb', line 6

def id
  @id
end

#itemsObject

Returns the value of attribute items.



6
7
8
# File 'lib/pag_seguro/payment.rb', line 6

def items
  @items
end

#max_ageObject

Returns the value of attribute max_age.



6
7
8
# File 'lib/pag_seguro/payment.rb', line 6

def max_age
  @max_age
end

#max_usesObject

Returns the value of attribute max_uses.



6
7
8
# File 'lib/pag_seguro/payment.rb', line 6

def max_uses
  @max_uses
end

#notification_urlObject

Returns the value of attribute notification_url.



6
7
8
# File 'lib/pag_seguro/payment.rb', line 6

def notification_url
  @notification_url
end

#pre_approvalObject

Returns the value of attribute pre_approval.



6
7
8
# File 'lib/pag_seguro/payment.rb', line 6

def pre_approval
  @pre_approval
end

#redirect_urlObject

Returns the value of attribute redirect_url.



6
7
8
# File 'lib/pag_seguro/payment.rb', line 6

def redirect_url
  @redirect_url
end

#responseObject

Returns the value of attribute response.



6
7
8
# File 'lib/pag_seguro/payment.rb', line 6

def response
  @response
end

#senderObject

Returns the value of attribute sender.



6
7
8
# File 'lib/pag_seguro/payment.rb', line 6

def sender
  @sender
end

#shippingObject

Returns the value of attribute shipping.



6
7
8
# File 'lib/pag_seguro/payment.rb', line 6

def shipping
  @shipping
end

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/pag_seguro/payment.rb', line 6

def token
  @token
end

Class Method Details

.checkout_payment_url(code) ⇒ Object



39
40
41
# File 'lib/pag_seguro/payment.rb', line 39

def self.checkout_payment_url(code)
  PagSeguro::Url.site_url("/checkout/payment.html?code=#{code}")
end

.checkout_urlObject



35
36
37
# File 'lib/pag_seguro/payment.rb', line 35

def self.checkout_url
  PagSeguro::Url.api_url("/checkout")
end

Instance Method Details

#checkout_payment_urlObject



55
56
57
# File 'lib/pag_seguro/payment.rb', line 55

def checkout_payment_url
  self.class.checkout_payment_url(code)
end

#checkout_urlObject



59
60
61
# File 'lib/pag_seguro/payment.rb', line 59

def checkout_url
  self.class.checkout_url
end

#checkout_xmlObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/pag_seguro/payment.rb', line 43

def checkout_xml
  xml_content = File.open( File.dirname(__FILE__) + "/checkout.xml.haml" ).read
  haml_engine = Haml::Engine.new(xml_content)

  haml_engine.render Object.new,
                     items: @items,
                     payment: self,
                     sender: @sender,
                     shipping: @shipping,
                     pre_approval: @pre_approval
end

#codeObject



63
64
65
66
# File 'lib/pag_seguro/payment.rb', line 63

def code
  response || parse_checkout_response
  parse_code
end

#dateObject



68
69
70
71
# File 'lib/pag_seguro/payment.rb', line 68

def date
  response || parse_checkout_response
  parse_date
end

#reset!Object



73
74
75
# File 'lib/pag_seguro/payment.rb', line 73

def reset!
  @response = nil
end