Class: PagSeguro::Transaction

Inherits:
Object
  • Object
show all
Includes:
Extensions::EnsureType, Extensions::MassAssignment
Defined in:
lib/pagseguro/transaction.rb,
lib/pagseguro/transaction/response.rb,
lib/pagseguro/transaction/serializer.rb

Defined Under Namespace

Classes: Response, Serializer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Extensions::EnsureType

#ensure_type

Methods included from Extensions::MassAssignment

#initialize

Instance Attribute Details

#cancellation_sourceObject

The cancellation source.



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

def cancellation_source
  @cancellation_source
end

#codeObject

The transaction code.



10
11
12
# File 'lib/pagseguro/transaction.rb', line 10

def code
  @code
end

#created_atObject

When the payment request was created.



7
8
9
# File 'lib/pagseguro/transaction.rb', line 7

def created_at
  @created_at
end

#creditor_feesObject

The charged fees.



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

def creditor_fees
  @creditor_fees
end

#discount_amountObject

The discount amount.



35
36
37
# File 'lib/pagseguro/transaction.rb', line 35

def discount_amount
  @discount_amount
end

#errorsObject (readonly)

Set the transaction errors.



64
65
66
# File 'lib/pagseguro/transaction.rb', line 64

def errors
  @errors
end

#escrow_end_dateObject

The escrow end date.



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

def escrow_end_date
  @escrow_end_date
end

#extra_amountObject

Set the extra amount applied to the transaction’s total. It’s considered as an extra charge when positive, or a discount if negative.



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

def extra_amount
  @extra_amount
end

#gross_amountObject

The gross amount.



32
33
34
# File 'lib/pagseguro/transaction.rb', line 32

def gross_amount
  @gross_amount
end

#installmentsObject

The installment count.



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

def installments
  @installments
end

#net_amountObject

The net amount.



41
42
43
# File 'lib/pagseguro/transaction.rb', line 41

def net_amount
  @net_amount
end

The boleto payment url.



29
30
31
# File 'lib/pagseguro/transaction.rb', line 29

def payment_link
  @payment_link
end

#payment_methodObject

The payment method.



26
27
28
# File 'lib/pagseguro/transaction.rb', line 26

def payment_method
  @payment_method
end

#referenceObject

The reference code identifies the order you placed on the payment request. It’s used by the store and can be something like the order id.



14
15
16
# File 'lib/pagseguro/transaction.rb', line 14

def reference
  @reference
end

#senderObject

The payer information (who is sending money).



52
53
54
# File 'lib/pagseguro/transaction.rb', line 52

def sender
  @sender
end

#shippingObject

The shipping information.



55
56
57
# File 'lib/pagseguro/transaction.rb', line 55

def shipping
  @shipping
end

#statusObject

The transaction status.



23
24
25
# File 'lib/pagseguro/transaction.rb', line 23

def status
  @status
end

#type_idObject

The transaction type.



17
18
19
# File 'lib/pagseguro/transaction.rb', line 17

def type_id
  @type_id
end

#updated_atObject

The last notification’s update.



20
21
22
# File 'lib/pagseguro/transaction.rb', line 20

def updated_at
  @updated_at
end

Class Method Details

.find_abandoned(options = {}, page = 0) ⇒ Object

Get abandoned transactions. Return a PagSeguro::SearchByDate instance

Options:

# starts_at: the starting date. Defaults to the last 24-hours. # ends_at: the ending date. Defaults to 15 minutes ago. Attention: you have to set it this to Time.now - 15 minutes, otherwise the “finalDate must be lower than allowed limit” error will be returned. # page: the current page. # per_page: the result limit.



119
120
121
122
123
124
125
126
127
# File 'lib/pagseguro/transaction.rb', line 119

def self.find_abandoned(options = {}, page = 0)
  options = {
    starts_at: Time.now - 86400,
    ends_at: Time.now - 900,
    per_page: 50
  }.merge(options)

  SearchAbandoned.new("transactions/abandoned", options, page)
end

.find_by_code(code) ⇒ Object

Find a transaction by its transactionCode Return a PagSeguro::Transaction instance



68
69
70
# File 'lib/pagseguro/transaction.rb', line 68

def self.find_by_code(code)
  load_from_response send_request("transactions/#{code}")
end

.find_by_date(options = {}, page = 0) ⇒ Object

Search transactions within a date range. Return a PagSeguro::SearchByDate instance

Options:

# starts_at: the starting date. Defaults to the last 24-hours. # ends_at: the ending date. # page: the current page. # per_page: the result limit.



88
89
90
91
92
93
94
95
# File 'lib/pagseguro/transaction.rb', line 88

def self.find_by_date(options = {}, page = 0)
  options = {
    starts_at: Time.now - 86400,
    ends_at: Time.now,
    per_page: 50
  }.merge(options)
  SearchByDate.new("transactions", options, page)
end

.find_by_notification_code(code) ⇒ Object

Find a transaction by its notificationCode. Return a PagSeguro::Transaction instance.



74
75
76
# File 'lib/pagseguro/transaction.rb', line 74

def self.find_by_notification_code(code)
  load_from_response send_request("transactions/notifications/#{code}")
end

.find_by_reference(reference) ⇒ Object

Search a transaction by its reference code Return a PagSeguro::SearchByReference instance

Options:

# reference: the transaction reference code



104
105
106
107
# File 'lib/pagseguro/transaction.rb', line 104

def self.find_by_reference(reference)
  options = { reference: reference }
  SearchByReference.new("transactions", options)
end

.load_from_response(response) ⇒ Object

Serialize the HTTP response into data.



130
131
132
133
134
135
136
# File 'lib/pagseguro/transaction.rb', line 130

def self.load_from_response(response) # :nodoc:
  if response.success? and response.xml?
    load_from_xml Nokogiri::XML(response.body).css("transaction").first
  else
    Response.new Errors.new(response)
  end
end

.load_from_xml(xml) ⇒ Object

Serialize the XML object.



144
145
146
# File 'lib/pagseguro/transaction.rb', line 144

def self.load_from_xml(xml) # :nodoc:
  new Serializer.new(xml).serialize
end

.send_request(path) ⇒ Object

Send a get request to v3 API version, with the path given



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

def self.send_request(path)
  Request.get(path, 'v3')
end

Instance Method Details

#itemsObject

Hold the transaction’s items.



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

def items
  @items ||= Items.new
end

#items=(_items) ⇒ Object

Normalize the items list.



179
180
181
# File 'lib/pagseguro/transaction.rb', line 179

def items=(_items)
  _items.each {|item| items << item }
end

#payment_releasesObject

Hold the transaction’s payments



164
165
166
# File 'lib/pagseguro/transaction.rb', line 164

def payment_releases
  @payment_releases ||= PaymentReleases.new
end

#payment_releases=(_payments) ⇒ Object

Normalize the transaction’s payments list



169
170
171
# File 'lib/pagseguro/transaction.rb', line 169

def payment_releases=(_payments)
  _payments.each { |payment| payment_releases << payment }
end