mollie-api-ruby 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/1-new-payment.rb +43 -43
- data/examples/2-webhook-verification.rb +31 -31
- data/examples/3-return-page.rb +11 -11
- data/examples/4-ideal-payment.rb +63 -63
- data/examples/5-payments-history.rb +17 -17
- data/examples/6-list-activated-methods.rb +20 -20
- data/examples/7-refund-payment.rb +28 -28
- data/examples/app.rb +30 -30
- data/lib/Mollie/API/Client.rb +92 -92
- data/lib/Mollie/API/Exception.rb +6 -6
- data/lib/Mollie/API/Object/Base.rb +15 -15
- data/lib/Mollie/API/Object/Issuer.rb +10 -10
- data/lib/Mollie/API/Object/List.rb +30 -30
- data/lib/Mollie/API/Object/Method.rb +24 -24
- data/lib/Mollie/API/Object/Payment.rb +45 -33
- data/lib/Mollie/API/Object/Payment/Refund.rb +14 -14
- data/lib/Mollie/API/Resource/Base.rb +51 -51
- data/lib/Mollie/API/Resource/Issuers.rb +9 -9
- data/lib/Mollie/API/Resource/Methods.rb +9 -9
- data/lib/Mollie/API/Resource/Payments.rb +9 -9
- data/lib/Mollie/API/Resource/Payments/Refunds.rb +20 -20
- data/mollie.gemspec +1 -1
- metadata +3 -3
data/examples/app.rb
CHANGED
@@ -4,55 +4,55 @@ require 'sinatra'
|
|
4
4
|
# Show all examples as links.
|
5
5
|
#
|
6
6
|
examples = [
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
'1-new-payment',
|
8
|
+
'2-webhook-verification',
|
9
|
+
'3-return-page',
|
10
|
+
'4-ideal-payment',
|
11
|
+
'5-payments-history',
|
12
|
+
'6-list-activated-methods',
|
13
|
+
'7-refund-payment'
|
14
14
|
]
|
15
15
|
|
16
16
|
get "/" do
|
17
|
-
|
17
|
+
index = ""
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
examples.each { |example|
|
20
|
+
index << "<a href='/#{example}'>#{example}</a><br>"
|
21
|
+
}
|
22
22
|
|
23
|
-
|
23
|
+
index
|
24
24
|
end
|
25
25
|
|
26
26
|
#
|
27
27
|
# Register all examples as pages.
|
28
28
|
#
|
29
29
|
examples.each { |example|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
30
|
+
get "/#{example}" do
|
31
|
+
$request = request
|
32
|
+
$response = response
|
33
|
+
load File.expand_path "#{example}.rb", File.dirname(__FILE__)
|
34
|
+
end
|
35
|
+
|
36
|
+
post "/#{example}" do
|
37
|
+
$request = request
|
38
|
+
$response = response
|
39
|
+
load File.expand_path "#{example}.rb", File.dirname(__FILE__)
|
40
|
+
end
|
41
41
|
}
|
42
42
|
|
43
43
|
#
|
44
44
|
# NOTE: This example uses a text file as a database. Please use a real database like MySQL in production code.
|
45
45
|
#
|
46
46
|
def database_write (order_id, status)
|
47
|
-
|
48
|
-
|
47
|
+
order_id = order_id.to_i
|
48
|
+
database = File.expand_path "orders/order-#{order_id}.txt", File.dirname(__FILE__)
|
49
49
|
|
50
|
-
|
50
|
+
File.open(database, 'w') { |file| file.write status }
|
51
51
|
end
|
52
52
|
|
53
53
|
def database_read (order_id)
|
54
|
-
|
55
|
-
|
54
|
+
order_id = order_id.to_i
|
55
|
+
database = File.expand_path "orders/order-#{order_id}.txt", File.dirname(__FILE__)
|
56
56
|
|
57
|
-
|
58
|
-
end
|
57
|
+
status = File.read(database) || "unknown order"
|
58
|
+
end
|
data/lib/Mollie/API/Client.rb
CHANGED
@@ -15,96 +15,96 @@ require "rest_client"
|
|
15
15
|
"Object/Method"].each {|file| require File.expand_path file, File.dirname(__FILE__) }
|
16
16
|
|
17
17
|
module Mollie
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
18
|
+
module API
|
19
|
+
class Client
|
20
|
+
CLIENT_VERSION = "1.1.3"
|
21
|
+
API_ENDPOINT = "https://api.mollie.nl"
|
22
|
+
API_VERSION = "v1"
|
23
|
+
|
24
|
+
attr_reader :payments, :issuers, :methods, :payments_refunds
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
@payments = Mollie::API::Resource::Payments.new self
|
28
|
+
@issuers = Mollie::API::Resource::Issuers.new self
|
29
|
+
@methods = Mollie::API::Resource::Methods.new self
|
30
|
+
@payments_refunds = Mollie::API::Resource::Payments::Refunds.new self
|
31
|
+
|
32
|
+
@api_endpoint = API_ENDPOINT
|
33
|
+
@api_key = ""
|
34
|
+
@version_strings = []
|
35
|
+
|
36
|
+
addVersionString "Mollie/" << CLIENT_VERSION
|
37
|
+
addVersionString "Ruby/" << RUBY_VERSION
|
38
|
+
addVersionString OpenSSL::OPENSSL_VERSION.split(" ").slice(0, 2).join "/"
|
39
|
+
end
|
40
|
+
|
41
|
+
def setApiEndpoint(api_endpoint)
|
42
|
+
@api_endpoint = api_endpoint.chomp "/"
|
43
|
+
end
|
44
|
+
|
45
|
+
def getApiEndpoint
|
46
|
+
@api_endpoint
|
47
|
+
end
|
48
|
+
|
49
|
+
def setApiKey(api_key)
|
50
|
+
@api_key = api_key
|
51
|
+
end
|
52
|
+
|
53
|
+
def addVersionString(version_string)
|
54
|
+
@version_strings << (version_string.gsub /\s+/, "-")
|
55
|
+
end
|
56
|
+
|
57
|
+
def _getRestClient(request_url, request_headers)
|
58
|
+
RestClient::Resource.new request_url,
|
59
|
+
:headers => request_headers,
|
60
|
+
:ssl_ca_file => (File.expand_path "cacert.pem", File.dirname(__FILE__)),
|
61
|
+
:verify_ssl => OpenSSL::SSL::VERIFY_PEER
|
62
|
+
end
|
63
|
+
|
64
|
+
def performHttpCall(http_method, api_method, id = nil, http_body = nil)
|
65
|
+
request_headers = {
|
66
|
+
:accept => :json,
|
67
|
+
:authorization => "Bearer #{@api_key}",
|
68
|
+
:user_agent => @version_strings.join(" "),
|
69
|
+
"X-Mollie-Client-Info" => getUname
|
70
|
+
}
|
71
|
+
|
72
|
+
if http_body.respond_to? :delete_if
|
73
|
+
http_body.delete_if { |k, v| v.nil? }
|
74
|
+
end
|
75
|
+
|
76
|
+
begin
|
77
|
+
request_url = "#{@api_endpoint}/#{API_VERSION}/#{api_method}/#{id}".chomp "/"
|
78
|
+
rest_client = _getRestClient request_url, request_headers
|
79
|
+
|
80
|
+
case http_method
|
81
|
+
when "GET"
|
82
|
+
response = rest_client.get
|
83
|
+
when "POST"
|
84
|
+
response = rest_client.post http_body
|
85
|
+
when "DELETE"
|
86
|
+
response = rest_client.delete
|
87
|
+
end
|
88
|
+
response = JSON.parse response, :symbolize_names => true
|
89
|
+
rescue RestClient::ExceptionWithResponse => e
|
90
|
+
response = JSON.parse e.response, :symbolize_names => true
|
91
|
+
raise e if response[:error].nil?
|
92
|
+
end
|
93
|
+
|
94
|
+
unless response[:error].nil?
|
95
|
+
exception = Mollie::API::Exception.new response[:error][:message]
|
96
|
+
exception.field = response[:error][:field] unless response[:error][:field].nil?
|
97
|
+
raise exception
|
98
|
+
end
|
99
|
+
|
100
|
+
response
|
101
|
+
end
|
102
|
+
|
103
|
+
def getUname
|
104
|
+
`uname -a 2>/dev/null`.strip if RUBY_PLATFORM =~ /linux|darwin/i
|
105
|
+
rescue Errno::ENOMEM
|
106
|
+
"uname lookup failed"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
110
|
end
|
data/lib/Mollie/API/Exception.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
module Mollie
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
2
|
+
module API
|
3
|
+
module Object
|
4
|
+
class Base
|
5
|
+
def initialize(hash)
|
6
|
+
hash.each { |key, value|
|
7
|
+
if value.respond_to? :each
|
8
|
+
value = Base.new value
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
instance_variable_set "@#{key}", value
|
12
|
+
self.class.send :attr_accessor, key
|
13
|
+
}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
18
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module Mollie
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
2
|
+
module API
|
3
|
+
module Object
|
4
|
+
class Issuer < Base
|
5
|
+
attr_accessor :id,
|
6
|
+
:name,
|
7
|
+
:method
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,35 +1,35 @@
|
|
1
1
|
module Mollie
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module API
|
3
|
+
module Object
|
4
|
+
class List < Base
|
5
|
+
include Enumerable
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
attr_accessor :totalCount,
|
8
|
+
:offset,
|
9
|
+
:count,
|
10
|
+
:data
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def initialize(hash, classResourceObject)
|
13
|
+
data = hash[:data] || []
|
14
|
+
hash[:data] = nil
|
15
|
+
super hash
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
@data = []
|
18
|
+
data.each { |hash|
|
19
|
+
@data << (classResourceObject.new hash)
|
20
|
+
}
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
23
|
+
def each(&block)
|
24
|
+
@data.each { |object|
|
25
|
+
if block_given?
|
26
|
+
block.call object
|
27
|
+
else
|
28
|
+
yield object
|
29
|
+
end
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,29 +1,29 @@
|
|
1
1
|
module Mollie
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
2
|
+
module API
|
3
|
+
module Object
|
4
|
+
class Method < Base
|
5
|
+
IDEAL = "ideal"
|
6
|
+
CREDITCARD = "creditcard"
|
7
|
+
MISTERCASH = "mistercash"
|
8
|
+
BANKTRANSFER = "banktransfer"
|
9
|
+
PAYPAL = "paypal"
|
10
|
+
PAYSAFECARD = "paysafecard"
|
11
|
+
BITCOIN = "bitcoin"
|
12
|
+
SOFORT = "sofort"
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
attr_accessor :id,
|
15
|
+
:description,
|
16
|
+
:amount,
|
17
|
+
:image
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
def getMinimumAmount
|
20
|
+
@amount.minimum
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
def getMaximumAmount
|
24
|
+
@amount.maximum
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
29
|
end
|