Class: PagSeguro::Transaction
- Inherits:
-
Object
- Object
- PagSeguro::Transaction
- Defined in:
- lib/pag_seguro/transaction.rb
Direct Known Subclasses
Constant Summary collapse
- 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.
Class Method Summary collapse
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 (also: #reference)
- #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.
40 41 42 |
# File 'lib/pag_seguro/transaction.rb', line 40 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 |
Class Method Details
.status_for(status_code) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pag_seguro/transaction.rb', line 24 def self.status_for(status_code) case status_code when PAGSEGURO_PROCESSING then :processing when PAGSEGURO_IN_ANALYSIS then :in_analysis when PAGSEGURO_APPROVED then :approved when PAGSEGURO_AVAILABLE then :available when PAGSEGURO_DISPUTED then :disputed when PAGSEGURO_RETURNED then :returned when PAGSEGURO_CANCELLED then :cancelled end end |
Instance Method Details
#addition_of_funds? ⇒ Boolean
166 167 168 |
# File 'lib/pag_seguro/transaction.rb', line 166 def addition_of_funds? PAGSEGURO_ADDITION_OF_FUNDS == type end |
#approved? ⇒ Boolean
138 139 140 |
# File 'lib/pag_seguro/transaction.rb', line 138 def approved? PAGSEGURO_APPROVED == status end |
#available? ⇒ Boolean
142 143 144 |
# File 'lib/pag_seguro/transaction.rb', line 142 def available? PAGSEGURO_AVAILABLE == status end |
#bonus? ⇒ Boolean
174 175 176 |
# File 'lib/pag_seguro/transaction.rb', line 174 def bonus? PAGSEGURO_BONUS == type end |
#cancelled? ⇒ Boolean
154 155 156 |
# File 'lib/pag_seguro/transaction.rb', line 154 def cancelled? PAGSEGURO_CANCELLED == status end |
#charge? ⇒ Boolean
170 171 172 |
# File 'lib/pag_seguro/transaction.rb', line 170 def charge? PAGSEGURO_CHARGE == type end |
#date ⇒ Object
81 82 83 |
# File 'lib/pag_seguro/transaction.rb', line 81 def date DateTime.iso8601( @data.css("date").first.content ) end |
#discount_amount ⇒ Object
53 54 55 |
# File 'lib/pag_seguro/transaction.rb', line 53 def discount_amount @data.css("discountAmount").first.content end |
#disputed? ⇒ Boolean
146 147 148 |
# File 'lib/pag_seguro/transaction.rb', line 146 def disputed? PAGSEGURO_DISPUTED == status end |
#extra_amount ⇒ Object
65 66 67 |
# File 'lib/pag_seguro/transaction.rb', line 65 def extra_amount @data.css("extraAmount").first.content end |
#fee_amount ⇒ Object
57 58 59 |
# File 'lib/pag_seguro/transaction.rb', line 57 def fee_amount @data.css("feeAmount").first.content end |
#gross_amount ⇒ Object
49 50 51 |
# File 'lib/pag_seguro/transaction.rb', line 49 def gross_amount @data.css("grossAmount").first.content end |
#id ⇒ Object Also known as: reference
44 45 46 |
# File 'lib/pag_seguro/transaction.rb', line 44 def id @data.css("reference").first.content end |
#in_analysis? ⇒ Boolean
134 135 136 |
# File 'lib/pag_seguro/transaction.rb', line 134 def in_analysis? PAGSEGURO_IN_ANALYSIS == status end |
#installment_count ⇒ Object
69 70 71 |
# File 'lib/pag_seguro/transaction.rb', line 69 def installment_count @data.css("installmentCount").first.content.to_i end |
#item_count ⇒ Object
73 74 75 |
# File 'lib/pag_seguro/transaction.rb', line 73 def item_count @data.css("itemCount").first.content.to_i end |
#items ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/pag_seguro/transaction.rb', line 85 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
61 62 63 |
# File 'lib/pag_seguro/transaction.rb', line 61 def net_amount @data.css("netAmount").first.content end |
#payment? ⇒ Boolean
158 159 160 |
# File 'lib/pag_seguro/transaction.rb', line 158 def payment? PAGSEGURO_PAYMENT == type end |
#payment_method ⇒ Object
94 95 96 97 |
# File 'lib/pag_seguro/transaction.rb', line 94 def payment_method PaymentMethod.new code: parse_css("paymentMethod code"), type: parse_css("paymentMethod type") end |
#processing? ⇒ Boolean
130 131 132 |
# File 'lib/pag_seguro/transaction.rb', line 130 def processing? PAGSEGURO_PROCESSING == status end |
#returned? ⇒ Boolean
150 151 152 |
# File 'lib/pag_seguro/transaction.rb', line 150 def returned? PAGSEGURO_RETURNED == status end |
#sender ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/pag_seguro/transaction.rb', line 99 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
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/pag_seguro/transaction.rb', line 108 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
122 123 124 |
# File 'lib/pag_seguro/transaction.rb', line 122 def status @data.css("status").first.content.to_i end |
#transaction_id ⇒ Object
77 78 79 |
# File 'lib/pag_seguro/transaction.rb', line 77 def transaction_id @data.css("code").first.content end |
#transfer? ⇒ Boolean
162 163 164 |
# File 'lib/pag_seguro/transaction.rb', line 162 def transfer? PAGSEGURO_TRANSFER == type end |
#type ⇒ Object
126 127 128 |
# File 'lib/pag_seguro/transaction.rb', line 126 def type @data.css("type").first.content.to_i end |