Class: PagSeguro::Transaction
- Inherits:
-
Object
- Object
- PagSeguro::Transaction
- Defined in:
- lib/pag_seguro/transaction.rb
Direct Known Subclasses
Constant Summary collapse
- PAGSEGURO_TRANSACTIONS_URL =
"https://ws.pagseguro.uol.com.br/v2/transactions"
- PAGSEGURO_PROCESSING =
possible status values
1
- PAGSEGURO_IN_ANALYSIS =
2
- PAGSEGURO_APPROVED =
3
- PAGSEGURO_AVAILABLE =
4
- PAGSEGURO_DISPUTED =
5
- PAGSEGURO_RETURNED =
6
- PAGSEGURO_CANCELLED =
7
- PAGSEGURO_PAYMENT =
possible type values
1
- PAGSEGURO_TRANSFER =
2
- PAGSEGURO_ADDITION_OF_FUNDS =
3
- PAGSEGURO_CHARGE =
4
- PAGSEGURO_BONUS =
5
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #addition_of_funds? ⇒ Boolean
- #approved? ⇒ Boolean
- #available? ⇒ Boolean
- #bonus? ⇒ Boolean
- #cancelled? ⇒ Boolean
- #charge? ⇒ Boolean
- #date ⇒ Object
- #discount_amount ⇒ Object
- #disputed? ⇒ Boolean
- #extra_amount ⇒ Object
- #fee_amount ⇒ Object
- #gross_amount ⇒ Object
- #id ⇒ Object
- #in_analysis? ⇒ Boolean
-
#initialize(transaction_xml) ⇒ Transaction
constructor
A new instance of Transaction.
- #installment_count ⇒ Object
- #item_count ⇒ Object
- #items ⇒ Object
- #net_amount ⇒ Object
- #payment? ⇒ Boolean
- #payment_method ⇒ Object
- #processing? ⇒ Boolean
- #returned? ⇒ Boolean
- #sender ⇒ Object
- #shipping ⇒ Object
- #status ⇒ Object
- #transaction_id ⇒ Object
- #transfer? ⇒ Boolean
- #type ⇒ Object
Constructor Details
#initialize(transaction_xml) ⇒ Transaction
Returns a new instance of Transaction.
26 27 28 |
# File 'lib/pag_seguro/transaction.rb', line 26 def initialize(transaction_xml) @data = transaction_data(transaction_xml) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/pag_seguro/transaction.rb', line 6 def data @data end |
Instance Method Details
#addition_of_funds? ⇒ Boolean
147 148 149 |
# File 'lib/pag_seguro/transaction.rb', line 147 def addition_of_funds? PAGSEGURO_ADDITION_OF_FUNDS == type end |
#approved? ⇒ Boolean
119 120 121 |
# File 'lib/pag_seguro/transaction.rb', line 119 def approved? PAGSEGURO_APPROVED == status end |
#available? ⇒ Boolean
123 124 125 |
# File 'lib/pag_seguro/transaction.rb', line 123 def available? PAGSEGURO_AVAILABLE == status end |
#bonus? ⇒ Boolean
155 156 157 |
# File 'lib/pag_seguro/transaction.rb', line 155 def bonus? PAGSEGURO_BONUS == type end |
#cancelled? ⇒ Boolean
135 136 137 |
# File 'lib/pag_seguro/transaction.rb', line 135 def cancelled? PAGSEGURO_CANCELLED == status end |
#charge? ⇒ Boolean
151 152 153 |
# File 'lib/pag_seguro/transaction.rb', line 151 def charge? PAGSEGURO_CHARGE == type end |
#date ⇒ Object
66 67 68 |
# File 'lib/pag_seguro/transaction.rb', line 66 def date DateTime.iso8601( @data.css("date").first.content ) end |
#discount_amount ⇒ Object
38 39 40 |
# File 'lib/pag_seguro/transaction.rb', line 38 def discount_amount @data.css("discountAmount").first.content end |
#disputed? ⇒ Boolean
127 128 129 |
# File 'lib/pag_seguro/transaction.rb', line 127 def disputed? PAGSEGURO_DISPUTED == status end |
#extra_amount ⇒ Object
50 51 52 |
# File 'lib/pag_seguro/transaction.rb', line 50 def extra_amount @data.css("feeAmount").first.content end |
#fee_amount ⇒ Object
42 43 44 |
# File 'lib/pag_seguro/transaction.rb', line 42 def fee_amount @data.css("feeAmount").first.content end |
#gross_amount ⇒ Object
34 35 36 |
# File 'lib/pag_seguro/transaction.rb', line 34 def gross_amount @data.css("grossAmount").first.content end |
#id ⇒ Object
30 31 32 |
# File 'lib/pag_seguro/transaction.rb', line 30 def id @data.css("reference").first.content end |
#in_analysis? ⇒ Boolean
115 116 117 |
# File 'lib/pag_seguro/transaction.rb', line 115 def in_analysis? PAGSEGURO_IN_ANALYSIS == status end |
#installment_count ⇒ Object
54 55 56 |
# File 'lib/pag_seguro/transaction.rb', line 54 def installment_count @data.css("itemCount").first.content.to_i end |
#item_count ⇒ Object
58 59 60 |
# File 'lib/pag_seguro/transaction.rb', line 58 def item_count @data.css("itemCount").first.content.to_i end |
#items ⇒ Object
70 71 72 73 74 |
# File 'lib/pag_seguro/transaction.rb', line 70 def items @data.css("items item").map do |i| Item.new(id: parse_item(i, "id"), description: parse_item(i, "description"), quantity: parse_item(i, "quantity"), amount: parse_item(i, "amount")) end end |
#net_amount ⇒ Object
46 47 48 |
# File 'lib/pag_seguro/transaction.rb', line 46 def net_amount @data.css("feeAmount").first.content end |
#payment? ⇒ Boolean
139 140 141 |
# File 'lib/pag_seguro/transaction.rb', line 139 def payment? PAGSEGURO_PAYMENT == type end |
#payment_method ⇒ Object
76 77 78 |
# File 'lib/pag_seguro/transaction.rb', line 76 def payment_method pm = PaymentMethod.new(code: parse_css("paymentMethod code"), type: parse_css("paymentMethod type")) end |
#processing? ⇒ Boolean
111 112 113 |
# File 'lib/pag_seguro/transaction.rb', line 111 def processing? PAGSEGURO_PROCESSING == status end |
#returned? ⇒ Boolean
131 132 133 |
# File 'lib/pag_seguro/transaction.rb', line 131 def returned? PAGSEGURO_RETURNED == status end |
#sender ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/pag_seguro/transaction.rb', line 80 def sender sn = Sender.new sn.name = parse_css("sender name") sn.email = parse_css("sender email") sn.phone_ddd = parse_css("sender phone areaCode") sn.phone_number = parse_css("sender phone number") sn end |
#shipping ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/pag_seguro/transaction.rb', line 89 def shipping sh = Shipping.new sh.type = parse_css("shipping type") sh.cost = parse_css("shipping cost") sh.state = parse_css("shipping address state") sh.city = parse_css("shipping address city") sh.postal_code = parse_css("shipping address postalCode") sh.district = parse_css("shipping address district") sh.street = parse_css("shipping address street") sh.number = parse_css("shipping address number") sh.complement = parse_css("shipping address complement") sh end |
#status ⇒ Object
103 104 105 |
# File 'lib/pag_seguro/transaction.rb', line 103 def status @data.css("status").first.content.to_i end |
#transaction_id ⇒ Object
62 63 64 |
# File 'lib/pag_seguro/transaction.rb', line 62 def transaction_id @data.css("code").first.content end |
#transfer? ⇒ Boolean
143 144 145 |
# File 'lib/pag_seguro/transaction.rb', line 143 def transfer? PAGSEGURO_TRANSFER == type end |
#type ⇒ Object
107 108 109 |
# File 'lib/pag_seguro/transaction.rb', line 107 def type @data.css("type").first.content.to_i end |