Class: PagseguroClient::Transaction
- Inherits:
-
Object
- Object
- PagseguroClient::Transaction
- Defined in:
- lib/pagseguro_client/transaction.rb
Direct Known Subclasses
Constant Summary collapse
- PAYMENT_METHOD =
{ 1 => :credit_card, 2 => :invoice, 3 => :online_transfer, 4 => :pagseguro, 5 => :oi_paggo }
- STATUS =
{ 1 => :pending, 2 => :verifying, 3 => :approved, 4 => :available, 6 => :refunded, 7 => :canceled }
- SHIPPING_TYPE =
{ 1 => :pac, 2 => :sedex }
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#code ⇒ Object
Returns the value of attribute code.
-
#last_event_date ⇒ Object
Returns the value of attribute last_event_date.
-
#order_id ⇒ Object
Returns the value of attribute order_id.
-
#payment_method ⇒ Object
Returns the value of attribute payment_method.
-
#sender ⇒ Object
Returns the value of attribute sender.
-
#shipping ⇒ Object
Returns the value of attribute shipping.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Transaction
constructor
A new instance of Transaction.
Constructor Details
#initialize(attributes = {}) ⇒ Transaction
Returns a new instance of Transaction.
28 29 30 31 32 |
# File 'lib/pagseguro_client/transaction.rb', line 28 def initialize(attributes = {}) attributes.each do |name, value| send("#{name}=", value) end end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
26 27 28 |
# File 'lib/pagseguro_client/transaction.rb', line 26 def address @address end |
#code ⇒ Object
Returns the value of attribute code.
26 27 28 |
# File 'lib/pagseguro_client/transaction.rb', line 26 def code @code end |
#last_event_date ⇒ Object
Returns the value of attribute last_event_date.
26 27 28 |
# File 'lib/pagseguro_client/transaction.rb', line 26 def last_event_date @last_event_date end |
#order_id ⇒ Object
Returns the value of attribute order_id.
26 27 28 |
# File 'lib/pagseguro_client/transaction.rb', line 26 def order_id @order_id end |
#payment_method ⇒ Object
Returns the value of attribute payment_method.
26 27 28 |
# File 'lib/pagseguro_client/transaction.rb', line 26 def payment_method @payment_method end |
#sender ⇒ Object
Returns the value of attribute sender.
26 27 28 |
# File 'lib/pagseguro_client/transaction.rb', line 26 def sender @sender end |
#shipping ⇒ Object
Returns the value of attribute shipping.
26 27 28 |
# File 'lib/pagseguro_client/transaction.rb', line 26 def shipping @shipping end |
#status ⇒ Object
Returns the value of attribute status.
26 27 28 |
# File 'lib/pagseguro_client/transaction.rb', line 26 def status @status end |
Class Method Details
.create_by_xml(xml) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/pagseguro_client/transaction.rb', line 34 def self.create_by_xml(xml) doc = Nokogiri::XML(xml) code = doc.xpath("//transaction/code").text order_id = doc.xpath("//reference").text status = doc.xpath("//status").text.to_i payment_method = doc.xpath("//paymentMethod/type").text.to_i last_event_date = doc.xpath("//transaction/lastEventDate").text email = doc.xpath("//transaction/sender/email").text name = doc.xpath("//transaction/sender/name").text phone = { area_code: doc.xpath("//transaction/sender/phone/areaCode").text, number: doc.xpath("//transaction/sender/phone/number").text } address = { country: doc.xpath("//transaction/shipping/address/country").text, state: doc.xpath("//transaction/shipping/address/state").text, city: doc.xpath("//transaction/shipping/address/city").text, postal_code: doc.xpath("//transaction/shipping/address/postalCode").text, district: doc.xpath("//transaction/shipping/address/district").text, street: doc.xpath("//transaction/shipping/address/street").text, number: doc.xpath("//transaction/shipping/address/number").text, complement: doc.xpath("//transaction/shipping/address/complement").text } shipping = { type: SHIPPING_TYPE[doc.xpath("//transaction/shipping/type").text.to_i], cost: doc.xpath("//transaction/shipping/cost").text.to_f } transaction = Transaction.new( code: code, order_id: order_id, status: STATUS[status], payment_method: PAYMENT_METHOD[payment_method], sender: { name: name, email: email, phone: phone }, address: address, last_event_date: last_event_date, shipping: shipping ) end |
.retrieve(code) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pagseguro_client/transaction.rb', line 84 def self.retrieve(code) response = RestClient.get(url(code), { params: { email: PagseguroClient.email, token: PagseguroClient.token } } ) create_by_xml(response.body) end |
.url(code) ⇒ Object
80 81 82 |
# File 'lib/pagseguro_client/transaction.rb', line 80 def self.url(code) PagseguroClient.transaction_url(code) end |