Class: Mpayer::Transaction

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

Instance Attribute Summary

Attributes inherited from Endpoint

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

Class 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

Class Method Details

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

Mpayer::Transaction.all(from: Time.zone.now - (86400*400))



7
8
9
10
11
12
# File 'lib/mpayer_ruby/endpoints/transaction.rb', line 7

def all(page:1,per_page:100,from: nil,to: nil)
	url = "/transactions/all"
	from = from.strftime("%F %T") unless from.nil?
	to = to.strftime("%F %T") unless to.nil? 
	Mpayer::Fetch.get(url,query:{page:page,per_page:per_page,from:from,to:to})
end

.deposit(**options) ⇒ Object

Mpayer::Transaction.deposit(body)



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

def deposit(**options)
	url = "/transactions/deposit"
	response = Mpayer::Fetch.put(url,mpayer_refs.merge!(options))
	transaction = new(id:response.id,response:response) rescue response
end

.mpayer_refsObject

Integrating app should get this from their db or just random unique



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

def mpayer_refs
	{ref_id: SecureRandom.uuid}
end

.transfer(**options) ⇒ Object

Mpayer::Transaction.transfer(body)



39
40
41
42
43
# File 'lib/mpayer_ruby/endpoints/transaction.rb', line 39

def transfer(**options)
	url = "/transactions/transfer"
	response = Mpayer::Fetch.post(url,mpayer_refs.merge!(options))
	transaction = new(id:response.id,response:response) rescue response
end

.where(ref_id:, fetch: true) ⇒ Object



15
16
17
18
19
# File 'lib/mpayer_ruby/endpoints/transaction.rb', line 15

def where(ref_id:,fetch:true)
	url = "/transactions/#{CGI.escape(ref_id.to_s)}"
	response = Mpayer::Fetch.get(url) if fetch
	transaction = new(id:response.id,response:response) rescue response
end

.withdraw(**options) ⇒ Object

Mpayer::Transaction.withdraw(body)



31
32
33
34
35
# File 'lib/mpayer_ruby/endpoints/transaction.rb', line 31

def withdraw(**options)
	url = "/transactions/withdraw"
	response = Mpayer::Fetch.delete(url,mpayer_refs.merge!(options))
	transaction = new(id:response.id,response:response) rescue response
end