mollie-api-ruby 3.1.5 → 4.0.0.pre.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +0 -3
- data/CHANGELOG.md +6 -0
- data/README.md +63 -119
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/docs/migration_v2_2_x.md +67 -0
- data/docs/migration_v3_x.md +227 -0
- data/examples/chargebacks/get.rb +4 -0
- data/examples/chargebacks/list.rb +1 -0
- data/{website-docs → examples}/connect/authorize.rb +3 -2
- data/{website-docs → examples}/connect/tokens.rb +1 -1
- data/examples/customers/create-payment.rb +6 -0
- data/examples/customers/create.rb +5 -0
- data/examples/customers/delete.rb +1 -0
- data/examples/customers/get.rb +1 -0
- data/examples/customers/list-payments.rb +1 -0
- data/examples/customers/list.rb +1 -0
- data/examples/customers/update.rb +4 -0
- data/examples/invoices/get.rb +1 -0
- data/examples/invoices/list.rb +1 -0
- data/examples/mandates/create.rb +9 -0
- data/examples/mandates/delete.rb +1 -0
- data/examples/mandates/get.rb +1 -0
- data/examples/mandates/list.rb +1 -0
- data/examples/methods/get.rb +4 -0
- data/examples/methods/list.rb +4 -0
- data/examples/organisations/get-current.rb +1 -0
- data/examples/organisations/get.rb +1 -0
- data/examples/payments/create.rb +9 -0
- data/examples/payments/delete.rb +1 -0
- data/examples/payments/get-customer.rb +2 -0
- data/examples/payments/get-mandate.rb +2 -0
- data/examples/payments/get-settlement.rb +2 -0
- data/examples/payments/get-subscription.rb +2 -0
- data/examples/payments/get.rb +1 -0
- data/examples/payments/list.rb +1 -0
- data/examples/payments/webhook.rb +12 -0
- data/examples/permissions/get.rb +1 -0
- data/examples/permissions/list.rb +1 -0
- data/examples/profiles/create.rb +8 -0
- data/examples/profiles/delete.rb +1 -0
- data/examples/profiles/get.rb +1 -0
- data/examples/profiles/list-chargebacks.rb +2 -0
- data/examples/profiles/list-methods.rb +2 -0
- data/examples/profiles/list-payments.rb +2 -0
- data/examples/profiles/list-refunds.rb +2 -0
- data/examples/profiles/list.rb +1 -0
- data/examples/profiles/update.rb +5 -0
- data/examples/refunds/create.rb +5 -0
- data/examples/refunds/delete.rb +4 -0
- data/examples/refunds/get-payment.rb +2 -0
- data/examples/refunds/get.rb +4 -0
- data/examples/refunds/list.rb +1 -0
- data/examples/settlements/get.rb +1 -0
- data/examples/settlements/list-chargebacks.rb +1 -0
- data/examples/settlements/list-payments.rb +1 -0
- data/examples/settlements/list-refunds.rb +1 -0
- data/examples/settlements/list.rb +1 -0
- data/examples/settlements/next.rb +1 -0
- data/examples/settlements/open.rb +1 -0
- data/examples/subscriptions/create.rb +8 -0
- data/examples/subscriptions/delete.rb +4 -0
- data/examples/subscriptions/get.rb +4 -0
- data/examples/subscriptions/list.rb +1 -0
- data/examples/subscriptions/update.rb +5 -0
- data/lib/cacert.pem +168 -48
- data/lib/mollie.rb +1 -3
- data/lib/mollie/amount.rb +20 -0
- data/lib/mollie/base.rb +9 -8
- data/lib/mollie/chargeback.rb +25 -15
- data/lib/mollie/client.rb +33 -13
- data/lib/mollie/customer.rb +9 -14
- data/lib/mollie/customer/mandate.rb +17 -5
- data/lib/mollie/customer/subscription.rb +14 -15
- data/lib/mollie/exception.rb +15 -3
- data/lib/mollie/invoice.rb +30 -26
- data/lib/mollie/list.rb +27 -18
- data/lib/mollie/method.rb +17 -25
- data/lib/mollie/organization.rb +5 -11
- data/lib/mollie/payment.rb +89 -61
- data/lib/mollie/permission.rb +0 -1
- data/lib/mollie/profile.rb +18 -13
- data/lib/mollie/refund.rb +27 -7
- data/lib/mollie/settlement.rb +50 -9
- data/lib/mollie/util.rb +11 -0
- data/lib/mollie/version.rb +1 -1
- data/mollie-api-ruby.gemspec +0 -7
- data/test/mollie/amount_test.rb +30 -0
- data/test/mollie/base_test.rb +44 -44
- data/test/mollie/chargeback_test.rb +78 -17
- data/test/mollie/client_test.rb +29 -12
- data/test/mollie/customer/mandate_test.rb +85 -9
- data/test/mollie/customer/payment_test.rb +2 -2
- data/test/mollie/customer/subscription_test.rb +71 -20
- data/test/mollie/customer_test.rb +17 -89
- data/test/mollie/invoice_test.rb +40 -24
- data/test/mollie/list_test.rb +62 -18
- data/test/mollie/method_test.rb +2 -8
- data/test/mollie/organization_test.rb +28 -23
- data/test/mollie/payment/chargeback_test.rb +2 -3
- data/test/mollie/payment/refund_test.rb +2 -3
- data/test/mollie/payment_test.rb +272 -86
- data/test/mollie/permission_test.rb +0 -2
- data/test/mollie/profile_test.rb +129 -35
- data/test/mollie/refund_test.rb +90 -10
- data/test/mollie/settlement/chargeback_test.rb +2 -4
- data/test/mollie/settlement/payment_test.rb +2 -2
- data/test/mollie/settlement/refund_test.rb +2 -3
- data/test/mollie/settlement_test.rb +199 -98
- data/test/mollie/util_test.rb +31 -0
- metadata +96 -239
- data/examples/apis/api_docs.rb +0 -37
- data/examples/apis/chargebacks.rb +0 -17
- data/examples/apis/connect.rb +0 -58
- data/examples/apis/customers.rb +0 -116
- data/examples/apis/invoices.rb +0 -38
- data/examples/apis/issuers.rb +0 -35
- data/examples/apis/mandates.rb +0 -83
- data/examples/apis/methods.rb +0 -50
- data/examples/apis/organizations.rb +0 -16
- data/examples/apis/payments.rb +0 -174
- data/examples/apis/permissions.rb +0 -32
- data/examples/apis/profiles.rb +0 -126
- data/examples/apis/refunds.rb +0 -17
- data/examples/apis/settlements.rb +0 -84
- data/examples/apis/subscriptions.rb +0 -165
- data/examples/config.ru +0 -57
- 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 +0 -101
- data/examples/public/javascripts/lib/backbone-min.js +0 -1
- data/examples/public/javascripts/lib/es5-shim.js +0 -1
- data/examples/public/javascripts/lib/handlebars-4.0.5.js +0 -3
- data/examples/public/javascripts/lib/highlight.9.1.0.pack.js +0 -1
- data/examples/public/javascripts/lib/highlight.9.1.0.pack_extended.js +0 -1
- data/examples/public/javascripts/lib/jquery-1.8.0.min.js +0 -3
- data/examples/public/javascripts/lib/jquery.ba-bbq.min.js +0 -1
- data/examples/public/javascripts/lib/jquery.slideto.min.js +0 -1
- data/examples/public/javascripts/lib/jquery.wiggle.min.js +0 -1
- data/examples/public/javascripts/lib/js-yaml.min.js +0 -2
- data/examples/public/javascripts/lib/jsoneditor.min.js +0 -5
- data/examples/public/javascripts/lib/lodash.min.js +0 -2
- data/examples/public/javascripts/lib/marked.js +0 -1
- data/examples/public/javascripts/lib/object-assign-pollyfill.js +0 -1
- data/examples/public/javascripts/lib/sanitize-html.min.js +0 -4
- data/examples/public/javascripts/lib/swagger-oauth.js +0 -1
- data/examples/public/javascripts/swagger-ui.js +0 -25378
- data/examples/public/javascripts/swagger-ui.min.js +0 -15
- data/examples/public/javascripts/swagger_docs.js +0 -14
- data/examples/public/o2c.html +0 -20
- data/examples/public/stylesheets/reset.css +0 -1
- data/examples/public/stylesheets/screen.css +0 -1545
- data/examples/public/stylesheets/swagger_docs.css +0 -4
- data/examples/public/stylesheets/typography.css +0 -0
- data/lib/mollie/issuer.rb +0 -5
- data/lib/mollie/profile/api_key.rb +0 -19
- data/lib/mollie/relation.rb +0 -36
- data/test/mollie/issuer_test.rb +0 -19
- data/test/mollie/profile/apikey_test.rb +0 -31
- data/website-docs/chargebacks/list-all.rb +0 -12
- data/website-docs/customers/create-payment.rb +0 -13
- data/website-docs/customers/create.rb +0 -12
- data/website-docs/customers/delete.rb +0 -10
- data/website-docs/customers/get.rb +0 -10
- data/website-docs/customers/list-payments.rb +0 -10
- data/website-docs/customers/list.rb +0 -12
- data/website-docs/customers/update.rb +0 -11
- data/website-docs/invoices/get.rb +0 -10
- data/website-docs/invoices/list.rb +0 -12
- data/website-docs/issuers/get.rb +0 -10
- data/website-docs/issuers/list.rb +0 -12
- data/website-docs/mandates/create.rb +0 -16
- data/website-docs/mandates/delete.rb +0 -10
- data/website-docs/mandates/get.rb +0 -10
- data/website-docs/mandates/list.rb +0 -12
- data/website-docs/methods/get.rb +0 -10
- data/website-docs/methods/list.rb +0 -12
- data/website-docs/organisations/get.rb +0 -10
- data/website-docs/payments/create-refund.rb +0 -14
- data/website-docs/payments/create.rb +0 -16
- data/website-docs/payments/delete-refund.rb +0 -13
- data/website-docs/payments/delete.rb +0 -12
- data/website-docs/payments/get-chargeback.rb +0 -11
- data/website-docs/payments/get-refund.rb +0 -11
- data/website-docs/payments/get.rb +0 -10
- data/website-docs/payments/list-chargeback.rb +0 -13
- data/website-docs/payments/list-refunds.rb +0 -13
- data/website-docs/payments/list.rb +0 -12
- data/website-docs/payments/payment-webhook.rb +0 -21
- data/website-docs/permissions/get.rb +0 -10
- data/website-docs/permissions/list.rb +0 -12
- data/website-docs/profiles/create.rb +0 -15
- data/website-docs/profiles/delete.rb +0 -10
- data/website-docs/profiles/get-key.rb +0 -11
- data/website-docs/profiles/get.rb +0 -10
- data/website-docs/profiles/list-keys.rb +0 -13
- data/website-docs/profiles/list.rb +0 -12
- data/website-docs/profiles/reset-key.rb +0 -13
- data/website-docs/profiles/update.rb +0 -12
- data/website-docs/refunds/list.rb +0 -12
- data/website-docs/settlements/get.rb +0 -10
- data/website-docs/settlements/list-chargebacks.rb +0 -13
- data/website-docs/settlements/list-payments.rb +0 -13
- data/website-docs/settlements/list-refunds.rb +0 -13
- data/website-docs/settlements/list.rb +0 -12
- data/website-docs/settlements/next.rb +0 -9
- data/website-docs/settlements/open.rb +0 -9
- data/website-docs/subscriptions/create.rb +0 -14
- data/website-docs/subscriptions/delete.rb +0 -10
- data/website-docs/subscriptions/get.rb +0 -10
- data/website-docs/subscriptions/list.rb +0 -12
data/lib/mollie.rb
CHANGED
@@ -13,21 +13,19 @@ require 'mollie/util'
|
|
13
13
|
require 'mollie/version'
|
14
14
|
|
15
15
|
require 'mollie/base'
|
16
|
-
require 'mollie/
|
16
|
+
require 'mollie/amount'
|
17
17
|
require 'mollie/chargeback'
|
18
18
|
require 'mollie/client'
|
19
19
|
require 'mollie/customer'
|
20
20
|
require 'mollie/customer/mandate'
|
21
21
|
require 'mollie/customer/subscription'
|
22
22
|
require 'mollie/invoice'
|
23
|
-
require 'mollie/issuer'
|
24
23
|
require 'mollie/list'
|
25
24
|
require 'mollie/method'
|
26
25
|
require 'mollie/organization'
|
27
26
|
require 'mollie/payment'
|
28
27
|
require 'mollie/permission'
|
29
28
|
require 'mollie/profile'
|
30
|
-
require 'mollie/profile/api_key'
|
31
29
|
require 'mollie/refund'
|
32
30
|
require 'mollie/settlement'
|
33
31
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Mollie
|
2
|
+
class Amount < Base
|
3
|
+
attr_accessor :value, :currency
|
4
|
+
|
5
|
+
def initialize(attributes)
|
6
|
+
super unless attributes.nil?
|
7
|
+
end
|
8
|
+
|
9
|
+
def value=(val)
|
10
|
+
@value = BigDecimal.new(val.to_s)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_h
|
14
|
+
{
|
15
|
+
value: attributes['value'],
|
16
|
+
currency: attributes['currency']
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/mollie/base.rb
CHANGED
@@ -20,10 +20,11 @@ module Mollie
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def all(
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
def all(options = {})
|
24
|
+
id = nil
|
25
|
+
data = {}
|
26
|
+
|
27
|
+
request("GET", id, data, options) do |response|
|
27
28
|
Mollie::List.new(response, self)
|
28
29
|
end
|
29
30
|
end
|
@@ -35,7 +36,7 @@ module Mollie
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def update(id, data = {})
|
38
|
-
request("
|
39
|
+
request("PATCH", id, data) do |response|
|
39
40
|
new(response)
|
40
41
|
end
|
41
42
|
end
|
@@ -44,9 +45,9 @@ module Mollie
|
|
44
45
|
request("DELETE", id, options)
|
45
46
|
end
|
46
47
|
|
47
|
-
def request(method, id = 0, data = {},
|
48
|
-
parent_id =
|
49
|
-
response = Mollie::Client.instance.perform_http_call(method, resource_name(parent_id), id, data,
|
48
|
+
def request(method, id = 0, data = {}, options = {})
|
49
|
+
parent_id = options.delete(self.parent_id) || data.delete(self.parent_id)
|
50
|
+
response = Mollie::Client.instance.perform_http_call(method, resource_name(parent_id), id, data, options)
|
50
51
|
yield(response) if block_given?
|
51
52
|
end
|
52
53
|
|
data/lib/mollie/chargeback.rb
CHANGED
@@ -4,33 +4,43 @@ module Mollie
|
|
4
4
|
attr_accessor :id,
|
5
5
|
:payment,
|
6
6
|
:amount,
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
7
|
+
:settlement_amount,
|
8
|
+
:created_at,
|
9
|
+
:payment_id,
|
10
|
+
:reversed_at,
|
11
|
+
:_links
|
10
12
|
|
13
|
+
alias_method :links, :_links
|
11
14
|
|
12
15
|
def reversed?
|
13
|
-
!!
|
16
|
+
!!reversed_at
|
14
17
|
end
|
15
18
|
|
16
|
-
def
|
17
|
-
@
|
19
|
+
def reversed_at=(reversed_at)
|
20
|
+
@reversed_at = Time.parse(reversed_at) rescue nil
|
18
21
|
end
|
19
22
|
|
20
|
-
def
|
21
|
-
@
|
23
|
+
def created_at=(created_at)
|
24
|
+
@created_at = Time.parse(created_at) rescue nil
|
22
25
|
end
|
23
26
|
|
24
27
|
def amount=(amount)
|
25
|
-
@amount =
|
28
|
+
@amount = Mollie::Amount.new(amount)
|
26
29
|
end
|
27
30
|
|
28
|
-
def
|
29
|
-
|
30
|
-
@payment = Payment.new(payment)
|
31
|
-
else
|
32
|
-
@payment = payment
|
33
|
-
end
|
31
|
+
def settlement_amount=(settlement_amount)
|
32
|
+
@settlement_amount = Mollie::Amount.new(settlement_amount)
|
34
33
|
end
|
34
|
+
|
35
|
+
def payment(options = {})
|
36
|
+
Payment.get(payment_id, options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def settlement(options = {})
|
40
|
+
settlement_id = Util.extract_id(links, "settlement")
|
41
|
+
return if settlement_id.nil?
|
42
|
+
Settlement.get(settlement_id, options)
|
43
|
+
end
|
44
|
+
|
35
45
|
end
|
36
46
|
end
|
data/lib/mollie/client.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Mollie
|
2
2
|
class Client
|
3
|
-
API_ENDPOINT = 'https://api.mollie.
|
4
|
-
API_VERSION = '
|
3
|
+
API_ENDPOINT = 'https://api.mollie.com'
|
4
|
+
API_VERSION = 'v2'
|
5
5
|
|
6
6
|
MODE_TEST = 'test'
|
7
7
|
MODE_LIVE = 'live'
|
@@ -68,7 +68,7 @@ module Mollie
|
|
68
68
|
|
69
69
|
if query.length > 0
|
70
70
|
camelized_query = Util.camelize_keys(query)
|
71
|
-
path += "?#{
|
71
|
+
path += "?#{build_nested_query(camelized_query)}"
|
72
72
|
end
|
73
73
|
|
74
74
|
uri = URI.parse(api_endpoint)
|
@@ -84,6 +84,10 @@ module Mollie
|
|
84
84
|
http_body.delete_if { |k, v| v.nil? }
|
85
85
|
request = Net::HTTP::Post.new(path)
|
86
86
|
request.body = Util.camelize_keys(http_body).to_json
|
87
|
+
when 'PATCH'
|
88
|
+
http_body.delete_if { |k, v| v.nil? }
|
89
|
+
request = Net::HTTP::Patch.new(path)
|
90
|
+
request.body = Util.camelize_keys(http_body).to_json
|
87
91
|
when 'DELETE'
|
88
92
|
http_body.delete_if { |k, v| v.nil? }
|
89
93
|
request = Net::HTTP::Delete.new(path)
|
@@ -111,18 +115,34 @@ module Mollie
|
|
111
115
|
when 204
|
112
116
|
{} # No Content
|
113
117
|
else
|
114
|
-
|
115
|
-
|
116
|
-
exception = Mollie::Exception.new response['error']['message']
|
117
|
-
exception.field = response['error']['field'] unless response['error']['field'].nil?
|
118
|
-
elsif response['errors']
|
119
|
-
exception = Mollie::Exception.new response['errors'].values.join(', ')
|
120
|
-
else
|
121
|
-
exception = Mollie::Exception.new response.body
|
122
|
-
end
|
123
|
-
exception.code = http_code
|
118
|
+
json = JSON.parse(response.body)
|
119
|
+
exception = Mollie::RequestError.new(json)
|
124
120
|
raise exception
|
125
121
|
end
|
126
122
|
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def build_nested_query(value, prefix = nil)
|
127
|
+
case value
|
128
|
+
when Array
|
129
|
+
value.map { |v|
|
130
|
+
build_nested_query(v, "#{prefix}[]")
|
131
|
+
}.join("&")
|
132
|
+
when Hash
|
133
|
+
value.map { |k, v|
|
134
|
+
build_nested_query(v, prefix ? "#{prefix}[#{escape(k)}]" : escape(k))
|
135
|
+
}.reject(&:empty?).join('&')
|
136
|
+
when nil
|
137
|
+
prefix
|
138
|
+
else
|
139
|
+
raise ArgumentError, "value must be a Hash" if prefix.nil?
|
140
|
+
"#{prefix}=#{escape(value)}"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def escape(s)
|
145
|
+
URI.encode_www_form_component(s)
|
146
|
+
end
|
127
147
|
end
|
128
148
|
end
|
data/lib/mollie/customer.rb
CHANGED
@@ -6,31 +6,26 @@ module Mollie
|
|
6
6
|
:email,
|
7
7
|
:locale,
|
8
8
|
:metadata,
|
9
|
-
:
|
10
|
-
:created_datetime
|
9
|
+
:created_at
|
11
10
|
|
12
|
-
def
|
13
|
-
@
|
14
|
-
end
|
15
|
-
|
16
|
-
def recently_used_methods=(methods)
|
17
|
-
@recently_used_methods = Array(methods).map(&:to_s)
|
11
|
+
def created_at=(created_at)
|
12
|
+
@created_at = Time.parse(created_at.to_s)
|
18
13
|
end
|
19
14
|
|
20
15
|
def metadata=(metadata)
|
21
16
|
@metadata = OpenStruct.new(metadata) if metadata.is_a?(Hash)
|
22
17
|
end
|
23
18
|
|
24
|
-
def
|
25
|
-
|
19
|
+
def mandates(options = {})
|
20
|
+
Mandate.all(options.merge(customer_id: id))
|
26
21
|
end
|
27
22
|
|
28
|
-
def
|
29
|
-
|
23
|
+
def payments(options = {})
|
24
|
+
Payment.all(options.merge(customer_id: id))
|
30
25
|
end
|
31
26
|
|
32
|
-
def subscriptions
|
33
|
-
|
27
|
+
def subscriptions(options = {})
|
28
|
+
Subscription.all(options.merge(customer_id: id))
|
34
29
|
end
|
35
30
|
end
|
36
31
|
end
|
@@ -3,31 +3,43 @@ module Mollie
|
|
3
3
|
class Mandate < Base
|
4
4
|
STATUS_VALID = "valid"
|
5
5
|
STATUS_INVALID = "invalid"
|
6
|
+
STATUS_PENDING = "pending"
|
6
7
|
|
7
8
|
attr_accessor :id,
|
8
9
|
:status,
|
9
10
|
:method,
|
10
|
-
:customer_id,
|
11
11
|
:details,
|
12
|
-
:
|
13
|
-
:
|
12
|
+
:mandate_reference,
|
13
|
+
:signature_date,
|
14
|
+
:created_at,
|
15
|
+
:_links
|
14
16
|
|
17
|
+
alias_method :links, :_links
|
15
18
|
|
16
19
|
def details=(details)
|
17
20
|
@details = OpenStruct.new(details) if details.is_a?(Hash)
|
18
21
|
end
|
19
22
|
|
20
|
-
def
|
21
|
-
@
|
23
|
+
def created_at=(created_at)
|
24
|
+
@created_at = Time.parse(created_at.to_s) rescue nil
|
22
25
|
end
|
23
26
|
|
24
27
|
def valid?
|
25
28
|
status == STATUS_VALID
|
26
29
|
end
|
27
30
|
|
31
|
+
def pending?
|
32
|
+
status == STATUS_PENDING
|
33
|
+
end
|
34
|
+
|
28
35
|
def invalid?
|
29
36
|
status == STATUS_INVALID
|
30
37
|
end
|
38
|
+
|
39
|
+
def customer(options = {})
|
40
|
+
customer_id = Util.extract_id(links, "customer")
|
41
|
+
Customer.get(customer_id, options)
|
42
|
+
end
|
31
43
|
end
|
32
44
|
end
|
33
45
|
end
|
@@ -3,23 +3,22 @@ module Mollie
|
|
3
3
|
class Subscription < Base
|
4
4
|
STATUS_ACTIVE = "active"
|
5
5
|
STATUS_PENDING = "pending" # Waiting for a valid mandate.
|
6
|
-
|
6
|
+
STATUS_CANCELED = "canceled"
|
7
7
|
STATUS_SUSPENDED = "suspended" # Active, but mandate became invalid.
|
8
8
|
STATUS_COMPLETED = "completed"
|
9
9
|
|
10
|
-
attr_accessor :
|
11
|
-
:id,
|
10
|
+
attr_accessor :id,
|
12
11
|
:customer_id,
|
13
12
|
:mode,
|
14
|
-
:
|
13
|
+
:created_at,
|
15
14
|
:status,
|
16
15
|
:amount,
|
17
16
|
:times,
|
18
17
|
:interval,
|
19
18
|
:description,
|
20
19
|
:method,
|
21
|
-
:
|
22
|
-
:
|
20
|
+
:canceled_at,
|
21
|
+
:webhook_url
|
23
22
|
|
24
23
|
def active?
|
25
24
|
status == STATUS_ACTIVE
|
@@ -33,32 +32,32 @@ module Mollie
|
|
33
32
|
status == STATUS_SUSPENDED
|
34
33
|
end
|
35
34
|
|
36
|
-
def
|
37
|
-
status ==
|
35
|
+
def canceled?
|
36
|
+
status == STATUS_CANCELED
|
38
37
|
end
|
39
38
|
|
40
39
|
def completed?
|
41
40
|
status == STATUS_COMPLETED
|
42
41
|
end
|
43
42
|
|
44
|
-
def
|
45
|
-
@
|
43
|
+
def created_at=(created_at)
|
44
|
+
@created_at = Time.parse(created_at.to_s) rescue nil
|
46
45
|
end
|
47
46
|
|
48
|
-
def
|
49
|
-
@
|
47
|
+
def canceled_at=(canceled_at)
|
48
|
+
@canceled_at = Time.parse(canceled_at.to_s) rescue nil
|
50
49
|
end
|
51
50
|
|
52
51
|
def amount=(amount)
|
53
|
-
@amount =
|
52
|
+
@amount = Mollie::Amount.new(amount)
|
54
53
|
end
|
55
54
|
|
56
55
|
def times=(times)
|
57
56
|
@times = times.to_i
|
58
57
|
end
|
59
58
|
|
60
|
-
def
|
61
|
-
|
59
|
+
def customer(options = {})
|
60
|
+
Customer.get(customer_id, options)
|
62
61
|
end
|
63
62
|
end
|
64
63
|
end
|
data/lib/mollie/exception.rb
CHANGED
@@ -1,8 +1,20 @@
|
|
1
1
|
module Mollie
|
2
2
|
class Exception < StandardError
|
3
|
-
|
4
|
-
|
3
|
+
end
|
4
|
+
|
5
|
+
class RequestError < Exception
|
6
|
+
attr_accessor :status, :title, :detail, :field, :links
|
7
|
+
|
8
|
+
def initialize(error)
|
9
|
+
exception.status = error['status']
|
10
|
+
exception.title = error['title']
|
11
|
+
exception.detail = error['detail']
|
12
|
+
exception.field = error['field']
|
13
|
+
exception.links = error['_links']
|
14
|
+
end
|
5
15
|
|
6
|
-
|
16
|
+
def to_s
|
17
|
+
"#{status} #{title}: #{detail}"
|
18
|
+
end
|
7
19
|
end
|
8
20
|
end
|
data/lib/mollie/invoice.rb
CHANGED
@@ -4,32 +4,28 @@ module Mollie
|
|
4
4
|
STATUS_PAID = "paid"
|
5
5
|
STATUS_OVERDUE = "overdue"
|
6
6
|
|
7
|
-
class Amount < Base
|
8
|
-
attr_accessor :net, :vat, :gross
|
9
|
-
|
10
|
-
def net=(net)
|
11
|
-
@net = BigDecimal.new(net.to_s)
|
12
|
-
end
|
13
|
-
|
14
|
-
def vat=(vat)
|
15
|
-
@vat = BigDecimal.new(vat.to_s, 2)
|
16
|
-
end
|
17
|
-
|
18
|
-
def gross=(gross)
|
19
|
-
@gross = BigDecimal.new(gross.to_s)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
7
|
class Line < Base
|
24
8
|
attr_accessor :period, :description, :count, :vat_percentage, :amount
|
25
9
|
|
26
10
|
def amount=(amount)
|
27
|
-
@amount =
|
11
|
+
@amount = Mollie::Amount.new(amount)
|
28
12
|
end
|
29
13
|
end
|
30
14
|
|
31
|
-
attr_accessor :
|
32
|
-
:
|
15
|
+
attr_accessor :id,
|
16
|
+
:reference,
|
17
|
+
:vat_number,
|
18
|
+
:status,
|
19
|
+
:issued_at,
|
20
|
+
:paid_at,
|
21
|
+
:due_at,
|
22
|
+
:net_amount,
|
23
|
+
:vat_amount,
|
24
|
+
:gross_amount,
|
25
|
+
:lines,
|
26
|
+
:_links
|
27
|
+
|
28
|
+
alias_method :links, :_links
|
33
29
|
|
34
30
|
def open?
|
35
31
|
status == STATUS_OPEN
|
@@ -43,16 +39,24 @@ module Mollie
|
|
43
39
|
status == STATUS_OVERDUE
|
44
40
|
end
|
45
41
|
|
46
|
-
def
|
47
|
-
@
|
42
|
+
def net_amount=(net_amount)
|
43
|
+
@net_amount = Mollie::Amount.new(net_amount)
|
44
|
+
end
|
45
|
+
|
46
|
+
def vat_amount=(vat_amount)
|
47
|
+
@vat_amount = Mollie::Amount.new(vat_amount)
|
48
|
+
end
|
49
|
+
|
50
|
+
def gross_amount=(gross_amount)
|
51
|
+
@gross_amount = Mollie::Amount.new(gross_amount)
|
48
52
|
end
|
49
53
|
|
50
|
-
def
|
51
|
-
@
|
54
|
+
def issued_at=(issued_at)
|
55
|
+
@issued_at = Time.parse(issued_at) rescue nil
|
52
56
|
end
|
53
57
|
|
54
|
-
def
|
55
|
-
@
|
58
|
+
def due_at=(due_at)
|
59
|
+
@due_at = Time.parse(due_at) rescue nil
|
56
60
|
end
|
57
61
|
|
58
62
|
def lines=(lines)
|
@@ -60,7 +64,7 @@ module Mollie
|
|
60
64
|
end
|
61
65
|
|
62
66
|
def pdf
|
63
|
-
links
|
67
|
+
Util.extract_url(links, 'pdf')
|
64
68
|
end
|
65
69
|
end
|
66
70
|
end
|