Class: PagSeguro::Transaction
- Inherits:
-
Object
- Object
- PagSeguro::Transaction
- 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
-
#cancellation_source ⇒ Object
The cancellation source.
-
#code ⇒ Object
The transaction code.
-
#created_at ⇒ Object
When the payment request was created.
-
#creditor_fees ⇒ Object
The charged fees.
-
#discount_amount ⇒ Object
The discount amount.
-
#errors ⇒ Object
readonly
Set the transaction errors.
-
#escrow_end_date ⇒ Object
The escrow end date.
-
#extra_amount ⇒ Object
Set the extra amount applied to the transaction’s total.
-
#gross_amount ⇒ Object
The gross amount.
-
#installments ⇒ Object
The installment count.
-
#net_amount ⇒ Object
The net amount.
-
#payment_link ⇒ Object
The boleto payment url.
-
#payment_method ⇒ Object
The payment method.
-
#reference ⇒ Object
The reference code identifies the order you placed on the payment request.
-
#sender ⇒ Object
The payer information (who is sending money).
-
#shipping ⇒ Object
The shipping information.
-
#status ⇒ Object
The transaction status.
-
#type_id ⇒ Object
The transaction type.
-
#updated_at ⇒ Object
The last notification’s update.
Class Method Summary collapse
-
.find_abandoned(options = {}, page = 0) ⇒ Object
Get abandoned transactions.
-
.find_by_code(code) ⇒ Object
Find a transaction by its transactionCode Return a PagSeguro::Transaction instance.
-
.find_by_date(options = {}, page = 0) ⇒ Object
Search transactions within a date range.
-
.find_by_notification_code(code) ⇒ Object
Find a transaction by its notificationCode.
-
.find_by_reference(reference) ⇒ Object
Search a transaction by its reference code Return a PagSeguro::SearchByReference instance.
-
.load_from_response(response) ⇒ Object
Serialize the HTTP response into data.
-
.load_from_xml(xml) ⇒ Object
Serialize the XML object.
-
.send_request(path) ⇒ Object
Send a get request to v3 API version, with the path given.
Instance Method Summary collapse
-
#items ⇒ Object
Hold the transaction’s items.
-
#items=(_items) ⇒ Object
Normalize the items list.
-
#payment_releases ⇒ Object
Hold the transaction’s payments.
-
#payment_releases=(_payments) ⇒ Object
Normalize the transaction’s payments list.
Methods included from Extensions::EnsureType
Methods included from Extensions::MassAssignment
Instance Attribute Details
#cancellation_source ⇒ Object
The cancellation source.
58 59 60 |
# File 'lib/pagseguro/transaction.rb', line 58 def cancellation_source @cancellation_source end |
#code ⇒ Object
The transaction code.
10 11 12 |
# File 'lib/pagseguro/transaction.rb', line 10 def code @code end |
#created_at ⇒ Object
When the payment request was created.
7 8 9 |
# File 'lib/pagseguro/transaction.rb', line 7 def created_at @created_at end |
#creditor_fees ⇒ Object
The charged fees.
38 39 40 |
# File 'lib/pagseguro/transaction.rb', line 38 def creditor_fees @creditor_fees end |
#discount_amount ⇒ Object
The discount amount.
35 36 37 |
# File 'lib/pagseguro/transaction.rb', line 35 def discount_amount @discount_amount end |
#errors ⇒ Object (readonly)
Set the transaction errors.
64 65 66 |
# File 'lib/pagseguro/transaction.rb', line 64 def errors @errors end |
#escrow_end_date ⇒ Object
The escrow end date.
61 62 63 |
# File 'lib/pagseguro/transaction.rb', line 61 def escrow_end_date @escrow_end_date end |
#extra_amount ⇒ Object
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_amount ⇒ Object
The gross amount.
32 33 34 |
# File 'lib/pagseguro/transaction.rb', line 32 def gross_amount @gross_amount end |
#installments ⇒ Object
The installment count.
49 50 51 |
# File 'lib/pagseguro/transaction.rb', line 49 def installments @installments end |
#net_amount ⇒ Object
The net amount.
41 42 43 |
# File 'lib/pagseguro/transaction.rb', line 41 def net_amount @net_amount end |
#payment_link ⇒ Object
The boleto payment url.
29 30 31 |
# File 'lib/pagseguro/transaction.rb', line 29 def payment_link @payment_link end |
#payment_method ⇒ Object
The payment method.
26 27 28 |
# File 'lib/pagseguro/transaction.rb', line 26 def payment_method @payment_method end |
#reference ⇒ Object
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 |
#sender ⇒ Object
The payer information (who is sending money).
52 53 54 |
# File 'lib/pagseguro/transaction.rb', line 52 def sender @sender end |
#shipping ⇒ Object
The shipping information.
55 56 57 |
# File 'lib/pagseguro/transaction.rb', line 55 def shipping @shipping end |
#status ⇒ Object
The transaction status.
23 24 25 |
# File 'lib/pagseguro/transaction.rb', line 23 def status @status end |
#type_id ⇒ Object
The transaction type.
17 18 19 |
# File 'lib/pagseguro/transaction.rb', line 17 def type_id @type_id end |
#updated_at ⇒ Object
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( = {}, page = 0) = { starts_at: Time.now - 86400, ends_at: Time.now - 900, per_page: 50 }.merge() SearchAbandoned.new("transactions/abandoned", , 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( = {}, page = 0) = { starts_at: Time.now - 86400, ends_at: Time.now, per_page: 50 }.merge() SearchByDate.new("transactions", , 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) = { reference: reference } SearchByReference.new("transactions", ) 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 |
Instance Method Details
#items ⇒ Object
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_releases ⇒ Object
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 |