Class: PagSeguro::Transaction

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

Direct Known Subclasses

Notification, Query

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

Instance Method Summary collapse

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

#dataObject

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

Returns:

  • (Boolean)


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

def addition_of_funds?
  PAGSEGURO_ADDITION_OF_FUNDS == type
end

#approved?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/pag_seguro/transaction.rb', line 119

def approved?
  PAGSEGURO_APPROVED == status
end

#available?Boolean

Returns:

  • (Boolean)


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

def available?
  PAGSEGURO_AVAILABLE == status
end

#bonus?Boolean

Returns:

  • (Boolean)


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

def bonus?
  PAGSEGURO_BONUS == type
end

#cancelled?Boolean

Returns:

  • (Boolean)


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

def cancelled?
  PAGSEGURO_CANCELLED == status
end

#charge?Boolean

Returns:

  • (Boolean)


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

def charge?
  PAGSEGURO_CHARGE == type
end

#dateObject



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

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

#discount_amountObject



38
39
40
# File 'lib/pag_seguro/transaction.rb', line 38

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

#disputed?Boolean

Returns:

  • (Boolean)


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

def disputed?
  PAGSEGURO_DISPUTED == status
end

#extra_amountObject



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

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

#fee_amountObject



42
43
44
# File 'lib/pag_seguro/transaction.rb', line 42

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

#gross_amountObject



34
35
36
# File 'lib/pag_seguro/transaction.rb', line 34

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

#idObject



30
31
32
# File 'lib/pag_seguro/transaction.rb', line 30

def id
  @data.css("reference").first.content
end

#in_analysis?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/pag_seguro/transaction.rb', line 115

def in_analysis?
  PAGSEGURO_IN_ANALYSIS == status
end

#installment_countObject



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

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

#item_countObject



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

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

#itemsObject



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_amountObject



46
47
48
# File 'lib/pag_seguro/transaction.rb', line 46

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

#payment?Boolean

Returns:

  • (Boolean)


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

def payment?
  PAGSEGURO_PAYMENT == type
end

#payment_methodObject



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

Returns:

  • (Boolean)


111
112
113
# File 'lib/pag_seguro/transaction.rb', line 111

def processing?
  PAGSEGURO_PROCESSING == status
end

#returned?Boolean

Returns:

  • (Boolean)


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

def returned?
  PAGSEGURO_RETURNED == status
end

#senderObject



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

#shippingObject



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

#statusObject



103
104
105
# File 'lib/pag_seguro/transaction.rb', line 103

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

#transaction_idObject



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

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

#transfer?Boolean

Returns:

  • (Boolean)


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

def transfer?
  PAGSEGURO_TRANSFER == type
end

#typeObject



107
108
109
# File 'lib/pag_seguro/transaction.rb', line 107

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