Class: PagSeguro::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/pag_seguro/transaction.rb

Direct Known Subclasses

Notification, Query

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

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject

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

.transactions_urlObject



36
37
38
# File 'lib/pag_seguro/transaction.rb', line 36

def self.transactions_url
  PagSeguro::Url.api_url("/transactions")
end

Instance Method Details

#addition_of_funds?Boolean

Returns:

  • (Boolean)


166
167
168
# File 'lib/pag_seguro/transaction.rb', line 166

def addition_of_funds?
  PAGSEGURO_ADDITION_OF_FUNDS == type
end

#approved?Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/pag_seguro/transaction.rb', line 138

def approved?
  PAGSEGURO_APPROVED == status
end

#available?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/pag_seguro/transaction.rb', line 142

def available?
  PAGSEGURO_AVAILABLE == status
end

#bonus?Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/pag_seguro/transaction.rb', line 174

def bonus?
  PAGSEGURO_BONUS == type
end

#cancelled?Boolean

Returns:

  • (Boolean)


154
155
156
# File 'lib/pag_seguro/transaction.rb', line 154

def cancelled?
  PAGSEGURO_CANCELLED == status
end

#charge?Boolean

Returns:

  • (Boolean)


170
171
172
# File 'lib/pag_seguro/transaction.rb', line 170

def charge?
  PAGSEGURO_CHARGE == type
end

#dateObject



81
82
83
# File 'lib/pag_seguro/transaction.rb', line 81

def date
  DateTime.iso8601( @data.css("date").first.content )
end

#discount_amountObject



53
54
55
# File 'lib/pag_seguro/transaction.rb', line 53

def discount_amount
  @data.css("discountAmount").first.content
end

#disputed?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/pag_seguro/transaction.rb', line 146

def disputed?
  PAGSEGURO_DISPUTED == status
end

#extra_amountObject



65
66
67
# File 'lib/pag_seguro/transaction.rb', line 65

def extra_amount
  @data.css("extraAmount").first.content
end

#fee_amountObject



57
58
59
# File 'lib/pag_seguro/transaction.rb', line 57

def fee_amount
  @data.css("feeAmount").first.content
end

#gross_amountObject



49
50
51
# File 'lib/pag_seguro/transaction.rb', line 49

def gross_amount
  @data.css("grossAmount").first.content
end

#idObject 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

Returns:

  • (Boolean)


134
135
136
# File 'lib/pag_seguro/transaction.rb', line 134

def in_analysis?
  PAGSEGURO_IN_ANALYSIS == status
end

#installment_countObject



69
70
71
# File 'lib/pag_seguro/transaction.rb', line 69

def installment_count
  @data.css("installmentCount").first.content.to_i
end

#item_countObject



73
74
75
# File 'lib/pag_seguro/transaction.rb', line 73

def item_count
  @data.css("itemCount").first.content.to_i
end

#itemsObject



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_amountObject



61
62
63
# File 'lib/pag_seguro/transaction.rb', line 61

def net_amount
  @data.css("netAmount").first.content
end

#payment?Boolean

Returns:

  • (Boolean)


158
159
160
# File 'lib/pag_seguro/transaction.rb', line 158

def payment?
  PAGSEGURO_PAYMENT == type
end

#payment_methodObject



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

Returns:

  • (Boolean)


130
131
132
# File 'lib/pag_seguro/transaction.rb', line 130

def processing?
  PAGSEGURO_PROCESSING == status
end

#returned?Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/pag_seguro/transaction.rb', line 150

def returned?
  PAGSEGURO_RETURNED == status
end

#senderObject



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

#shippingObject



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

#statusObject



122
123
124
# File 'lib/pag_seguro/transaction.rb', line 122

def status
  @data.css("status").first.content.to_i
end

#transaction_idObject



77
78
79
# File 'lib/pag_seguro/transaction.rb', line 77

def transaction_id
  @data.css("code").first.content
end

#transfer?Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/pag_seguro/transaction.rb', line 162

def transfer?
  PAGSEGURO_TRANSFER == type
end

#typeObject



126
127
128
# File 'lib/pag_seguro/transaction.rb', line 126

def type
  @data.css("type").first.content.to_i
end