Class: Mpayer::Client

Inherits:
Endpoint show all
Defined in:
lib/mpayer_ruby/endpoints/client.rb

Instance Attribute Summary collapse

Attributes inherited from Endpoint

#attributes, #config, #endpoint, #id, #pagination, #response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Endpoint

#initialize, #success?

Constructor Details

This class inherits a constructor from Mpayer::Endpoint

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Mpayer::Endpoint

Instance Attribute Details

#account(account_id = nil, client_id = id) ⇒ Object

Mpayer::Client.find(id:20284).account(accountsid)



32
33
34
35
36
37
38
39
40
41
# File 'lib/mpayer_ruby/endpoints/client.rb', line 32

def (=nil,client_id=id)
	 ||= @account.id rescue nil
	raise "Arguments missing: account_id or client_id" if client_id.nil? or .nil?
	url = "/clients/#{client_id}/accounts/#{}"
	if (@account.id ==  rescue false)
		@account ||= Mpayer::Fetch.get(url)
	else	
		@account = Mpayer::Fetch.get(url)
	end
end

#accounts(page: 1, per_page: 100) ⇒ Object

Mpayer::Client.find(26, fetch:false).accounts(page:1,per_page:100)



51
52
53
# File 'lib/mpayer_ruby/endpoints/client.rb', line 51

def accounts(page:1,per_page:100)
	find_all(page:page,per_page:per_page)
end

#payables(page: 1, per_page: 100) ⇒ Object

Mpayer::Client.find(26, fetch:false).payables(page:1,per_page:100)



56
57
58
# File 'lib/mpayer_ruby/endpoints/client.rb', line 56

def payables(page:1,per_page:100)
	find_all(page:page,per_page:per_page)
end

#transactions(account_id, page: 1, per_page: 100) ⇒ Object

Mpayer::Client.find(26, fetch:false).transactions(account_id, page:1,per_page:100)



61
62
63
# File 'lib/mpayer_ruby/endpoints/client.rb', line 61

def transactions(,page:1,per_page:100)
	find_all(page:page,per_page:per_page,account_id:)
end

Class Method Details

.all(page: 1, per_page: 100) ⇒ Object

Mpayer::Client.all



8
9
10
11
# File 'lib/mpayer_ruby/endpoints/client.rb', line 8

def all(page:1,per_page:100)
  url = "/clients/all_clients"
	Mpayer::Fetch.get(url,query:{page:page,per_page:per_page})
end

.create(options = {}) ⇒ Object

client_attributes = { client_name: “Kiki Lolo”, client_birthday: Time.zone.now.iso8601, client_type: “ext”, ac_type: “cu”,client_mobile: ‘073373932’, client_email: ‘[email protected]’,currency: “kes”, mandate:“s”, sub_type: “od” } Mpayer::Client.create(client_attributes)



22
23
24
25
26
27
# File 'lib/mpayer_ruby/endpoints/client.rb', line 22

def create(options={})
	url = "/clients"
	# bp
	response = Mpayer::Fetch.post(url,options)
	client = new(options.merge!(id:response.id ,response:response, account: response..first)) rescue response
end

.find(client_id, fetch: true) ⇒ Object

Mpayer::Client.find(id)



14
15
16
17
18
# File 'lib/mpayer_ruby/endpoints/client.rb', line 14

def find(client_id,fetch: true)
	url = "/clients/#{client_id}"
	response = Mpayer::Fetch.get(url) if fetch
	client = new(id:client_id,response:response)
end

Instance Method Details

#create_account(options = {}) ⇒ Object

Mpayer::Client.find(id:20284).create_account(options)



45
46
47
48
# File 'lib/mpayer_ruby/endpoints/client.rb', line 45

def (options={})
    url = "/clients/#{self.id}/accounts/new"
	@account = Mpayer::Fetch.post(url,options)
end