Class: PagSeguro::Transaction

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

Defined Under Namespace

Classes: Collection, Response, Serializer

Constant Summary collapse

ONE_DAY_IN_SECONDS =
86400
FIFTEEN_MINUTES_IN_SECONDS =
900

Instance Attribute Summary collapse

Attributes included from Extensions::Credentiable

#credentials

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.



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

def cancellation_source
  @cancellation_source
end

#codeObject

The transaction code.



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

def code
  @code
end

#created_atObject

When the payment request was created.



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

def created_at
  @created_at
end

#creditor_feesObject

The charged fees.



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

def creditor_fees
  @creditor_fees
end

#discount_amountObject

The discount amount.



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

def discount_amount
  @discount_amount
end

#errorsObject (readonly)

Set errors.



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

def errors
  @errors
end

#escrow_end_dateObject

The escrow end date.



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

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.



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

def extra_amount
  @extra_amount
end

#gross_amountObject

The gross amount.



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

def gross_amount
  @gross_amount
end

#installmentsObject

The installment count.



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

def installments
  @installments
end

#net_amountObject

The net amount.



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

def net_amount
  @net_amount
end

The boleto payment url.



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

def payment_link
  @payment_link
end

#payment_methodObject

The payment method.



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

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.



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

def reference
  @reference
end

#senderObject

The payer information (who is sending money).



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

def sender
  @sender
end

#shippingObject

The shipping information.



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

def shipping
  @shipping
end

#statusObject

The transaction status.



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

def status
  @status
end

#type_idObject

The transaction type.



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

def type_id
  @type_id
end

#updated_atObject

The last notification’s update.



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

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.



122
123
124
125
126
127
128
129
130
# File 'lib/pagseguro/transaction.rb', line 122

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

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

.find_by_code(code, options = {}) ⇒ Object

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



72
73
74
# File 'lib/pagseguro/transaction.rb', line 72

def self.find_by_code(code, options = {})
  load_from_response send_request("transactions/#{code}", options)
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.



92
93
94
95
96
97
98
99
# File 'lib/pagseguro/transaction.rb', line 92

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

.find_by_notification_code(code, options = {}) ⇒ Object

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



78
79
80
# File 'lib/pagseguro/transaction.rb', line 78

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

.find_by_reference(reference, options = {}) ⇒ Object

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

Options:

# reference: the transaction reference code



108
109
110
# File 'lib/pagseguro/transaction.rb', line 108

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

.load_from_xml(xml) ⇒ Object

Serialize the XML object.



188
189
190
# File 'lib/pagseguro/transaction.rb', line 188

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

Instance Method Details

#itemsObject

Hold the transaction’s items.



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

def items
  @items ||= Items.new
end

#items=(_items) ⇒ Object

Normalize the items list.



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

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

#payment_releasesObject

Hold the transaction’s payments



148
149
150
# File 'lib/pagseguro/transaction.rb', line 148

def payment_releases
  @payment_releases ||= PaymentReleases.new
end

#payment_releases=(_payments) ⇒ Object

Normalize the transaction’s payments list



153
154
155
# File 'lib/pagseguro/transaction.rb', line 153

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

#update_attributes(attrs) ⇒ Object

Update all attributes



183
184
185
# File 'lib/pagseguro/transaction.rb', line 183

def update_attributes(attrs)
  attrs.each { |name, value| send("#{name}=", value) }
end