mollie-api-ruby 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e715e8bb3f17bcb8273f8de4d317f8e997509f0e
|
4
|
+
data.tar.gz: ee5baaa31d4386ef9a6530b7d15f06eae22cde93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cccda5a9e67201819b9024e9764d254209b3d3e6647255b6683ecaea60484b0c52e3e56a3e0a588f29abfa8b1019bda486ceff136a6b2aef742e650f1c3a84ea
|
7
|
+
data.tar.gz: be187c4a79959128e3e41881c4fd67960ae27103224c4f1b493afb35c5a926e736ab07a00ee5ca6ae156b9b6b6b520dfd3b4734b3c71ba2e0091749f144f4d81
|
data/examples/1-new-payment.rb
CHANGED
@@ -3,53 +3,53 @@
|
|
3
3
|
#
|
4
4
|
require File.expand_path "../lib/Mollie/API/Client", File.dirname(__FILE__)
|
5
5
|
|
6
|
-
begin
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
begin
|
7
|
+
#
|
8
|
+
# Initialize the Mollie API library with your API key.
|
9
|
+
#
|
10
|
+
# See: https://www.mollie.nl/beheer/account/profielen/
|
11
|
+
#
|
12
|
+
mollie = Mollie::API::Client.new
|
13
|
+
mollie.setApiKey "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
#
|
16
|
+
# Generate a unique order id for this example. It is important to include this unique attribute
|
17
|
+
# in the redirectUrl (below) so a proper return page can be shown to the customer.
|
18
|
+
#
|
19
|
+
order_id = Time.now.to_i
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
#
|
22
|
+
# Determine the url parts to these example files.
|
23
|
+
#
|
24
|
+
protocol = $request.secure? && "https" || "http"
|
25
|
+
hostname = $request.host || "localhost"
|
26
|
+
port = $request.port || 80
|
27
|
+
path = $request.script_name || ""
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
29
|
+
#
|
30
|
+
# Payment parameters:
|
31
|
+
# amount Amount in EUROs. This example creates a € 10,- payment.
|
32
|
+
# description Description of the payment.
|
33
|
+
# redirectUrl Redirect location. The customer will be redirected there after the payment.
|
34
|
+
# metadata Custom metadata that is stored with the payment.
|
35
|
+
#
|
36
|
+
payment = mollie.payments.create \
|
37
|
+
:amount => 10.00,
|
38
|
+
:description => "My first API payment",
|
39
|
+
:redirectUrl => "#{protocol}://#{hostname}:#{port}#{path}/3-return-page?order_id=#{order_id}",
|
40
|
+
:metadata => {
|
41
|
+
:order_id => order_id
|
42
|
+
}
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
#
|
45
|
+
# In this example we store the order with its payment status in a database.
|
46
|
+
#
|
47
|
+
database_write order_id, payment.status
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
#
|
50
|
+
# Send the customer off to complete the payment.
|
51
|
+
#
|
52
|
+
$response.redirect payment.getPaymentUrl
|
53
53
|
rescue Mollie::API::Exception => e
|
54
|
-
|
54
|
+
$response.body << "API call failed: " << (CGI.escapeHTML e.message)
|
55
55
|
end
|
@@ -3,39 +3,39 @@
|
|
3
3
|
#
|
4
4
|
require File.expand_path "../lib/Mollie/API/Client", File.dirname(__FILE__)
|
5
5
|
|
6
|
-
begin
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
begin
|
7
|
+
#
|
8
|
+
# Initialize the Mollie API library with your API key.
|
9
|
+
#
|
10
|
+
# See: https://www.mollie.nl/beheer/account/profielen/
|
11
|
+
#
|
12
|
+
mollie = Mollie::API::Client.new
|
13
|
+
mollie.setApiKey "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
#
|
16
|
+
# Retrieve the payment's current state.
|
17
|
+
#
|
18
|
+
payment = mollie.payments.get $request.params['id']
|
19
|
+
order_id = payment.metadata.order_id
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
#
|
22
|
+
# Update the order in the database.
|
23
|
+
#
|
24
|
+
database_write order_id, payment.status
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
26
|
+
if payment.paid?
|
27
|
+
#
|
28
|
+
# At this point you'd probably want to start the process of delivering the product to the customer.
|
29
|
+
#
|
30
|
+
$response.body << "Paid"
|
31
|
+
elsif payment.open? == false
|
32
|
+
#
|
33
|
+
# The payment isn't paid and isn't open anymore. We can assume it was aborted.
|
34
|
+
#
|
35
|
+
$response.body << "Cancelled"
|
36
|
+
else
|
37
|
+
$response.body << "In progress"
|
38
|
+
end
|
39
39
|
rescue Mollie::API::Exception => e
|
40
|
-
|
40
|
+
$response.body << "API call failed: " << (CGI.escapeHTML e.message)
|
41
41
|
end
|
data/examples/3-return-page.rb
CHANGED
@@ -5,17 +5,17 @@
|
|
5
5
|
# Here, it's unnecessary to use the Mollie API Client.
|
6
6
|
#
|
7
7
|
if $request.params.empty?
|
8
|
-
|
8
|
+
$response.body << "No order"
|
9
9
|
else
|
10
|
-
|
10
|
+
status = database_read $request.params['order_id']
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
#
|
13
|
+
# Determine the url parts to these example files.
|
14
|
+
#
|
15
|
+
path = $request.script_name || ""
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
17
|
+
$response.body << "<p>Your payment status is '" << (CGI.escapeHTML status) << "'.</p>"
|
18
|
+
$response.body << "<p>"
|
19
|
+
$response.body << '<a href="' << path << '/">Back to examples</a><br>'
|
20
|
+
$response.body << "</p>"
|
21
|
+
end
|
data/examples/4-ideal-payment.rb
CHANGED
@@ -3,75 +3,75 @@
|
|
3
3
|
#
|
4
4
|
require File.expand_path "../lib/Mollie/API/Client", File.dirname(__FILE__)
|
5
5
|
|
6
|
-
begin
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
begin
|
7
|
+
#
|
8
|
+
# Initialize the Mollie API library with your API key.
|
9
|
+
#
|
10
|
+
# See: https://www.mollie.nl/beheer/account/profielen/
|
11
|
+
#
|
12
|
+
mollie = Mollie::API::Client.new
|
13
|
+
mollie.setApiKey "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
#
|
16
|
+
# First, let the customer pick the bank in a simple HTML form. This step is actually optional.
|
17
|
+
#
|
18
|
+
if $request.params.empty?
|
19
|
+
issuers = mollie.issuers.all
|
20
20
|
|
21
|
-
|
21
|
+
$response.body << '<form method="post">Select your bank: <select name="issuer">'
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
issuers.each { |issuer|
|
24
|
+
if issuer.method == Mollie::API::Object::Method::IDEAL
|
25
|
+
$response.body << '<option value=' << (CGI.escapeHTML issuer.id) << '>' << (CGI.escapeHTML issuer.name)
|
26
|
+
end
|
27
|
+
}
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
$response.body << '<option value="">or select later</option>'
|
30
|
+
$response.body << '</select><button>OK</button></form>'
|
31
|
+
else
|
32
|
+
#
|
33
|
+
# Generate a unique order id for this example. It is important to include this unique attribute
|
34
|
+
# in the redirectUrl (below) so a proper return page can be shown to the customer.
|
35
|
+
#
|
36
|
+
order_id = Time.now.to_i
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
#
|
39
|
+
# Determine the url parts to these example files.
|
40
|
+
#
|
41
|
+
protocol = $request.secure? && "https" || "http"
|
42
|
+
hostname = $request.host || "localhost"
|
43
|
+
port = $request.port || 80
|
44
|
+
path = $request.script_name || ""
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
#
|
66
|
-
# In this example we store the order with its payment status in a database.
|
67
|
-
#
|
68
|
-
database_write order_id, payment.status
|
46
|
+
#
|
47
|
+
# Payment parameters:
|
48
|
+
# amount Amount in EUROs. This example creates a € 27,50 payment.
|
49
|
+
# description Description of the payment.
|
50
|
+
# redirectUrl Redirect location. The customer will be redirected there after the payment.
|
51
|
+
# metadata Custom metadata that is stored with the payment.
|
52
|
+
# method Payment method "ideal".
|
53
|
+
# issuer The customer's bank. If empty the customer can select it later.
|
54
|
+
#
|
55
|
+
payment = mollie.payments.create \
|
56
|
+
:amount => 27.50,
|
57
|
+
:description => "My first API payment",
|
58
|
+
:redirectUrl => "#{protocol}://#{hostname}:#{port}#{path}/3-return-page?order_id=#{order_id}",
|
59
|
+
:metadata => {
|
60
|
+
:order_id => order_id
|
61
|
+
},
|
62
|
+
:method => Mollie::API::Object::Method::IDEAL,
|
63
|
+
:issuer => !$request.params['issuer'].empty? ? $request.params['issuer'] : nil
|
69
64
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
65
|
+
#
|
66
|
+
# In this example we store the order with its payment status in a database.
|
67
|
+
#
|
68
|
+
database_write order_id, payment.status
|
69
|
+
|
70
|
+
#
|
71
|
+
# Send the customer off to complete the payment.
|
72
|
+
#
|
73
|
+
$response.redirect payment.getPaymentUrl
|
74
|
+
end
|
75
75
|
rescue Mollie::API::Exception => e
|
76
|
-
|
76
|
+
$response.body << "API call failed: " << (CGI.escapeHTML e.message)
|
77
77
|
end
|
@@ -3,25 +3,25 @@
|
|
3
3
|
#
|
4
4
|
require File.expand_path "../lib/Mollie/API/Client", File.dirname(__FILE__)
|
5
5
|
|
6
|
-
begin
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
begin
|
7
|
+
#
|
8
|
+
# Initialize the Mollie API library with your API key.
|
9
|
+
#
|
10
|
+
# See: https://www.mollie.nl/beheer/account/profielen/
|
11
|
+
#
|
12
|
+
mollie = Mollie::API::Client.new
|
13
|
+
mollie.setApiKey "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
#
|
16
|
+
# Get the all payments for this API key ordered by newest.
|
17
|
+
#
|
18
|
+
payments = mollie.payments.all
|
19
19
|
|
20
|
-
|
20
|
+
$response.body = "Your API key has #{payments.totalCount} payments, last #{payments.count}:<br>"
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
payments.each { |payment|
|
23
|
+
$response.body << "€ #{payment.amount}, status: #{CGI.escapeHTML payment.status} (#{CGI.escapeHTML payment.id})<br>"
|
24
|
+
}
|
25
25
|
rescue Mollie::API::Exception => e
|
26
|
-
|
26
|
+
$response.body << "API call failed: " << (CGI.escapeHTML e.message)
|
27
27
|
end
|
@@ -3,28 +3,28 @@
|
|
3
3
|
#
|
4
4
|
require File.expand_path "../lib/Mollie/API/Client", File.dirname(__FILE__)
|
5
5
|
|
6
|
-
begin
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
begin
|
7
|
+
#
|
8
|
+
# Initialize the Mollie API library with your API key.
|
9
|
+
#
|
10
|
+
# See: https://www.mollie.nl/beheer/account/profielen/
|
11
|
+
#
|
12
|
+
mollie = Mollie::API::Client.new
|
13
|
+
mollie.setApiKey "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
#
|
16
|
+
# Get the all the activated methods for this API key.
|
17
|
+
#
|
18
|
+
methods = mollie.methods.all
|
19
19
|
|
20
|
-
|
20
|
+
$response.body << "Your API key has #{methods.totalCount} activated payment methods:<br>"
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
methods.each { |method|
|
23
|
+
$response.body << '<div style="line-height:40px; vertical-align:top">'
|
24
|
+
$response.body << '<img src="' << (CGI.escapeHTML method.image.normal) << '"> '
|
25
|
+
$response.body << (CGI.escapeHTML method.description) << ' (' << (CGI.escapeHTML method.id) << ')'
|
26
|
+
$response.body << '</div>'
|
27
|
+
}
|
28
28
|
rescue Mollie::API::Exception => e
|
29
|
-
|
29
|
+
$response.body << "API call failed: " << (CGI.escapeHTML e.message)
|
30
30
|
end
|
@@ -3,38 +3,38 @@
|
|
3
3
|
#
|
4
4
|
require File.expand_path "../lib/Mollie/API/Client", File.dirname(__FILE__)
|
5
5
|
|
6
|
-
begin
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
begin
|
7
|
+
#
|
8
|
+
# Initialize the Mollie API library with your API key.
|
9
|
+
#
|
10
|
+
# See: https://www.mollie.nl/beheer/account/profielen/
|
11
|
+
#
|
12
|
+
mollie = Mollie::API::Client.new
|
13
|
+
mollie.setApiKey "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
#
|
16
|
+
# Retrieve the payment you want to refund from the API.
|
17
|
+
#
|
18
|
+
payment = mollie.payments.get "tr_47uEE1su8q"
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
#
|
21
|
+
# Refund the payment.
|
22
|
+
#
|
23
|
+
refund = mollie.payments_refunds.with(payment).create
|
24
24
|
|
25
|
-
|
25
|
+
$response.body << "The payment #{payment.id} is now refunded.<br>"
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
#
|
28
|
+
# Retrieve refunds on a payment.
|
29
|
+
#
|
30
|
+
refunds = mollie.payments_refunds.with(payment).all
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
refunds.each { |refund|
|
33
|
+
$response.body << '<br> Refund date: ' << (CGI.escapeHTML refund.refundedDatetime)
|
34
|
+
$response.body << '<br> Refunded: € ' << (CGI.escapeHTML refund.amountRefunded)
|
35
|
+
$response.body << '<br> Remaining: € ' << (CGI.escapeHTML refund.amountRemaining)
|
36
|
+
$response.body << '<br>'
|
37
|
+
}
|
38
38
|
rescue Mollie::API::Exception => e
|
39
|
-
|
39
|
+
$response.body << "API call failed: " << (CGI.escapeHTML e.message)
|
40
40
|
end
|