Class: MollieApi::Client
- Inherits:
-
Object
- Object
- MollieApi::Client
- Includes:
- HTTParty
- Defined in:
- lib/mollie_api/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
Instance Method Summary collapse
- #auth_token ⇒ Object
-
#initialize(api_key, api_version = 'v1') ⇒ Client
constructor
A new instance of Client.
- #issuers ⇒ Object
- #payment_methods(method = nil) ⇒ Object
- #payment_status(payment_id) ⇒ Object
- #prepare_payment(amount, description, redirect_url, metadata = {}, method = nil, method_params = {}) ⇒ Object
- #refund_payment(payment_id, params = {}) ⇒ Object
Constructor Details
#initialize(api_key, api_version = 'v1') ⇒ Client
Returns a new instance of Client.
11 12 13 14 |
# File 'lib/mollie_api/client.rb', line 11 def initialize(api_key, api_version = 'v1') self.api_key = api_key self.api_version = api_version end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/mollie_api/client.rb', line 9 def api_key @api_key end |
#api_version ⇒ Object
Returns the value of attribute api_version.
9 10 11 |
# File 'lib/mollie_api/client.rb', line 9 def api_version @api_version end |
Instance Method Details
#auth_token ⇒ Object
16 17 18 |
# File 'lib/mollie_api/client.rb', line 16 def auth_token "Bearer " + self.api_key end |
#issuers ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/mollie_api/client.rb', line 36 def issuers response = self.class.get("/#{self.api_version}/issuers", :headers => { 'Authorization' => auth_token } ) response = JSON.parse(response.body) response["data"].map {|issuer| {id: issuer["id"], name: issuer["name"]} } end |
#payment_methods(method = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mollie_api/client.rb', line 65 def payment_methods(method = nil) if method url = "/#{self.api_version}/methods/#{method}" else url = "/#{self.api_version}/methods" end response = self.class.get(url, :headers => { 'Authorization' => auth_token } ) JSON.parse(response.body) end |
#payment_status(payment_id) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/mollie_api/client.rb', line 46 def payment_status(payment_id) response = self.class.get("/#{self.api_version}/payments/#{payment_id}", :headers => { 'Authorization' => auth_token } ) JSON.parse(response.body) end |
#prepare_payment(amount, description, redirect_url, metadata = {}, method = nil, method_params = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mollie_api/client.rb', line 20 def prepare_payment(amount, description, redirect_url, = {}, method=nil, method_params = {}) response = self.class.post("/#{self.api_version}/payments", :body => { :amount => amount, :description => description, :redirectUrl => redirect_url, :metadata => , :method => method }.merge(method_params), :headers => { 'Authorization' => auth_token } ) JSON.parse(response.body) end |
#refund_payment(payment_id, params = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/mollie_api/client.rb', line 55 def refund_payment(payment_id, params = {}) response = self.class.post("/#{self.api_version}/payments/#{payment_id}/refunds", :query => params, :headers => { 'Authorization' => auth_token } ) JSON.parse(response.body) end |