Class: ProcessOut::Refund
- Inherits:
-
Object
- Object
- ProcessOut::Refund
- Defined in:
- lib/processout/refund.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#has_failed ⇒ Object
Returns the value of attribute has_failed.
-
#id ⇒ Object
Returns the value of attribute id.
-
#information ⇒ Object
Returns the value of attribute information.
-
#invoice_detail_ids ⇒ Object
Returns the value of attribute invoice_detail_ids.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#reason ⇒ Object
Returns the value of attribute reason.
-
#sandbox ⇒ Object
Returns the value of attribute sandbox.
-
#transaction ⇒ Object
Returns the value of attribute transaction.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
Instance Method Summary collapse
-
#create(options = {}) ⇒ Object
Create a refund for a transaction.
-
#create_for_invoice(invoice_id, options = {}) ⇒ Object
Create a refund for an invoice.
-
#fetch_transaction_refunds(transaction_id, options = {}) ⇒ Object
Get the transaction’s refunds.
-
#fill_with_data(data) ⇒ Object
- Fills the object with data coming from the API Params:
data
-
Hash
of data coming from the API.
- Fills the object with data coming from the API Params:
-
#find(transaction_id, refund_id, options = {}) ⇒ Object
Find a transaction’s refund by its ID.
-
#initialize(client, data = {}) ⇒ Refund
constructor
- Initializes the Refund object Params:
client
ProcessOut
client instancedata
-
data that can be used to fill the object.
- Initializes the Refund object Params:
-
#new(data = {}) ⇒ Object
Create a new Refund using the current client.
-
#prefill(data) ⇒ Object
- Prefills the object with the data passed as parameters Params:
data
-
Hash
of data.
- Prefills the object with the data passed as parameters Params:
-
#to_json(options) ⇒ Object
Overrides the JSON marshaller to only send the fields we want.
Constructor Details
#initialize(client, data = {}) ⇒ Refund
Initializes the Refund object Params:
client
-
ProcessOut
client instance data
-
data that can be used to fill the object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/processout/refund.rb', line 85 def initialize(client, data = {}) @client = client self.id = data.fetch(:id, nil) self.transaction = data.fetch(:transaction, nil) self.transaction_id = data.fetch(:transaction_id, nil) self.amount = data.fetch(:amount, nil) self.reason = data.fetch(:reason, nil) self.information = data.fetch(:information, nil) self.has_failed = data.fetch(:has_failed, nil) self. = data.fetch(:metadata, nil) self.sandbox = data.fetch(:sandbox, nil) self.created_at = data.fetch(:created_at, nil) self.invoice_detail_ids = data.fetch(:invoice_detail_ids, nil) end |
Instance Attribute Details
#amount ⇒ Object
Returns the value of attribute amount.
14 15 16 |
# File 'lib/processout/refund.rb', line 14 def amount @amount end |
#created_at ⇒ Object
Returns the value of attribute created_at.
20 21 22 |
# File 'lib/processout/refund.rb', line 20 def created_at @created_at end |
#has_failed ⇒ Object
Returns the value of attribute has_failed.
17 18 19 |
# File 'lib/processout/refund.rb', line 17 def has_failed @has_failed end |
#id ⇒ Object
Returns the value of attribute id.
11 12 13 |
# File 'lib/processout/refund.rb', line 11 def id @id end |
#information ⇒ Object
Returns the value of attribute information.
16 17 18 |
# File 'lib/processout/refund.rb', line 16 def information @information end |
#invoice_detail_ids ⇒ Object
Returns the value of attribute invoice_detail_ids.
21 22 23 |
# File 'lib/processout/refund.rb', line 21 def invoice_detail_ids @invoice_detail_ids end |
#metadata ⇒ Object
Returns the value of attribute metadata.
18 19 20 |
# File 'lib/processout/refund.rb', line 18 def @metadata end |
#reason ⇒ Object
Returns the value of attribute reason.
15 16 17 |
# File 'lib/processout/refund.rb', line 15 def reason @reason end |
#sandbox ⇒ Object
Returns the value of attribute sandbox.
19 20 21 |
# File 'lib/processout/refund.rb', line 19 def sandbox @sandbox end |
#transaction ⇒ Object
Returns the value of attribute transaction.
12 13 14 |
# File 'lib/processout/refund.rb', line 12 def transaction @transaction end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
13 14 15 |
# File 'lib/processout/refund.rb', line 13 def transaction_id @transaction_id end |
Instance Method Details
#create(options = {}) ⇒ Object
Create a refund for a transaction. Params:
options
-
Hash
of options
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/processout/refund.rb', line 279 def create( = {}) self.prefill() request = Request.new(@client) path = "/transactions/" + CGI.escape(@transaction_id) + "/refunds" data = { "amount" => @amount, "reason" => @reason, "information" => @information, "invoice_detail_ids" => @invoice_detail_ids, "metadata" => .fetch(:metadata, nil) } response = Response.new(request.post(path, data, )) return_values = Array.new return_values.push(response.success) return_values[0] end |
#create_for_invoice(invoice_id, options = {}) ⇒ Object
Create a refund for an invoice. Params:
invoice_id
-
ID of the invoice
options
-
Hash
of options
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/processout/refund.rb', line 194 def create_for_invoice(invoice_id, = {}) self.prefill() request = Request.new(@client) path = "/invoices/" + CGI.escape(invoice_id) + "/refunds" data = { "amount" => @amount, "reason" => @reason, "information" => @information, "invoice_detail_ids" => @invoice_detail_ids, "metadata" => .fetch(:metadata, nil) } response = Response.new(request.post(path, data, )) return_values = Array.new return_values.push(response.success) return_values[0] end |
#fetch_transaction_refunds(transaction_id, options = {}) ⇒ Object
Get the transaction’s refunds. Params:
transaction_id
-
ID of the transaction
options
-
Hash
of options
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/processout/refund.rb', line 220 def fetch_transaction_refunds(transaction_id, = {}) self.prefill() request = Request.new(@client) path = "/transactions/" + CGI.escape(transaction_id) + "/refunds" data = { } response = Response.new(request.get(path, data, )) return_values = Array.new a = Array.new body = response.body for v in body['refunds'] tmp = Refund.new(@client) tmp.fill_with_data(v) a.push(tmp) end return_values.push(a) return_values[0] end |
#fill_with_data(data) ⇒ Object
Fills the object with data coming from the API Params:
data
-
Hash
of data coming from the API
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/processout/refund.rb', line 127 def fill_with_data(data) if data.nil? return self end if data.include? "id" self.id = data["id"] end if data.include? "transaction" self.transaction = data["transaction"] end if data.include? "transaction_id" self.transaction_id = data["transaction_id"] end if data.include? "amount" self.amount = data["amount"] end if data.include? "reason" self.reason = data["reason"] end if data.include? "information" self.information = data["information"] end if data.include? "has_failed" self.has_failed = data["has_failed"] end if data.include? "metadata" self. = data["metadata"] end if data.include? "sandbox" self.sandbox = data["sandbox"] end if data.include? "created_at" self.created_at = data["created_at"] end if data.include? "invoice_detail_ids" self.invoice_detail_ids = data["invoice_detail_ids"] end self end |
#find(transaction_id, refund_id, options = {}) ⇒ Object
Find a transaction’s refund by its ID. Params:
transaction_id
-
ID of the transaction on which the refund was applied
refund_id
-
ID of the refund
options
-
Hash
of options
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/processout/refund.rb', line 252 def find(transaction_id, refund_id, = {}) self.prefill() request = Request.new(@client) path = "/transactions/" + CGI.escape(transaction_id) + "/refunds/" + CGI.escape(refund_id) + "" data = { } response = Response.new(request.get(path, data, )) return_values = Array.new body = response.body body = body["refund"] obj = Refund.new(@client) return_values.push(obj.fill_with_data(body)) return_values[0] end |
#new(data = {}) ⇒ Object
Create a new Refund using the current client
103 104 105 |
# File 'lib/processout/refund.rb', line 103 def new(data = {}) Refund.new(@client, data) end |
#prefill(data) ⇒ Object
Prefills the object with the data passed as parameters Params:
data
-
Hash
of data
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/processout/refund.rb', line 171 def prefill(data) if data.nil? return self end self.id = data.fetch(:id, self.id) self.transaction = data.fetch(:transaction, self.transaction) self.transaction_id = data.fetch(:transaction_id, self.transaction_id) self.amount = data.fetch(:amount, self.amount) self.reason = data.fetch(:reason, self.reason) self.information = data.fetch(:information, self.information) self.has_failed = data.fetch(:has_failed, self.has_failed) self. = data.fetch(:metadata, self.) self.sandbox = data.fetch(:sandbox, self.sandbox) self.created_at = data.fetch(:created_at, self.created_at) self.invoice_detail_ids = data.fetch(:invoice_detail_ids, self.invoice_detail_ids) self end |
#to_json(options) ⇒ Object
Overrides the JSON marshaller to only send the fields we want
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/processout/refund.rb', line 108 def to_json() { "id": self.id, "transaction": self.transaction, "transaction_id": self.transaction_id, "amount": self.amount, "reason": self.reason, "information": self.information, "has_failed": self.has_failed, "metadata": self., "sandbox": self.sandbox, "created_at": self.created_at, "invoice_detail_ids": self.invoice_detail_ids, }.to_json end |