class PagseguroV2::Checkout
Attributes
client[RW]
Public Class Methods
new(options)
click to toggle source
Calls superclass method
# File lib/pagseguro_v2/checkout.rb, line 32 def initialize(options) self.item = options[:item] if options[:item] self.items = options[:items] if options[:items] options.delete(:items) options.delete(:item) super(options) end
url(code)
click to toggle source
# File lib/pagseguro_v2/checkout.rb, line 81 def self.url(code) PagseguroV2::Config::REDIRECT_URL + code end
Public Instance Methods
item=(item)
click to toggle source
# File lib/pagseguro_v2/checkout.rb, line 46 def item=(item) self.items = [item] end
items=(items)
click to toggle source
# File lib/pagseguro_v2/checkout.rb, line 40 def items=(items) items = items.map{ |i| Item.new(i) } if items.is_a? Array items = [Item.new(items)] if items.is_a? Hash self[:items] = items end
max_age()
click to toggle source
# File lib/pagseguro_v2/checkout.rb, line 71 def max_age self[:max_age].to_i if self[:max_age] end
max_uses()
click to toggle source
# File lib/pagseguro_v2/checkout.rb, line 67 def max_uses self[:max_uses].to_i if self[:max_uses] end
proceed!()
click to toggle source
# File lib/pagseguro_v2/checkout.rb, line 60 def proceed! response = self.client.proceed_checkout(self) # if code_blank self.code = response['checkout']['code'] self.date = response['checkout']['date'] !self.code.nil? && !self.date.nil? end
sender=(sender)
click to toggle source
# File lib/pagseguro_v2/checkout.rb, line 50 def sender=(sender) self[:sender] = Sender.new(sender) if sender.is_a? Hash self[:sender] = sender if sender.is_a? Sender end
shipping=(shipping)
click to toggle source
# File lib/pagseguro_v2/checkout.rb, line 55 def shipping=(shipping) self[:shipping] = Shipping.new(shipping) if shipping.is_a? Hash self[:shipping] = shipping if shipping.is_a? Shipping end
to_hash(options = {})
click to toggle source
Calls superclass method
# File lib/pagseguro_v2/checkout.rb, line 85 def to_hash(options = {}) sender = self.delete "sender" shipping = self.delete "shipping" items = self.delete "items" self[:sender] = sender.to_hash(options) unless sender.nil? self[:shipping] = shipping.to_hash(options) unless shipping.nil? self[:items] = items.map { |i| i.to_hash(options) } hash = super(options) self[:sender] = sender unless sender.nil? self[:shipping] = shipping unless shipping.nil? self[:items] = items return hash end
to_xml(options={})
click to toggle source
# File lib/pagseguro_v2/checkout.rb, line 103 def to_xml(options={}) builder = Builder::XmlMarkup.new( ) builder.instruct! :xml, :encoding => "UTF-8" builder.checkout do |checkout| checkout.currency currency checkout.reference reference if reference checkout.redirectURL redirect_url if redirect_url checkout.extraAmount extra_amount if extra_amount checkout.maxUses max_uses if max_uses checkout.maxAge max_age if max_age checkout.items do |items| self.items.each{ |i| i.to_xml(:builder => items) } end if self.shipping checkout.shipping self.shipping.to_xml(:builder => checkout) end if self.sender checkout.sender self.sender.to_xml(:builder => checkout) end end end
url()
click to toggle source
# File lib/pagseguro_v2/checkout.rb, line 75 def url url = "" url = PagseguroV2::Config::REDIRECT_URL + self.code if self.code url end
Private Instance Methods
convert_unit(number, unit)
click to toggle source
Todo: Melhorar
# File lib/pagseguro_v2/checkout.rb, line 131 def convert_unit(number, unit) number = (BigDecimal("#{number}") * unit).to_i unless number.nil? || number.kind_of?(Integer) number end