Module: Proxypay
- Includes:
- HTTParty
- Defined in:
- lib/proxypay.rb,
lib/proxypay/version.rb
Constant Summary collapse
- VERSION =
"0.2.3"
Class Method Summary collapse
-
.get_customer(id, options = {}) ⇒ Object
get a customer by id.
-
.get_customers(options = {}) ⇒ Object
Get a list of customers.
-
.get_payments(options = {}) ⇒ Object
Fetch all availables payments that have not been acknowledged.
-
.get_reference(id, options = {}) ⇒ Object
Fetch a specific reference by his ID string.
-
.get_references(options = {}) ⇒ Object
Fetch all available references.
-
.new_customer(id, nome, telemovel, email, options = {}) ⇒ Object
Store a new customer or update one.
-
.new_payment(id, options = {}) ⇒ Object
Acknowledge a payment by submitting his ID.
-
.new_payments(ids, options = {}) ⇒ Object
Acknowledge multiple payments by submitting an array of ids.
-
.new_reference(amount, expiry_date, options = {}) ⇒ Object
Submit a request to create a new reference.
- .set_base_url(is_test = false) ⇒ Object
Class Method Details
.get_customer(id, options = {}) ⇒ Object
get a customer by id
80 81 82 83 84 |
# File 'lib/proxypay.rb', line 80 def self.get_customer(id, = {}) set_base_url(.delete(:is_test)) = {:basic_auth => authenticate(.delete(:api_key))} get("/customers/#{id}", ).parsed_response end |
.get_customers(options = {}) ⇒ Object
Get a list of customers
69 70 71 72 73 74 75 76 77 |
# File 'lib/proxypay.rb', line 69 def self.get_customers( = {}) set_base_url(.delete(:is_test)) # request body and header content = {} content[:basic_auth] = authenticate(.delete(:api_key)) content[:headers] = {'Content-Type' => 'application/json'} content[:query] = .delete(:query) || {} get("/customers", content).parsed_response end |
.get_payments(options = {}) ⇒ Object
Fetch all availables payments that have not been acknowledged.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/proxypay.rb', line 40 def self.get_payments(={}) # Proxypay.get_payments(query: {limit: 20}, is_test: true, api_key: '0djwano5yth94ihrtw34ot9cehn9emo') set_base_url(.delete(:is_test)) # request body and header content = {} content[:basic_auth] = authenticate(.delete(:api_key)) content[:headers] = {'Content-Type' => 'application/json'} content[:query] = .delete(:query) || {} get("/events/payments", content).parsed_response end |
.get_reference(id, options = {}) ⇒ Object
Fetch a specific reference by his ID string
22 23 24 25 26 |
# File 'lib/proxypay.rb', line 22 def self.get_reference(id, = {}) set_base_url(.delete(:is_test)) = {:basic_auth => authenticate(.delete(:api_key))} get("/references/#{id}", ).parsed_response end |
.get_references(options = {}) ⇒ Object
Fetch all available references
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/proxypay.rb', line 10 def self.get_references( = {}) # Proxypay.get_references(query: {limit: 20}, is_test: true, api_key: '0djwano5yth94ihrtw34ot9cehn9emo') set_base_url(.delete(:is_test)) # request body and header content = {} content[:basic_auth] = authenticate(.delete(:api_key)) content[:headers] = {'Content-Type' => 'application/json'} content[:query] = .delete(:query) || {} get("/references", content).parsed_response end |
.new_customer(id, nome, telemovel, email, options = {}) ⇒ Object
Store a new customer or update one
87 88 89 90 91 92 93 94 |
# File 'lib/proxypay.rb', line 87 def self.new_customer(id, nome, telemovel, email, = {}) set_base_url(.delete(:is_test)) content = {} content[:basic_auth] = authenticate(.delete(:api_key)) content[:body] = {:customer => {:name => nome.to_s, :mobile => telemovel.to_s, :email => email.to_s}}.to_json content[:headers] = {'Content-Type' => 'application/json'} put("/customers/#{id}", content).parsed_response end |
.new_payment(id, options = {}) ⇒ Object
Acknowledge a payment by submitting his ID
52 53 54 55 56 |
# File 'lib/proxypay.rb', line 52 def self.new_payment(id, = {}) set_base_url(.delete(:is_test)) content = {:basic_auth => authenticate(.delete(:api_key))} delete("/events/payments/#{id}", content).parsed_response end |
.new_payments(ids, options = {}) ⇒ Object
Acknowledge multiple payments by submitting an array of ids
59 60 61 62 63 64 65 66 |
# File 'lib/proxypay.rb', line 59 def self.new_payments(ids, = {}) set_base_url(.delete(:is_test)) content = {} content[:body] = { :ids => ids }.to_json content[:basic_auth] = authenticate(.delete(:api_key)) content[:headers] = {'Content-Type' => 'application/json'} delete("/events/payments", content).parsed_response end |
.new_reference(amount, expiry_date, options = {}) ⇒ Object
Submit a request to create a new reference
29 30 31 32 33 34 35 36 37 |
# File 'lib/proxypay.rb', line 29 def self.new_reference(amount, expiry_date, ={}) # new_reference(78654.90, '12-12-2012', custom_fields: {foo: 'F0000-45', bar: 'MMM'}, api_key: 'ctsrxte56v8my_keyv7fuf676t7o89099y85ce6f', is_test: true) set_base_url(.delete(:is_test)) content = {} content[:basic_auth] = authenticate(.delete(:api_key)) content[:body] = {:reference => {:amount => amount.to_s, :expiry_date => expiry_date.to_s, custom_fields: (.delete(:custom_fields) || {})}}.to_json content[:headers] = {'Content-Type' => 'application/json'} post("/references", content).parsed_response end |
.set_base_url(is_test = false) ⇒ Object
96 97 98 |
# File 'lib/proxypay.rb', line 96 def self.set_base_url(is_test = false) self.base_uri is_test == true ? "https://api.proxypay.co.ao/tests" : "https://api.proxypay.co.ao" end |