Class: ProcessOut::Refund

Inherits:
Object
  • Object
show all
Defined in:
lib/processout/refund.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/processout/refund.rb', line 64

def initialize(client, data = {})
  @client = client

  self.id = data.fetch(:id, nil)
  self.transaction = data.fetch(:transaction, nil)
  self.reason = data.fetch(:reason, nil)
  self.information = data.fetch(:information, nil)
  self.amount = data.fetch(:amount, nil)
  self. = data.fetch(:metadata, nil)
  self.sandbox = data.fetch(:sandbox, nil)
  self.created_at = data.fetch(:created_at, nil)
  
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



14
15
16
# File 'lib/processout/refund.rb', line 14

def amount
  @amount
end

#created_atObject

Returns the value of attribute created_at.



17
18
19
# File 'lib/processout/refund.rb', line 17

def created_at
  @created_at
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/processout/refund.rb', line 10

def id
  @id
end

#informationObject

Returns the value of attribute information.



13
14
15
# File 'lib/processout/refund.rb', line 13

def information
  @information
end

#metadataObject

Returns the value of attribute metadata.



15
16
17
# File 'lib/processout/refund.rb', line 15

def 
  @metadata
end

#reasonObject

Returns the value of attribute reason.



12
13
14
# File 'lib/processout/refund.rb', line 12

def reason
  @reason
end

#sandboxObject

Returns the value of attribute sandbox.



16
17
18
# File 'lib/processout/refund.rb', line 16

def sandbox
  @sandbox
end

#transactionObject

Returns the value of attribute transaction.



11
12
13
# File 'lib/processout/refund.rb', line 11

def transaction
  @transaction
end

Instance Method Details

#apply(transaction_id, options = {}) ⇒ Object

Apply a refund to a transaction. Params:

transaction_id

ID of the transaction

options

Hash of options



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/processout/refund.rb', line 170

def apply(transaction_id, options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/transactions/" + CGI.escape(transaction_id) + "/refunds"
  data    = {
    "amount" => @amount, 
    "metadata" => @metadata, 
    "reason" => @reason, 
    "information" => @information
  }

  response = Response.new(request.post(path, data, options))
  return_values = Array.new
  
  return_values.push(response.success)

  
  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



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/processout/refund.rb', line 86

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? "reason"
    self.reason = data["reason"]
  end
  if data.include? "information"
    self.information = data["information"]
  end
  if data.include? "amount"
    self.amount = data["amount"]
  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
  
  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



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/processout/refund.rb', line 142

def find(transaction_id, refund_id, options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/transactions/" + CGI.escape(transaction_id) + "/refunds/" + CGI.escape(refund_id) + ""
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  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



79
80
81
# File 'lib/processout/refund.rb', line 79

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



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/processout/refund.rb', line 121

def prefill(data)
  if data.nil?
    return self
  end
  self.id = data.fetch(:id, self.id)
  self.transaction = data.fetch(:transaction, self.transaction)
  self.reason = data.fetch(:reason, self.reason)
  self.information = data.fetch(:information, self.information)
  self.amount = data.fetch(:amount, self.amount)
  self. = data.fetch(:metadata, self.)
  self.sandbox = data.fetch(:sandbox, self.sandbox)
  self.created_at = data.fetch(:created_at, self.created_at)
  
  self
end