Module: Xfers::Card

Defined in:
lib/xfers/card.rb

Constant Summary collapse

RESOURCE_URL =
'/cards'

Class Method Summary collapse

Class Method Details

.add(params) ⇒ Object



11
12
13
14
# File 'lib/xfers/card.rb', line 11

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

.charge_existing(charge_id) ⇒ Object



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

def self.charge_existing(charge_id)
  raise InvalidRequestError.new 'card_id id cannot be empty', 400 if charge_id.nil? or charge_id == ''
  params = {txn_id: charge_id}

  Xfers::APIOperations.post params, '/credit_card_charges/charge_card', nil
end

.charge_guest(params) ⇒ Object



30
31
32
33
# File 'lib/xfers/card.rb', line 30

def self.charge_guest(params)
  raise InvalidRequestError.new 'Params cannot be empty', 400 if params.nil? or params == ''
  Xfers::APIOperations.post params, '/credit_card_charges/charge_card_guest', nil
end

.delete(card_id, user_api_token) ⇒ Object



16
17
18
19
20
21
# File 'lib/xfers/card.rb', line 16

def self.delete(card_id, user_api_token)
  raise InvalidRequestError.new 'card_id id cannot be empty', 400 if card_id.nil? or card_id == ''
  raise InvalidRequestError.new 'user_api_token id cannot be empty', 400 if user_api_token.nil? or user_api_token == ''
  params = {user_api_token: user_api_token}
  Xfers::APIOperations.delete "#{RESOURCE_URL}/#{card_id}", nil, params
end

.list_all(user_api_token) ⇒ Object



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

def self.list_all(user_api_token)
  raise InvalidRequestError.new 'user_api_token cannot be empty', 400 if user_api_token.nil?
  url = "#{RESOURCE_URL}?user_api_token=#{user_api_token}"
  Xfers::APIOperations.get({}, url, nil)
end

.set_default(card_id, user_api_token) ⇒ Object



23
24
25
26
27
28
# File 'lib/xfers/card.rb', line 23

def self.set_default(card_id, user_api_token)
  raise InvalidRequestError.new 'card_id id cannot be empty', 400 if card_id.nil? or card_id == ''
  raise InvalidRequestError.new 'user_api_token id cannot be empty', 400 if user_api_token.nil? or user_api_token == ''
  params = {user_api_token: user_api_token}
  Xfers::APIOperations.post params, "#{RESOURCE_URL}/#{card_id}/set_default", nil
end