Class: PagseguroV2::Checkout
- Inherits:
-
Hashie::Dash
- Object
- Hashie::Dash
- PagseguroV2::Checkout
- Defined in:
- lib/pagseguro_v2/checkout.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Checkout
constructor
A new instance of Checkout.
- #item=(item) ⇒ Object
- #items=(items) ⇒ Object
- #max_age ⇒ Object
- #max_uses ⇒ Object
- #proceed! ⇒ Object
- #sender=(sender) ⇒ Object
- #shipping=(shipping) ⇒ Object
- #to_hash(options = {}) ⇒ Object
- #to_xml(options = {}) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(options) ⇒ Checkout
Returns a new instance of Checkout.
32 33 34 35 36 37 38 |
# File 'lib/pagseguro_v2/checkout.rb', line 32 def initialize() self.item = [:item] if [:item] self.items = [:items] if [:items] .delete(:items) .delete(:item) super() end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
5 6 7 |
# File 'lib/pagseguro_v2/checkout.rb', line 5 def client @client end |
Class Method Details
.url(code) ⇒ Object
81 82 83 |
# File 'lib/pagseguro_v2/checkout.rb', line 81 def self.url(code) PagseguroV2::Config::REDIRECT_URL + code end |
Instance Method Details
#item=(item) ⇒ Object
46 47 48 |
# File 'lib/pagseguro_v2/checkout.rb', line 46 def item=(item) self.items = [item] end |
#items=(items) ⇒ Object
40 41 42 43 44 |
# 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 ⇒ Object
71 72 73 |
# File 'lib/pagseguro_v2/checkout.rb', line 71 def max_age self[:max_age].to_i if self[:max_age] end |
#max_uses ⇒ Object
67 68 69 |
# File 'lib/pagseguro_v2/checkout.rb', line 67 def max_uses self[:max_uses].to_i if self[:max_uses] end |
#proceed! ⇒ Object
60 61 62 63 64 65 |
# 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) ⇒ Object
50 51 52 53 |
# 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) ⇒ Object
55 56 57 58 |
# 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 = {}) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/pagseguro_v2/checkout.rb', line 85 def to_hash( = {}) sender = self.delete "sender" shipping = self.delete "shipping" items = self.delete "items" self[:sender] = sender.to_hash() unless sender.nil? self[:shipping] = shipping.to_hash() unless shipping.nil? self[:items] = items.map { |i| i.to_hash() } hash = super() self[:sender] = sender unless sender.nil? self[:shipping] = shipping unless shipping.nil? self[:items] = items return hash end |
#to_xml(options = {}) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/pagseguro_v2/checkout.rb', line 103 def to_xml(={}) 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 ⇒ Object
75 76 77 78 79 |
# File 'lib/pagseguro_v2/checkout.rb', line 75 def url url = "" url = PagseguroV2::Config::REDIRECT_URL + self.code if self.code url end |