Class: Mollie::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mollie/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Client

Returns a new instance of Client.



11
12
13
# File 'lib/mollie/client.rb', line 11

def initialize(api_key)
  self.api_key = api_key
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



9
10
11
# File 'lib/mollie/client.rb', line 9

def api_key
  @api_key
end

Instance Method Details

#auth_tokenObject



15
16
17
# File 'lib/mollie/client.rb', line 15

def auth_token
  "Bearer " + self.api_key
end

#issuersObject



35
36
37
38
39
40
41
42
43
# File 'lib/mollie/client.rb', line 35

def issuers
  response = self.class.get("/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



63
64
65
66
67
68
69
70
# File 'lib/mollie/client.rb', line 63

def payment_methods(method = nil)
  response = self.class.get("/methods/#{method}",
    :headers => {
      'Authorization' => auth_token
    }
  )
  JSON.parse(response.body)
end

#payment_status(payment_id) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/mollie/client.rb', line 45

def payment_status(payment_id)
  response = self.class.get("/payments/#{payment_id}",
    :headers => {
      'Authorization' => auth_token
    }
  )
  JSON.parse(response.body)
end

#prepare_payment(amount, description, redirect_url, metadata = {}, method = nil, method_params = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/mollie/client.rb', line 19

def prepare_payment(amount, description, redirect_url,  = {}, method=nil, method_params = {})
  response = self.class.post('/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) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/mollie/client.rb', line 54

def refund_payment(payment_id)
  response = self.class.post("/payments/#{payment_id}/refunds",
    :headers => {
      'Authorization' => auth_token
    }
  )
  JSON.parse(response.body)
end