Class: Zoop::Transaction

Inherits:
Model show all
Defined in:
lib/zoop/resources/transaction.rb

Constant Summary

Constants inherited from ZoopObject

ZoopObject::RESOURCES

Instance Attribute Summary

Attributes inherited from ZoopObject

#attributes

Instance Method Summary collapse

Methods inherited from Model

class_name, #create, create, find_by_id, #save, underscored_class_name, #update, url, #url

Methods inherited from ZoopObject

#==, #[]=, convert, #empty?, #respond_to?, #to_hash, #to_s, #unsaved_attributes

Constructor Details

#initialize(response = {}) ⇒ Transaction

Returns a new instance of Transaction.



5
6
7
8
9
10
11
# File 'lib/zoop/resources/transaction.rb', line 5

def initialize(response = {})
  super(response)

  self.currency         ||= 'BRL'
  self.payment_type     ||= 'credit'
  self.capture          ||= true
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Zoop::ZoopObject

Instance Method Details

#capture!Object



13
14
15
16
17
# File 'lib/zoop/resources/transaction.rb', line 13

def capture!
  params = { amount: amount.convert_to_cents, on_behalf_of: on_behalf_of }
  update_model Zoop::Request.post(url('capture'), params: params).run
  self
end

#destroyObject

Raises:

  • (NotImplementedError)


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

def destroy
  raise NotImplementedError
end

#receivablesObject



25
26
27
# File 'lib/zoop/resources/transaction.rb', line 25

def receivables
  Zoop::Request.get( url 'receivables' ).call
end

#refundObject



19
20
21
22
23
# File 'lib/zoop/resources/transaction.rb', line 19

def refund
  params = { amount: amount.convert_to_cents, on_behalf_of: on_behalf_of }
  update_model Zoop::Request.post(url('void'), params: params).run
  self
end