Module: Proxypay

Includes:
HTTParty
Defined in:
lib/proxypay.rb,
lib/proxypay/version.rb

Constant Summary collapse

VERSION =
"0.2.6"

Class Method Summary collapse

Class Method Details

.get_customer(id, options = {}) ⇒ Object

get a customer by id



64
65
66
67
68
# File 'lib/proxypay.rb', line 64

def self.get_customer(id, options = {})
  set_base_url(options.delete(:is_test))
  content = set_headers(options)
  get("/customers/#{id}", content).parsed_response
end

.get_customers(options = {}) ⇒ Object

Get a list of customers



56
57
58
59
60
61
# File 'lib/proxypay.rb', line 56

def self.get_customers(options = {})
  set_base_url(options.delete(:is_test))
  content = set_headers(options)
  content[:query] = options.delete(:query) || {}
  get("/customers", content).parsed_response
end

.get_payments(options = {}) ⇒ Object

Fetch all availables payments that have not been acknowledged.



33
34
35
36
37
38
# File 'lib/proxypay.rb', line 33

def self.get_payments(options={})
  set_base_url(options.delete(:is_test))
  content = set_headers(options)
  content[:query] = options.delete(:query) || {}
  get("/events/payments", content).parsed_response
end

.get_reference(id, options = {}) ⇒ Object

Fetch a specific reference by his ID string



18
19
20
21
22
# File 'lib/proxypay.rb', line 18

def self.get_reference(id, options = {})
  set_base_url(options.delete(:is_test))
  content = set_headers(options)
  get("/references/#{id}", content).parsed_response
end

.get_references(options = {}) ⇒ Object

Fetch all available references



10
11
12
13
14
15
# File 'lib/proxypay.rb', line 10

def self.get_references(options = {})
  set_base_url(options.delete(:is_test))
  content = set_headers(options)
  content[:query] = options.delete(:query) || {}
  get("/references", content).parsed_response
end

.new_customer(id, nome, telemovel, email, options = {}) ⇒ Object

Store a new customer or update one



71
72
73
74
75
76
# File 'lib/proxypay.rb', line 71

def self.new_customer(id, nome, telemovel, email, options = {})
  set_base_url(options.delete(:is_test))
  content = set_headers(options)
  content[:body] = {:customer => {:name => nome.to_s, :mobile => telemovel.to_s, :email => email.to_s}}.to_json
  put("/customers/#{id}", content).parsed_response
end

.new_payment(id, options = {}) ⇒ Object

Acknowledge a payment by submitting his ID



41
42
43
44
45
# File 'lib/proxypay.rb', line 41

def self.new_payment(id, options = {})
  set_base_url(options.delete(:is_test))
  content = set_headers(options)
  delete("/events/payments/#{id}", content).parsed_response
end

.new_payments(ids, options = {}) ⇒ Object

Acknowledge multiple payments by submitting an array of ids



48
49
50
51
52
53
# File 'lib/proxypay.rb', line 48

def self.new_payments(ids, options = {})
  set_base_url(options.delete(:is_test))
  content = set_headers(options)
  content[:body] = { :ids => ids }.to_json
  delete("/events/payments", content).parsed_response
end

.new_reference(amount, expiry_date, options = {}) ⇒ Object

Submit a request to create a new reference



25
26
27
28
29
30
# File 'lib/proxypay.rb', line 25

def self.new_reference(amount, expiry_date, options={})
  set_base_url(options.delete(:is_test))
  content = set_headers(options)
  content[:body] = {:reference => {:amount => amount.to_s, :expiry_date => expiry_date.to_s, custom_fields: (options.delete(:custom_fields) || {})}}.to_json
  post("/references", content).parsed_response
end

.set_base_url(is_test = false) ⇒ Object



78
79
80
# File 'lib/proxypay.rb', line 78

def self.set_base_url(is_test = false)
  self.base_uri is_test == true ? "https://api.sandbox.proxypay.co.ao" : "https://api.proxypay.co.ao"
end