mollie-api-ruby 2.2.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +7 -0
- data/README.md +37 -8
- data/examples/apis/api_docs.rb +1 -1
- data/examples/apis/chargebacks.rb +17 -0
- data/examples/apis/connect.rb +1 -1
- data/examples/apis/customers.rb +7 -6
- data/examples/apis/invoices.rb +2 -2
- data/examples/apis/issuers.rb +2 -2
- data/examples/apis/mandates.rb +5 -5
- data/examples/apis/methods.rb +2 -2
- data/examples/apis/organizations.rb +1 -1
- data/examples/apis/payments.rb +43 -9
- data/examples/apis/permissions.rb +2 -2
- data/examples/apis/profiles.rb +7 -7
- data/examples/apis/refunds.rb +1 -1
- data/examples/apis/settlements.rb +5 -5
- data/examples/apis/subscriptions.rb +7 -7
- data/examples/config.ru +6 -7
- data/lib/{mollie/api/cacert.pem → cacert.pem} +0 -0
- data/lib/mollie-api-ruby.rb +1 -0
- data/lib/mollie.rb +39 -0
- data/lib/mollie/base.rb +91 -0
- data/lib/mollie/chargeback.rb +36 -0
- data/lib/mollie/client.rb +125 -0
- data/lib/mollie/customer.rb +36 -0
- data/lib/mollie/customer/mandate.rb +33 -0
- data/lib/mollie/customer/payment.rb +6 -0
- data/lib/mollie/customer/subscription.rb +65 -0
- data/lib/mollie/exception.rb +8 -0
- data/lib/mollie/invoice.rb +66 -0
- data/lib/mollie/issuer.rb +5 -0
- data/lib/mollie/list.rb +40 -0
- data/lib/mollie/method.rb +38 -0
- data/lib/mollie/organization.rb +24 -0
- data/lib/mollie/payment.rb +142 -0
- data/lib/mollie/payment/chargeback.rb +6 -0
- data/lib/mollie/payment/refund.rb +6 -0
- data/lib/mollie/permission.rb +26 -0
- data/lib/mollie/profile.rb +78 -0
- data/lib/mollie/profile/api_key.rb +19 -0
- data/lib/mollie/refund.rb +42 -0
- data/lib/mollie/relation.rb +36 -0
- data/lib/mollie/settlement.rb +36 -0
- data/lib/mollie/settlement/chargeback.rb +6 -0
- data/lib/mollie/settlement/payment.rb +6 -0
- data/lib/mollie/settlement/refund.rb +6 -0
- data/lib/mollie/util.rb +57 -0
- data/lib/mollie/version.rb +3 -0
- data/mollie.gemspec +2 -2
- data/test/helper.rb +5 -1
- data/test/mollie/base_test.rb +182 -0
- data/test/mollie/chargeback_test.rb +35 -0
- data/test/mollie/client_test.rb +122 -0
- data/test/mollie/customer/mandate_test.rb +43 -0
- data/test/mollie/customer/payment_test.rb +23 -0
- data/test/mollie/customer/subscription_test.rb +66 -0
- data/test/mollie/customer_test.rb +128 -0
- data/test/mollie/invoice_test.rb +55 -0
- data/test/mollie/issuer_test.rb +19 -0
- data/test/mollie/list_test.rb +40 -0
- data/test/mollie/method_test.rb +29 -0
- data/test/mollie/organization_test.rb +41 -0
- data/test/mollie/payment/chargeback_test.rb +22 -0
- data/test/mollie/payment/refund_test.rb +22 -0
- data/test/mollie/payment_test.rb +161 -0
- data/test/mollie/permission_test.rb +21 -0
- data/test/mollie/profile/apikey_test.rb +31 -0
- data/test/mollie/profile_test.rb +98 -0
- data/test/mollie/refund_test.rb +40 -0
- data/test/mollie/settlement/chargeback_test.rb +22 -0
- data/test/mollie/settlement/payment_test.rb +22 -0
- data/test/mollie/settlement/refund_test.rb +22 -0
- data/test/mollie/settlement_test.rb +156 -0
- data/website-docs/chargebacks/list-all.rb +12 -0
- data/website-docs/connect/authorize.rb +15 -0
- data/website-docs/connect/tokens.rb +14 -0
- data/website-docs/customers/create-payment.rb +13 -0
- data/website-docs/customers/create.rb +12 -0
- data/website-docs/customers/delete.rb +10 -0
- data/website-docs/customers/get.rb +10 -0
- data/website-docs/customers/list-payments.rb +10 -0
- data/website-docs/customers/list.rb +12 -0
- data/website-docs/customers/update.rb +11 -0
- data/website-docs/invoices/get.rb +10 -0
- data/website-docs/invoices/list.rb +12 -0
- data/website-docs/issuers/get.rb +10 -0
- data/website-docs/issuers/list.rb +12 -0
- data/website-docs/mandates/create.rb +16 -0
- data/website-docs/mandates/delete.rb +10 -0
- data/website-docs/mandates/get.rb +10 -0
- data/website-docs/mandates/list.rb +12 -0
- data/website-docs/methods/get.rb +10 -0
- data/website-docs/methods/list.rb +12 -0
- data/website-docs/organisations/get.rb +10 -0
- data/website-docs/payments/create-refund.rb +14 -0
- data/website-docs/payments/create.rb +16 -0
- data/website-docs/payments/delete-refund.rb +13 -0
- data/website-docs/payments/delete.rb +12 -0
- data/website-docs/payments/get-chargeback.rb +11 -0
- data/website-docs/payments/get-refund.rb +11 -0
- data/website-docs/payments/get.rb +10 -0
- data/website-docs/payments/list-chargeback.rb +13 -0
- data/website-docs/payments/list-refunds.rb +13 -0
- data/website-docs/payments/list.rb +12 -0
- data/website-docs/payments/payment-webhook.rb +21 -0
- data/website-docs/permissions/get.rb +10 -0
- data/website-docs/permissions/list.rb +12 -0
- data/website-docs/profiles/create.rb +15 -0
- data/website-docs/profiles/delete.rb +10 -0
- data/website-docs/profiles/get-key.rb +11 -0
- data/website-docs/profiles/get.rb +10 -0
- data/website-docs/profiles/list-keys.rb +13 -0
- data/website-docs/profiles/list.rb +12 -0
- data/website-docs/profiles/reset-key.rb +13 -0
- data/website-docs/profiles/update.rb +12 -0
- data/website-docs/refunds/list.rb +12 -0
- data/website-docs/settlements/get.rb +10 -0
- data/website-docs/settlements/list-chargebacks.rb +13 -0
- data/website-docs/settlements/list-payments.rb +13 -0
- data/website-docs/settlements/list-refunds.rb +13 -0
- data/website-docs/settlements/list.rb +12 -0
- data/website-docs/settlements/next.rb +9 -0
- data/website-docs/settlements/open.rb +9 -0
- data/website-docs/subscriptions/create.rb +14 -0
- data/website-docs/subscriptions/delete.rb +10 -0
- data/website-docs/subscriptions/get.rb +10 -0
- data/website-docs/subscriptions/list.rb +12 -0
- metadata +134 -104
- data/lib/mollie/api/client.rb +0 -161
- data/lib/mollie/api/client/version.rb +0 -7
- data/lib/mollie/api/exception.rb +0 -10
- data/lib/mollie/api/object/base.rb +0 -18
- data/lib/mollie/api/object/customer.rb +0 -28
- data/lib/mollie/api/object/customer/mandate.rb +0 -37
- data/lib/mollie/api/object/customer/subscription.rb +0 -69
- data/lib/mollie/api/object/invoice.rb +0 -70
- data/lib/mollie/api/object/issuer.rb +0 -9
- data/lib/mollie/api/object/list.rb +0 -44
- data/lib/mollie/api/object/method.rb +0 -42
- data/lib/mollie/api/object/organization.rb +0 -28
- data/lib/mollie/api/object/payment.rb +0 -137
- data/lib/mollie/api/object/payment/refund.rb +0 -47
- data/lib/mollie/api/object/permission.rb +0 -12
- data/lib/mollie/api/object/profile.rb +0 -78
- data/lib/mollie/api/object/profile/apikey.rb +0 -23
- data/lib/mollie/api/object/settlement.rb +0 -32
- data/lib/mollie/api/resource/base.rb +0 -53
- data/lib/mollie/api/resource/customers.rb +0 -11
- data/lib/mollie/api/resource/customers/mandates.rb +0 -27
- data/lib/mollie/api/resource/customers/payments.rb +0 -27
- data/lib/mollie/api/resource/customers/subscriptions.rb +0 -27
- data/lib/mollie/api/resource/invoices.rb +0 -11
- data/lib/mollie/api/resource/issuers.rb +0 -11
- data/lib/mollie/api/resource/methods.rb +0 -11
- data/lib/mollie/api/resource/organizations.rb +0 -11
- data/lib/mollie/api/resource/payments.rb +0 -11
- data/lib/mollie/api/resource/payments/refunds.rb +0 -27
- data/lib/mollie/api/resource/permissions.rb +0 -31
- data/lib/mollie/api/resource/profiles.rb +0 -11
- data/lib/mollie/api/resource/profiles/apikeys.rb +0 -33
- data/lib/mollie/api/resource/refunds.rb +0 -11
- data/lib/mollie/api/resource/settlements.rb +0 -19
- data/lib/mollie/api/resource/settlements/payments.rb +0 -27
- data/lib/mollie/api/util.rb +0 -53
- data/test/mollie/api/client_test.rb +0 -111
- data/test/mollie/api/object/base_test.rb +0 -21
- data/test/mollie/api/object/customer/mandate_test.rb +0 -47
- data/test/mollie/api/object/customer/subscription_test.rb +0 -70
- data/test/mollie/api/object/customer_test.rb +0 -35
- data/test/mollie/api/object/invoice_test.rb +0 -59
- data/test/mollie/api/object/issuer_test.rb +0 -23
- data/test/mollie/api/object/list_test.rb +0 -44
- data/test/mollie/api/object/method_test.rb +0 -33
- data/test/mollie/api/object/organization_test.rb +0 -45
- data/test/mollie/api/object/payment/refund_test.rb +0 -46
- data/test/mollie/api/object/payment_test.rb +0 -106
- data/test/mollie/api/object/permission_test.rb +0 -25
- data/test/mollie/api/object/profile/apikey_test.rb +0 -35
- data/test/mollie/api/object/profile_test.rb +0 -72
- data/test/mollie/api/object/settlement_test.rb +0 -140
- data/test/mollie/api/resource/base_test.rb +0 -83
- data/test/mollie/api/resource/customers/mandates_test.rb +0 -23
- data/test/mollie/api/resource/customers/payments_test.rb +0 -23
- data/test/mollie/api/resource/customers/subscriptions_test.rb +0 -23
- data/test/mollie/api/resource/customers_test.rb +0 -13
- data/test/mollie/api/resource/invoices_test.rb +0 -13
- data/test/mollie/api/resource/issuers_test.rb +0 -13
- data/test/mollie/api/resource/methods_test.rb +0 -13
- data/test/mollie/api/resource/organizations_test.rb +0 -13
- data/test/mollie/api/resource/payments/refunds_test.rb +0 -23
- data/test/mollie/api/resource/payments_test.rb +0 -13
- data/test/mollie/api/resource/permissions_test.rb +0 -13
- data/test/mollie/api/resource/profiles/apikeys_test.rb +0 -23
- data/test/mollie/api/resource/profiles_test.rb +0 -13
- data/test/mollie/api/resource/settlements_test.rb +0 -13
- data/test/mollie/api/util_test.rb +0 -47
data/examples/apis/refunds.rb
CHANGED
@@ -11,7 +11,7 @@ class Application < Sinatra::Application
|
|
11
11
|
end
|
12
12
|
|
13
13
|
get '/v1/refunds' do
|
14
|
-
refunds =
|
14
|
+
refunds = Mollie::Refund.all(params[:offset], params[:limit], testmode: params[:test_mode])
|
15
15
|
JSON.pretty_generate(refunds.attributes)
|
16
16
|
end
|
17
17
|
end
|
@@ -52,7 +52,7 @@ class Application < Sinatra::Application
|
|
52
52
|
end
|
53
53
|
|
54
54
|
get '/v1/settlements' do
|
55
|
-
settlements =
|
55
|
+
settlements = Mollie::Settlement.all(params[:offset], params[:count],
|
56
56
|
reference: params[:reference],
|
57
57
|
testmode: params[:testmode]
|
58
58
|
)
|
@@ -60,23 +60,23 @@ class Application < Sinatra::Application
|
|
60
60
|
end
|
61
61
|
|
62
62
|
get '/v1/settlements/:id' do
|
63
|
-
settlement =
|
63
|
+
settlement = Mollie::Settlement.get(params[:id], testmode: params[:testmode])
|
64
64
|
JSON.pretty_generate(settlement.attributes)
|
65
65
|
end
|
66
66
|
|
67
67
|
get '/v1/settlements/next' do
|
68
|
-
settlement =
|
68
|
+
settlement = Mollie::Settlement.next(testmode: params[:testmode])
|
69
69
|
JSON.pretty_generate(settlement.attributes)
|
70
70
|
end
|
71
71
|
|
72
72
|
get '/v1/settlements/open' do
|
73
|
-
settlement =
|
73
|
+
settlement = Mollie::Settlement.open(testmode: params[:testmode])
|
74
74
|
JSON.pretty_generate(settlement.attributes)
|
75
75
|
end
|
76
76
|
|
77
77
|
|
78
78
|
get '/v1/settlements/:settlement_id/payments' do
|
79
|
-
payments =
|
79
|
+
payments = Mollie::Settlement::Payment.all(params[:offset], params[:count], testmode: params[:testmode], settlement_id: params[:settlement_id])
|
80
80
|
JSON.pretty_generate(payments.attributes)
|
81
81
|
end
|
82
82
|
|
@@ -102,7 +102,7 @@ class Application < Sinatra::Application
|
|
102
102
|
end
|
103
103
|
|
104
104
|
post '/v1/subscriptions/first_payment' do
|
105
|
-
payment =
|
105
|
+
payment = Mollie::Payment.create(
|
106
106
|
amount: json_params['amount'],
|
107
107
|
customer_id: json_params['customer_id'],
|
108
108
|
description: json_params['description'],
|
@@ -116,12 +116,12 @@ class Application < Sinatra::Application
|
|
116
116
|
end
|
117
117
|
|
118
118
|
get '/v1/subscriptions/mandates/:customer_id' do
|
119
|
-
mandates =
|
119
|
+
mandates = Mollie::Customer::Mandates.all(customer_id: params[:customer_id])
|
120
120
|
JSON.pretty_generate(mandates.attributes)
|
121
121
|
end
|
122
122
|
|
123
123
|
post '/v1/subscriptions/on_demand' do
|
124
|
-
payment =
|
124
|
+
payment = Mollie::Payment.create(
|
125
125
|
amount: json_params['amount'],
|
126
126
|
customer_id: json_params['customer_id'],
|
127
127
|
description: json_params['description'],
|
@@ -135,17 +135,17 @@ class Application < Sinatra::Application
|
|
135
135
|
end
|
136
136
|
|
137
137
|
get '/v1/customers/:customer_id/subscriptions' do
|
138
|
-
subscriptions =
|
138
|
+
subscriptions = Mollie::Customer::Subscription.all(params[:offset], params[:count], testmode: params[:testmode], customer_id: params[:customer_id])
|
139
139
|
JSON.pretty_generate(subscriptions.attributes)
|
140
140
|
end
|
141
141
|
|
142
142
|
get '/v1/customers/:customer_id/subscriptions/:id' do
|
143
|
-
payment =
|
143
|
+
payment = Mollie::Customer::Subscription.get(params[:id], testmode: params[:testmode], customer_id: params[:customer_id])
|
144
144
|
JSON.pretty_generate(payment.attributes)
|
145
145
|
end
|
146
146
|
|
147
147
|
post '/v1/customers/:customer_id/subscriptions' do
|
148
|
-
subscription =
|
148
|
+
subscription = Mollie::Customer::Subscription.create(
|
149
149
|
amount: json_params['amount'],
|
150
150
|
times: json_params['times'],
|
151
151
|
interval: json_params['interval'],
|
@@ -159,7 +159,7 @@ class Application < Sinatra::Application
|
|
159
159
|
end
|
160
160
|
|
161
161
|
delete '/v1/customers/:customer_id/subscriptions/:id' do
|
162
|
-
|
162
|
+
Mollie::Customer::Subscription.delete(params[:id], testmode: params[:testmode], customer_id: params[:customer_id])
|
163
163
|
"deleted"
|
164
164
|
end
|
165
165
|
end
|
data/examples/config.ru
CHANGED
@@ -5,7 +5,7 @@ require 'sinatra/namespace'
|
|
5
5
|
require 'sinatra/cross_origin'
|
6
6
|
require "swagger/blocks"
|
7
7
|
|
8
|
-
require File.expand_path "../lib/mollie
|
8
|
+
require File.expand_path "../lib/mollie-api-ruby", File.dirname(__FILE__)
|
9
9
|
|
10
10
|
require 'ngrok/tunnel'
|
11
11
|
|
@@ -17,6 +17,9 @@ class Application < Sinatra::Application
|
|
17
17
|
before do
|
18
18
|
headers "Access-Control-Allow-Origin" => "*"
|
19
19
|
headers["Access-Control-Allow-Headers"] = "X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept, X-Mollie-Api-Key"
|
20
|
+
Mollie::Client.configure do |config|
|
21
|
+
config.api_key = request.env["HTTP_X_MOLLIE_API_KEY"] || ENV["API_KEY"]
|
22
|
+
end
|
20
23
|
end
|
21
24
|
|
22
25
|
configure :production, :development do
|
@@ -31,7 +34,7 @@ class Application < Sinatra::Application
|
|
31
34
|
also_reload File.expand_path "./apis/*.rb", File.dirname(__FILE__)
|
32
35
|
end
|
33
36
|
|
34
|
-
error {|err| Rack::Response.new([{ 'error' => err.message }.to_json], 500, { 'Content-type' => 'application/json' }).finish}
|
37
|
+
error { |err| Rack::Response.new([{ 'error' => err.message }.to_json], 500, { 'Content-type' => 'application/json' }).finish }
|
35
38
|
|
36
39
|
options "*" do
|
37
40
|
response.headers["Allow"] = "HEAD,GET,PUT,POST,DELETE,OPTIONS"
|
@@ -41,17 +44,13 @@ class Application < Sinatra::Application
|
|
41
44
|
200
|
42
45
|
end
|
43
46
|
|
44
|
-
def client
|
45
|
-
@client ||= Mollie::API::Client.new(request.env["HTTP_X_MOLLIE_API_KEY"] || ENV["API_KEY"])
|
46
|
-
end
|
47
|
-
|
48
47
|
def json_params
|
49
48
|
@json_params ||= JSON.parse request.body.read
|
50
49
|
end
|
51
50
|
|
52
51
|
end
|
53
52
|
|
54
|
-
Dir[File.join('apis', '*.rb')].each {|file| require File.expand_path(file)}
|
53
|
+
Dir[File.join('apis', '*.rb')].each { |file| require File.expand_path(file) }
|
55
54
|
|
56
55
|
run Application.new
|
57
56
|
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative './mollie'
|
data/lib/mollie.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'time'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'bigdecimal'
|
5
|
+
require 'net/https'
|
6
|
+
|
7
|
+
module Mollie
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'mollie/exception'
|
12
|
+
require 'mollie/util'
|
13
|
+
require 'mollie/version'
|
14
|
+
|
15
|
+
require 'mollie/base'
|
16
|
+
require 'mollie/relation'
|
17
|
+
require 'mollie/chargeback'
|
18
|
+
require 'mollie/client'
|
19
|
+
require 'mollie/customer'
|
20
|
+
require 'mollie/customer/mandate'
|
21
|
+
require 'mollie/customer/subscription'
|
22
|
+
require 'mollie/invoice'
|
23
|
+
require 'mollie/issuer'
|
24
|
+
require 'mollie/list'
|
25
|
+
require 'mollie/method'
|
26
|
+
require 'mollie/organization'
|
27
|
+
require 'mollie/payment'
|
28
|
+
require 'mollie/permission'
|
29
|
+
require 'mollie/profile'
|
30
|
+
require 'mollie/profile/api_key'
|
31
|
+
require 'mollie/refund'
|
32
|
+
require 'mollie/settlement'
|
33
|
+
|
34
|
+
require 'mollie/customer/payment'
|
35
|
+
require 'mollie/payment/chargeback'
|
36
|
+
require 'mollie/payment/refund'
|
37
|
+
require 'mollie/settlement/chargeback'
|
38
|
+
require 'mollie/settlement/payment'
|
39
|
+
require 'mollie/settlement/refund'
|
data/lib/mollie/base.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
module Mollie
|
2
|
+
class Base
|
3
|
+
attr_reader :attributes
|
4
|
+
|
5
|
+
def initialize(attributes)
|
6
|
+
@attributes = attributes
|
7
|
+
assign_attributes(attributes)
|
8
|
+
end
|
9
|
+
|
10
|
+
def assign_attributes(attributes)
|
11
|
+
attributes.each do |key, value|
|
12
|
+
public_send("#{key}=", value) if respond_to?("#{key}=")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def create(data = {})
|
18
|
+
request("POST", nil, data) do |response|
|
19
|
+
new(response)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def all(*args)
|
24
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
25
|
+
offset, limit = args
|
26
|
+
request("GET", nil, {}, { offset: offset || 0, count: limit || 50 }.merge(options)) do |response|
|
27
|
+
Mollie::List.new(response, self)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def get(id, options = {})
|
32
|
+
request("GET", id, {}, options) do |response|
|
33
|
+
new(response)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def update(id, data = {})
|
38
|
+
request("POST", id, data) do |response|
|
39
|
+
new(response)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete(id, options = {})
|
44
|
+
request("DELETE", id, options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def request(method, id = 0, data = {}, query = {})
|
48
|
+
parent_id = query.delete(self.parent_id) || data.delete(self.parent_id)
|
49
|
+
response = Mollie::Client.instance.perform_http_call(method, resource_name(parent_id), id, data, query)
|
50
|
+
yield(response) if block_given?
|
51
|
+
end
|
52
|
+
|
53
|
+
def id_param
|
54
|
+
"#{name.downcase.split("::")[-1]}_id".to_sym
|
55
|
+
end
|
56
|
+
|
57
|
+
def parent_id
|
58
|
+
"#{name.downcase.split("::")[-2]}_id".to_sym
|
59
|
+
end
|
60
|
+
|
61
|
+
def resource_name(parent_id = nil)
|
62
|
+
path = name.downcase.split("::").slice(1..-1).map(&Util.method(:pluralize))
|
63
|
+
|
64
|
+
if path.size == 2 && parent_id
|
65
|
+
path.join("/#{parent_id}/")
|
66
|
+
else
|
67
|
+
path.last
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def update(data = {})
|
73
|
+
if (parent_id = attributes[self.class.parent_id])
|
74
|
+
data[self.class.parent_id] = parent_id
|
75
|
+
end
|
76
|
+
|
77
|
+
if (resource = self.class.update(id, data))
|
78
|
+
!!assign_attributes(resource.attributes)
|
79
|
+
else
|
80
|
+
resource
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def delete(options = {})
|
85
|
+
if (parent_id = attributes[self.class.parent_id])
|
86
|
+
options[self.class.parent_id] = parent_id
|
87
|
+
end
|
88
|
+
self.class.delete(id, options)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Mollie
|
2
|
+
class Chargeback < Base
|
3
|
+
|
4
|
+
attr_accessor :id,
|
5
|
+
:payment,
|
6
|
+
:amount,
|
7
|
+
:chargeback_datetime,
|
8
|
+
:settlement_id,
|
9
|
+
:reversed_datetime
|
10
|
+
|
11
|
+
|
12
|
+
def reversed?
|
13
|
+
!!reversed_datetime
|
14
|
+
end
|
15
|
+
|
16
|
+
def reversed_datetime=(reversed_datetime)
|
17
|
+
@reversed_datetime = Time.parse(reversed_datetime) rescue nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def chargeback_datetime=(chargeback_datetime)
|
21
|
+
@chargeback_datetime = Time.parse(chargeback_datetime) rescue nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def amount=(amount)
|
25
|
+
@amount = BigDecimal.new(amount.to_s) if amount
|
26
|
+
end
|
27
|
+
|
28
|
+
def payment=(payment)
|
29
|
+
if payment.is_a?(Hash)
|
30
|
+
@payment = Payment.new(payment)
|
31
|
+
else
|
32
|
+
@payment = payment
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module Mollie
|
2
|
+
class Client
|
3
|
+
API_ENDPOINT = 'https://api.mollie.nl'
|
4
|
+
API_VERSION = 'v1'
|
5
|
+
|
6
|
+
MODE_TEST = 'test'
|
7
|
+
MODE_LIVE = 'live'
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor :configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
class Configuration
|
14
|
+
attr_accessor :api_key
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@api_key = ''
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.configure
|
22
|
+
self.configuration ||= Configuration.new
|
23
|
+
yield(configuration)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [Mollie::Client]
|
27
|
+
def self.instance
|
28
|
+
Thread.current['MOLLIE_CLIENT'] ||= new(configuration.api_key)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.with_api_key(api_key)
|
32
|
+
Thread.current['MOLLIE_API_KEY'] = instance.api_key
|
33
|
+
instance.api_key = api_key
|
34
|
+
yield
|
35
|
+
ensure
|
36
|
+
instance.api_key = Thread.current['MOLLIE_API_KEY']
|
37
|
+
Thread.current['MOLLIE_API_KEY'] = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
attr_accessor :api_key,
|
41
|
+
:api_endpoint
|
42
|
+
|
43
|
+
def initialize(api_key = nil)
|
44
|
+
@api_endpoint = API_ENDPOINT
|
45
|
+
@api_key = api_key
|
46
|
+
@version_strings = []
|
47
|
+
|
48
|
+
add_version_string 'Mollie/' << VERSION
|
49
|
+
add_version_string 'Ruby/' << RUBY_VERSION
|
50
|
+
add_version_string OpenSSL::OPENSSL_VERSION.split(' ').slice(0, 2).join '/'
|
51
|
+
end
|
52
|
+
|
53
|
+
def api_endpoint=(api_endpoint)
|
54
|
+
@api_endpoint = api_endpoint.chomp('/')
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_version_string(version_string)
|
58
|
+
@version_strings << version_string.gsub(/\s+/, '-')
|
59
|
+
end
|
60
|
+
|
61
|
+
def perform_http_call(http_method, api_method, id = nil, http_body = {}, query = {})
|
62
|
+
path = "/#{API_VERSION}/#{api_method}/#{id}".chomp('/')
|
63
|
+
api_key = http_body.delete(:api_key) || query.delete(:api_key) || @api_key
|
64
|
+
api_endpoint = http_body.delete(:api_endpoint) || query.delete(:api_endpoint) || @api_endpoint
|
65
|
+
|
66
|
+
if query.length > 0
|
67
|
+
camelized_query = Util.camelize_keys(query)
|
68
|
+
path += "?#{URI.encode_www_form(camelized_query)}"
|
69
|
+
end
|
70
|
+
|
71
|
+
uri = URI.parse(api_endpoint)
|
72
|
+
client = Net::HTTP.new(uri.host, uri.port)
|
73
|
+
client.use_ssl = true
|
74
|
+
client.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
75
|
+
client.ca_file = (File.expand_path '../cacert.pem', File.dirname(__FILE__))
|
76
|
+
|
77
|
+
case http_method
|
78
|
+
when 'GET'
|
79
|
+
request = Net::HTTP::Get.new(path)
|
80
|
+
when 'POST'
|
81
|
+
http_body.delete_if { |k, v| v.nil? }
|
82
|
+
request = Net::HTTP::Post.new(path)
|
83
|
+
request.body = Util.camelize_keys(http_body).to_json
|
84
|
+
when 'DELETE'
|
85
|
+
http_body.delete_if { |k, v| v.nil? }
|
86
|
+
request = Net::HTTP::Delete.new(path)
|
87
|
+
request.body = Util.camelize_keys(http_body).to_json
|
88
|
+
else
|
89
|
+
raise Mollie::Exception.new("Invalid HTTP Method: #{http_method}")
|
90
|
+
end
|
91
|
+
|
92
|
+
request['Accept'] = 'application/json'
|
93
|
+
request['Content-Type'] = 'application/json'
|
94
|
+
request['Authorization'] = "Bearer #{api_key}"
|
95
|
+
request['User-Agent'] = @version_strings.join(' ')
|
96
|
+
|
97
|
+
begin
|
98
|
+
response = client.request(request)
|
99
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
100
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
101
|
+
raise Mollie::Exception.new(e.message)
|
102
|
+
end
|
103
|
+
|
104
|
+
http_code = response.code.to_i
|
105
|
+
case http_code
|
106
|
+
when 200, 201
|
107
|
+
Util.nested_underscore_keys(JSON.parse(response.body))
|
108
|
+
when 204
|
109
|
+
{} # No Content
|
110
|
+
else
|
111
|
+
response = JSON.parse(response.body)
|
112
|
+
if response['error']
|
113
|
+
exception = Mollie::Exception.new response['error']['message']
|
114
|
+
exception.field = response['error']['field'] unless response['error']['field'].nil?
|
115
|
+
elsif response['errors']
|
116
|
+
exception = Mollie::Exception.new response['errors'].values.join(', ')
|
117
|
+
else
|
118
|
+
exception = Mollie::Exception.new response.body
|
119
|
+
end
|
120
|
+
exception.code = http_code
|
121
|
+
raise exception
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Mollie
|
2
|
+
class Customer < Base
|
3
|
+
attr_accessor :id,
|
4
|
+
:mode,
|
5
|
+
:name,
|
6
|
+
:email,
|
7
|
+
:locale,
|
8
|
+
:metadata,
|
9
|
+
:recently_used_methods,
|
10
|
+
:created_datetime
|
11
|
+
|
12
|
+
def created_datetime=(created_datetime)
|
13
|
+
@created_datetime = Time.parse(created_datetime.to_s)
|
14
|
+
end
|
15
|
+
|
16
|
+
def recently_used_methods=(methods)
|
17
|
+
@recently_used_methods = Array(methods).map(&:to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
def metadata=(metadata)
|
21
|
+
@metadata = OpenStruct.new(metadata) if metadata.is_a?(Hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
def payments
|
25
|
+
Relation.new(self, Customer::Payment)
|
26
|
+
end
|
27
|
+
|
28
|
+
def mandates
|
29
|
+
Relation.new(self, Customer::Mandate)
|
30
|
+
end
|
31
|
+
|
32
|
+
def subscriptions
|
33
|
+
Relation.new(self, Customer::Subscription)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|