Module: Xfers::Charge

Defined in:
lib/xfers/charge.rb

Constant Summary collapse

RESOUCE_URL =
'/charges'

Class Method Summary collapse

Class Method Details

.authorize(charge_id, auth_code) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/xfers/charge.rb', line 34

def self.authorize(charge_id, auth_code)
  raise InvalidRequestError.new 'Charge id cannot be empty', 400 if charge_id.nil? or charge_id == ''
  raise InvalidRequestError.new 'auth_code cannot be empty', 400 if auth_code.nil? or auth_code == ''
  params = {
      'auth_code'=> auth_code
  }
  Xfers::APIOperations.post params, "#{RESOUCE_URL}/#{charge_id}/authorize", nil
end

.cancel(charge_id, connect_key = nil) ⇒ Object



29
30
31
32
# File 'lib/xfers/charge.rb', line 29

def self.cancel(charge_id, connect_key=nil)
  raise InvalidRequestError.new 'Charge id cannot be empty', 400 if charge_id.nil? or charge_id == ''
  Xfers::APIOperations.post nil, "#{RESOUCE_URL}/#{charge_id}/cancel", connect_key
end

.create(params, connect_key = nil) ⇒ Object



14
15
16
17
# File 'lib/xfers/charge.rb', line 14

def self.create(params, connect_key=nil)
  raise InvalidRequestError.new 'Params cannot be empty', 400 if params.nil? or params == ''
  Xfers::APIOperations.post params, RESOUCE_URL, connect_key
end

.list_all(params = nil, connect_key = nil) ⇒ Object



10
11
12
# File 'lib/xfers/charge.rb', line 10

def self.list_all(params=nil, connect_key=nil)
  Xfers::APIOperations.get(params, RESOUCE_URL, connect_key)
end

.refund(charge_id, connect_key = nil) ⇒ Object



19
20
21
22
# File 'lib/xfers/charge.rb', line 19

def self.refund(charge_id, connect_key=nil)
  raise InvalidRequestError.new 'Charge id cannot be empty', 400 if charge_id.nil? or charge_id == ''
  Xfers::APIOperations.post nil, "#{RESOUCE_URL}/#{charge_id}/refunds", connect_key
end

.retrieve(charge_id, connect_key = nil) ⇒ Object



5
6
7
8
# File 'lib/xfers/charge.rb', line 5

def self.retrieve(charge_id, connect_key=nil)
  raise InvalidRequestError.new 'Charge id cannot be empty', 400 if charge_id.nil? or charge_id == ''
  Xfers::APIOperations.get nil, "#{RESOUCE_URL}/#{charge_id}", connect_key
end

.validate(charge_id, params, connect_key = nil) ⇒ Object



24
25
26
27
# File 'lib/xfers/charge.rb', line 24

def self.validate(charge_id, params, connect_key=nil)
  raise InvalidRequestError.new 'Charge id cannot be empty', 400 if charge_id.nil? or charge_id == ''
  Xfers::APIOperations.post params, "#{RESOUCE_URL}/#{charge_id}/validate", connect_key
end