mollie-api-ruby 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +15 -2
- data/examples/apis/api_docs.rb +37 -0
- data/examples/apis/connect.rb +58 -0
- data/examples/apis/customers.rb +115 -0
- data/examples/apis/invoices.rb +38 -0
- data/examples/apis/issuers.rb +35 -0
- data/examples/apis/mandates.rb +83 -0
- data/examples/apis/methods.rb +50 -0
- data/examples/apis/organizations.rb +16 -0
- data/examples/apis/payments.rb +140 -0
- data/examples/apis/permissions.rb +32 -0
- data/examples/apis/profiles.rb +126 -0
- data/examples/apis/refunds.rb +17 -0
- data/examples/apis/settlements.rb +84 -0
- data/examples/apis/subscriptions.rb +165 -0
- data/examples/config.ru +58 -0
- data/examples/public/images/collapse.gif +0 -0
- data/examples/public/images/expand.gif +0 -0
- data/examples/public/images/explorer_icons.png +0 -0
- data/examples/public/images/favicon-16x16.png +0 -0
- data/examples/public/images/favicon-32x32.png +0 -0
- data/examples/public/images/favicon.ico +0 -0
- data/examples/public/images/logo_small.png +0 -0
- data/examples/public/images/pet_store_api.png +0 -0
- data/examples/public/images/throbber.gif +0 -0
- data/examples/public/images/wordnik_api.png +0 -0
- data/examples/public/index.html +101 -0
- data/examples/public/javascripts/lib/backbone-min.js +1 -0
- data/examples/public/javascripts/lib/es5-shim.js +1 -0
- data/examples/public/javascripts/lib/handlebars-4.0.5.js +3 -0
- data/examples/public/javascripts/lib/highlight.9.1.0.pack.js +1 -0
- data/examples/public/javascripts/lib/highlight.9.1.0.pack_extended.js +1 -0
- data/examples/public/javascripts/lib/jquery-1.8.0.min.js +3 -0
- data/examples/public/javascripts/lib/jquery.ba-bbq.min.js +1 -0
- data/examples/public/javascripts/lib/jquery.slideto.min.js +1 -0
- data/examples/public/javascripts/lib/jquery.wiggle.min.js +1 -0
- data/examples/public/javascripts/lib/js-yaml.min.js +2 -0
- data/examples/public/javascripts/lib/jsoneditor.min.js +5 -0
- data/examples/public/javascripts/lib/lodash.min.js +2 -0
- data/examples/public/javascripts/lib/marked.js +1 -0
- data/examples/public/javascripts/lib/object-assign-pollyfill.js +1 -0
- data/examples/public/javascripts/lib/sanitize-html.min.js +4 -0
- data/examples/public/javascripts/lib/swagger-oauth.js +1 -0
- data/examples/public/javascripts/swagger-ui.js +25378 -0
- data/examples/public/javascripts/swagger-ui.min.js +15 -0
- data/examples/public/javascripts/swagger_docs.js +14 -0
- data/examples/public/o2c.html +20 -0
- data/examples/public/stylesheets/reset.css +1 -0
- data/examples/public/stylesheets/screen.css +1545 -0
- data/examples/public/stylesheets/swagger_docs.css +4 -0
- data/examples/public/stylesheets/typography.css +0 -0
- data/lib/mollie/api/client.rb +42 -22
- data/lib/mollie/api/client/version.rb +1 -1
- data/lib/mollie/api/object/invoice.rb +70 -0
- data/lib/mollie/api/object/method.rb +1 -0
- data/lib/mollie/api/object/organization.rb +1 -1
- data/lib/mollie/api/object/payment.rb +21 -7
- data/lib/mollie/api/object/payment/refund.rb +5 -1
- data/lib/mollie/api/resource/base.rb +6 -6
- data/lib/mollie/api/resource/invoices.rb +11 -0
- data/lib/mollie/api/resource/permissions.rb +20 -0
- data/lib/mollie/api/resource/profiles/apikeys.rb +6 -0
- data/lib/mollie/api/resource/refunds.rb +11 -0
- data/lib/mollie/api/resource/settlements.rb +8 -0
- data/lib/mollie/api/resource/settlements/payments.rb +27 -0
- data/mollie.gemspec +7 -0
- data/test/mollie/api/client_test.rb +12 -5
- data/test/mollie/api/object/invoice_test.rb +59 -0
- data/test/mollie/api/object/organization_test.rb +0 -6
- data/test/mollie/api/object/payment_test.rb +15 -0
- data/test/mollie/api/resource/invoices_test.rb +13 -0
- metadata +159 -12
- data/examples/1-new-payment.rb +0 -56
- data/examples/2-webhook-verification.rb +0 -41
- data/examples/3-return-page.rb +0 -21
- data/examples/4-ideal-payment.rb +0 -79
- data/examples/5-payments-history.rb +0 -27
- data/examples/6-list-activated-methods.rb +0 -30
- data/examples/7-refund-payment.rb +0 -40
- data/examples/app.rb +0 -58
- data/examples/orders/.gitignore +0 -1
File without changes
|
data/lib/mollie/api/client.rb
CHANGED
@@ -2,6 +2,7 @@ require "json"
|
|
2
2
|
require "time"
|
3
3
|
require "ostruct"
|
4
4
|
require "bigdecimal"
|
5
|
+
require "net/https"
|
5
6
|
|
6
7
|
["exception",
|
7
8
|
"util",
|
@@ -11,20 +12,24 @@ require "bigdecimal"
|
|
11
12
|
"resource/customers/mandates",
|
12
13
|
"resource/customers/payments",
|
13
14
|
"resource/customers/subscriptions",
|
15
|
+
"resource/invoices",
|
14
16
|
"resource/issuers",
|
15
17
|
"resource/methods",
|
16
18
|
"resource/organizations",
|
17
19
|
"resource/payments",
|
18
20
|
"resource/payments/refunds",
|
21
|
+
"resource/refunds",
|
19
22
|
"resource/permissions",
|
20
23
|
"resource/profiles",
|
21
24
|
"resource/profiles/apikeys",
|
22
25
|
"resource/settlements",
|
26
|
+
"resource/settlements/payments",
|
23
27
|
"object/base",
|
24
28
|
"object/list",
|
25
29
|
"object/customer",
|
26
30
|
"object/customer/mandate",
|
27
31
|
"object/customer/subscription",
|
32
|
+
"object/invoice",
|
28
33
|
"object/issuer",
|
29
34
|
"object/method",
|
30
35
|
"object/organization",
|
@@ -46,8 +51,8 @@ module Mollie
|
|
46
51
|
|
47
52
|
attr_accessor :api_key
|
48
53
|
attr_reader :customers, :customers_payments, :customers_mandates, :customers_subscriptions,
|
49
|
-
:issuers, :methods, :organizations, :payments, :payments_refunds,
|
50
|
-
:permissions, :profiles, :profiles_api_keys, :settlements,
|
54
|
+
:issuers, :methods, :organizations, :payments, :payments_refunds, :refunds,
|
55
|
+
:permissions, :profiles, :profiles_api_keys, :settlements, :settlements_payments, :invoices,
|
51
56
|
:api_endpoint
|
52
57
|
|
53
58
|
def initialize(api_key)
|
@@ -60,10 +65,13 @@ module Mollie
|
|
60
65
|
@organizations = Mollie::API::Resource::Organizations.new self
|
61
66
|
@payments = Mollie::API::Resource::Payments.new self
|
62
67
|
@payments_refunds = Mollie::API::Resource::Payments::Refunds.new self
|
68
|
+
@refunds = Mollie::API::Resource::Refunds.new self
|
63
69
|
@permissions = Mollie::API::Resource::Permissions.new self
|
64
70
|
@profiles = Mollie::API::Resource::Profiles.new self
|
65
71
|
@profiles_api_keys = Mollie::API::Resource::Profiles::ApiKeys.new self
|
66
72
|
@settlements = Mollie::API::Resource::Settlements.new self
|
73
|
+
@settlements_payments = Mollie::API::Resource::Settlements::Payments.new self
|
74
|
+
@invoices = Mollie::API::Resource::Invoices.new self
|
67
75
|
|
68
76
|
@api_endpoint = API_ENDPOINT
|
69
77
|
@api_key = api_key
|
@@ -84,44 +92,56 @@ module Mollie
|
|
84
92
|
|
85
93
|
def perform_http_call(http_method, api_method, id = nil, http_body = {}, query = {})
|
86
94
|
path = "/#{API_VERSION}/#{api_method}/#{id}".chomp('/')
|
87
|
-
|
95
|
+
if query.length > 0
|
96
|
+
camelized_query = Util.camelize_keys(query)
|
97
|
+
path += "?#{URI.encode_www_form(camelized_query)}"
|
98
|
+
end
|
88
99
|
|
89
100
|
case http_method
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
101
|
+
when 'GET'
|
102
|
+
request = Net::HTTP::Get.new(path)
|
103
|
+
when 'POST'
|
104
|
+
http_body.delete_if { |k, v| v.nil? }
|
105
|
+
request = Net::HTTP::Post.new(path)
|
106
|
+
request.body = Util.camelize_keys(http_body).to_json
|
107
|
+
when 'DELETE'
|
108
|
+
http_body.delete_if { |k, v| v.nil? }
|
109
|
+
request = Net::HTTP::Delete.new(path)
|
110
|
+
request.body = Util.camelize_keys(http_body).to_json
|
111
|
+
else
|
112
|
+
raise Mollie::API::Exception.new("Invalid HTTP Method: #{http_method}")
|
100
113
|
end
|
101
114
|
|
102
115
|
request['Accept'] = 'application/json'
|
116
|
+
request['Content-Type'] = 'application/json'
|
103
117
|
request['Authorization'] = "Bearer #{@api_key}"
|
104
118
|
request['User-Agent'] = @version_strings.join(" ")
|
105
119
|
|
106
120
|
begin
|
107
121
|
response = client.request(request)
|
108
122
|
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
109
|
-
|
123
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
110
124
|
raise Mollie::API::Exception.new(e.message)
|
111
125
|
end
|
112
126
|
|
113
127
|
http_code = response.code.to_i
|
114
128
|
case http_code
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
129
|
+
when 200, 201
|
130
|
+
Util.nested_underscore_keys(JSON.parse(response.body))
|
131
|
+
when 204
|
132
|
+
{} # No Content
|
133
|
+
else
|
134
|
+
response = JSON.parse(response.body)
|
135
|
+
if response['error']
|
121
136
|
exception = Mollie::API::Exception.new response['error']['message']
|
122
|
-
exception.code = http_code
|
123
137
|
exception.field = response['error']['field'] unless response['error']['field'].nil?
|
124
|
-
|
138
|
+
elsif response['errors']
|
139
|
+
exception = Mollie::API::Exception.new response['errors'].values.join(", ")
|
140
|
+
else
|
141
|
+
exception = Mollie::API::Exception.new response.body
|
142
|
+
end
|
143
|
+
exception.code = http_code
|
144
|
+
raise exception
|
125
145
|
end
|
126
146
|
end
|
127
147
|
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Mollie
|
2
|
+
module API
|
3
|
+
module Object
|
4
|
+
class Invoice < Base
|
5
|
+
STATUS_OPEN = "open"
|
6
|
+
STATUS_PAID = "paid"
|
7
|
+
STATUS_OVERDUE = "overdue"
|
8
|
+
|
9
|
+
class Amount < Base
|
10
|
+
attr_accessor :net, :vat, :gross
|
11
|
+
|
12
|
+
def net=(net)
|
13
|
+
@net = BigDecimal.new(net.to_s)
|
14
|
+
end
|
15
|
+
|
16
|
+
def vat=(vat)
|
17
|
+
@vat = BigDecimal.new(vat.to_s, 2)
|
18
|
+
end
|
19
|
+
|
20
|
+
def gross=(gross)
|
21
|
+
@gross = BigDecimal.new(gross.to_s)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Line < Base
|
26
|
+
attr_accessor :period, :description, :count, :vat_percentage, :amount
|
27
|
+
|
28
|
+
def amount=(amount)
|
29
|
+
@amount = BigDecimal.new(amount.to_s)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
attr_accessor :resource, :id, :reference, :vat_number, :status,
|
34
|
+
:issue_date, :due_date, :amount, :lines, :links
|
35
|
+
|
36
|
+
def open?
|
37
|
+
status == STATUS_OPEN
|
38
|
+
end
|
39
|
+
|
40
|
+
def paid?
|
41
|
+
status == STATUS_PAID
|
42
|
+
end
|
43
|
+
|
44
|
+
def overdue?
|
45
|
+
status == STATUS_OVERDUE
|
46
|
+
end
|
47
|
+
|
48
|
+
def amount=(amount)
|
49
|
+
@amount = Amount.new(amount)
|
50
|
+
end
|
51
|
+
|
52
|
+
def issue_date=(issue_date)
|
53
|
+
@issue_date = Time.parse(issue_date) rescue nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def due_date=(due_date)
|
57
|
+
@due_date = Time.parse(due_date) rescue nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def lines=(lines)
|
61
|
+
@lines = lines.map { |line| Line.new(line) }
|
62
|
+
end
|
63
|
+
|
64
|
+
def pdf
|
65
|
+
links && links['pdf']
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -16,7 +16,7 @@ module Mollie
|
|
16
16
|
:verified_datetime
|
17
17
|
|
18
18
|
def registration_datetime=(registration_datetime)
|
19
|
-
@registration_datetime = Time.parse(registration_datetime.to_s)
|
19
|
+
@registration_datetime = Time.parse(registration_datetime.to_s) rescue nil
|
20
20
|
end
|
21
21
|
|
22
22
|
def verified_datetime=(verified_datetime)
|
@@ -2,13 +2,15 @@ module Mollie
|
|
2
2
|
module API
|
3
3
|
module Object
|
4
4
|
class Payment < Base
|
5
|
-
STATUS_OPEN
|
6
|
-
STATUS_CANCELLED
|
7
|
-
STATUS_EXPIRED
|
8
|
-
STATUS_PAID
|
9
|
-
STATUS_PAIDOUT
|
10
|
-
STATUS_FAILED
|
11
|
-
STATUS_REFUNDED
|
5
|
+
STATUS_OPEN = "open"
|
6
|
+
STATUS_CANCELLED = "cancelled"
|
7
|
+
STATUS_EXPIRED = "expired"
|
8
|
+
STATUS_PAID = "paid"
|
9
|
+
STATUS_PAIDOUT = "paidout"
|
10
|
+
STATUS_FAILED = "failed"
|
11
|
+
STATUS_REFUNDED = "refunded"
|
12
|
+
STATUS_PENDING = "pending"
|
13
|
+
STATUS_CHARGED_BACK = "charged_back"
|
12
14
|
|
13
15
|
RECURRINGTYPE_NONE = nil
|
14
16
|
RECURRINGTYPE_FIRST = "first"
|
@@ -62,6 +64,18 @@ module Mollie
|
|
62
64
|
status == STATUS_REFUNDED
|
63
65
|
end
|
64
66
|
|
67
|
+
def failed?
|
68
|
+
status == STATUS_FAILED
|
69
|
+
end
|
70
|
+
|
71
|
+
def pending?
|
72
|
+
status == STATUS_PENDING
|
73
|
+
end
|
74
|
+
|
75
|
+
def charged_back?
|
76
|
+
status == STATUS_CHARGED_BACK
|
77
|
+
end
|
78
|
+
|
65
79
|
def details=(details)
|
66
80
|
@details = OpenStruct.new(details) if details.is_a?(Hash)
|
67
81
|
end
|
@@ -3,6 +3,7 @@ module Mollie
|
|
3
3
|
module Object
|
4
4
|
class Payment
|
5
5
|
class Refund < Base
|
6
|
+
STATUS_QUEUED = "queued"
|
6
7
|
STATUS_PENDING = "pending"
|
7
8
|
STATUS_PROCESSING = "processing"
|
8
9
|
STATUS_REFUNDED = "refunded"
|
@@ -12,7 +13,10 @@ module Mollie
|
|
12
13
|
:amount,
|
13
14
|
:status,
|
14
15
|
:refunded_datetime
|
15
|
-
|
16
|
+
def queued?
|
17
|
+
status == STATUS_QUEUED
|
18
|
+
end
|
19
|
+
|
16
20
|
def pending?
|
17
21
|
status == STATUS_PENDING
|
18
22
|
end
|
@@ -16,8 +16,8 @@ module Mollie
|
|
16
16
|
}
|
17
17
|
end
|
18
18
|
|
19
|
-
def get(id)
|
20
|
-
request("GET", id, {}) { |response|
|
19
|
+
def get(id, options = {})
|
20
|
+
request("GET", id, {}, options) { |response|
|
21
21
|
new_resource_object response
|
22
22
|
}
|
23
23
|
end
|
@@ -28,12 +28,12 @@ module Mollie
|
|
28
28
|
}
|
29
29
|
end
|
30
30
|
|
31
|
-
def delete(id)
|
32
|
-
request "DELETE", id,
|
31
|
+
def delete(id, options = {})
|
32
|
+
request "DELETE", id, options
|
33
33
|
end
|
34
34
|
|
35
|
-
def all(offset = 0, limit = 50)
|
36
|
-
request("GET", nil, {}, { offset: offset, count: limit }) { |response|
|
35
|
+
def all(offset = 0, limit = 50, options = {})
|
36
|
+
request("GET", nil, {}, { offset: offset, count: limit }.merge(options)) { |response|
|
37
37
|
Object::List.new response, resource_object
|
38
38
|
}
|
39
39
|
end
|
@@ -2,6 +2,26 @@ module Mollie
|
|
2
2
|
module API
|
3
3
|
module Resource
|
4
4
|
class Permissions < Base
|
5
|
+
def self.available
|
6
|
+
%w(
|
7
|
+
payments.read
|
8
|
+
payments.write
|
9
|
+
refunds.read
|
10
|
+
refunds.write
|
11
|
+
customers.read
|
12
|
+
customers.write
|
13
|
+
mandates.read
|
14
|
+
mandates.write
|
15
|
+
subscriptions.read
|
16
|
+
subscriptions.write
|
17
|
+
profiles.read
|
18
|
+
profiles.write
|
19
|
+
invoices.read
|
20
|
+
settlements.read
|
21
|
+
organizations.read
|
22
|
+
organizations.write)
|
23
|
+
end
|
24
|
+
|
5
25
|
def resource_object
|
6
26
|
Object::Permission
|
7
27
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
module API
|
5
|
+
module Resource
|
6
|
+
class Settlements
|
7
|
+
class Payments < Base
|
8
|
+
@settlement_id = nil
|
9
|
+
|
10
|
+
def resource_object
|
11
|
+
Object::Payment
|
12
|
+
end
|
13
|
+
|
14
|
+
def resource_name
|
15
|
+
settlement_id = URI::encode(@settlement_id)
|
16
|
+
"settlements/#{settlement_id}/payments"
|
17
|
+
end
|
18
|
+
|
19
|
+
def with(settlement_or_id)
|
20
|
+
@settlement_id = settlement_or_id.is_a?(Object::Settlement) ? settlement_or_id.id : settlement_or_id
|
21
|
+
self
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/mollie.gemspec
CHANGED
@@ -23,4 +23,11 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency("rake")
|
24
24
|
s.add_development_dependency("test-unit")
|
25
25
|
s.add_development_dependency("webmock")
|
26
|
+
s.add_development_dependency("thin")
|
27
|
+
s.add_development_dependency("sinatra")
|
28
|
+
s.add_development_dependency("sinatra-contrib")
|
29
|
+
s.add_development_dependency("sinatra-cross_origin")
|
30
|
+
s.add_development_dependency("rack-oauth2")
|
31
|
+
s.add_development_dependency("swagger-blocks")
|
32
|
+
s.add_development_dependency("ngrok-tunnel")
|
26
33
|
end
|