mollie-api-ruby 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -2
- data/CHANGELOG.md +4 -0
- data/{README.mdown → README.md} +8 -8
- data/examples/1-new-payment.rb +4 -2
- data/examples/4-ideal-payment.rb +4 -2
- data/lib/mollie/api/client.rb +32 -13
- data/lib/mollie/api/client/version.rb +1 -1
- data/lib/mollie/api/object/customer/mandate.rb +37 -0
- data/lib/mollie/api/object/customer/subscription.rb +69 -0
- data/lib/mollie/api/object/organization.rb +28 -0
- data/lib/mollie/api/object/permission.rb +12 -0
- data/lib/mollie/api/object/profile.rb +78 -0
- data/lib/mollie/api/object/profile/apikey.rb +23 -0
- data/lib/mollie/api/object/settlement.rb +32 -0
- data/lib/mollie/api/resource/customers/mandates.rb +1 -1
- data/lib/mollie/api/resource/customers/subscriptions.rb +1 -1
- data/lib/mollie/api/resource/organizations.rb +11 -0
- data/lib/mollie/api/resource/permissions.rb +11 -0
- data/lib/mollie/api/resource/profiles.rb +11 -0
- data/lib/mollie/api/resource/profiles/apikeys.rb +27 -0
- data/lib/mollie/api/resource/settlements.rb +11 -0
- data/lib/mollie/api/util.rb +46 -30
- data/test/mollie/api/client_test.rb +9 -4
- data/test/mollie/api/object/customer/mandate_test.rb +47 -0
- data/test/mollie/api/object/customer/subscription_test.rb +70 -0
- data/test/mollie/api/object/organization_test.rb +51 -0
- data/test/mollie/api/object/permission_test.rb +25 -0
- data/test/mollie/api/object/profile/apikey_test.rb +35 -0
- data/test/mollie/api/object/profile_test.rb +72 -0
- data/test/mollie/api/object/settlement_test.rb +140 -0
- data/test/mollie/api/resource/customers/mandates_test.rb +1 -1
- data/test/mollie/api/resource/customers/subscriptions_test.rb +1 -1
- data/test/mollie/api/resource/organizations_test.rb +13 -0
- data/test/mollie/api/resource/permissions_test.rb +13 -0
- data/test/mollie/api/resource/profiles/apikeys_test.rb +23 -0
- data/test/mollie/api/resource/profiles_test.rb +13 -0
- data/test/mollie/api/resource/settlements_test.rb +13 -0
- data/test/mollie/api/util_test.rb +47 -0
- metadata +42 -10
- data/lib/mollie/api/object/mandate.rb +0 -35
- data/lib/mollie/api/object/subscription.rb +0 -67
- data/test/mollie/api/object/mandate_test.rb +0 -45
- data/test/mollie/api/object/subscription_test.rb +0 -68
@@ -0,0 +1,32 @@
|
|
1
|
+
module Mollie
|
2
|
+
module API
|
3
|
+
module Object
|
4
|
+
class Settlement < Base
|
5
|
+
attr_accessor :id,
|
6
|
+
:reference,
|
7
|
+
:settled_datetime,
|
8
|
+
:amount,
|
9
|
+
:periods,
|
10
|
+
:payment_ids,
|
11
|
+
:refund_ids,
|
12
|
+
:links
|
13
|
+
|
14
|
+
def settled_datetime=(settled_datetime)
|
15
|
+
@settled_datetime = Time.parse(settled_datetime.to_s) rescue nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def amount=(amount)
|
19
|
+
@amount = BigDecimal.new(amount.to_s) if amount
|
20
|
+
end
|
21
|
+
|
22
|
+
def periods=(periods)
|
23
|
+
@periods = Util.nested_openstruct(periods) if periods.is_a?(Hash)
|
24
|
+
end
|
25
|
+
|
26
|
+
def payments
|
27
|
+
links && links['payments']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
module API
|
5
|
+
module Resource
|
6
|
+
class Profiles
|
7
|
+
class ApiKeys < Base
|
8
|
+
@profile_id = nil
|
9
|
+
|
10
|
+
def resource_object
|
11
|
+
Object::Profile::ApiKey
|
12
|
+
end
|
13
|
+
|
14
|
+
def resource_name
|
15
|
+
profile_id = URI::encode(@profile_id)
|
16
|
+
"profiles/#{profile_id}/apikeys"
|
17
|
+
end
|
18
|
+
|
19
|
+
def with(profile_or_id)
|
20
|
+
@profile_id = profile_or_id.is_a?(Object::Profile) ? profile_or_id.id : profile_or_id
|
21
|
+
self
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/mollie/api/util.rb
CHANGED
@@ -1,37 +1,53 @@
|
|
1
|
-
module
|
2
|
-
|
1
|
+
module Mollie
|
2
|
+
module API
|
3
|
+
module Util
|
4
|
+
extend self
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
def nested_underscore_keys(obj)
|
7
|
+
if obj.is_a?(Hash)
|
8
|
+
obj.each_with_object({}) do |(key, value), underscored|
|
9
|
+
underscored[underscore(key)] = nested_underscore_keys(value)
|
10
|
+
end
|
11
|
+
elsif obj.is_a?(Array)
|
12
|
+
obj.map { |v| nested_underscore_keys(v) }
|
13
|
+
else
|
14
|
+
obj
|
15
|
+
end
|
12
16
|
end
|
13
|
-
end
|
14
|
-
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def camelize_keys(hash)
|
19
|
+
hash.each_with_object({}) do |(key, value), camelized|
|
20
|
+
camelized[camelize(key)] = value
|
21
|
+
end
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
def underscore(string)
|
25
|
+
string.to_s.gsub(/::/, '/').
|
26
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
27
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
28
|
+
tr("-", "_").
|
29
|
+
downcase.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def camelize(term)
|
33
|
+
string = term.to_s
|
34
|
+
string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
|
35
|
+
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
|
36
|
+
string.gsub!('/'.freeze, '::'.freeze)
|
37
|
+
string
|
38
|
+
end
|
29
39
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
40
|
+
def nested_openstruct(obj)
|
41
|
+
if obj.is_a?(Hash)
|
42
|
+
obj.each_with_object(OpenStruct.new) do |(key, value), openstructed|
|
43
|
+
openstructed[key] = nested_openstruct(value)
|
44
|
+
end
|
45
|
+
elsif obj.is_a?(Array)
|
46
|
+
obj.map { |v| nested_openstruct(v) }
|
47
|
+
else
|
48
|
+
obj
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
36
52
|
end
|
37
53
|
end
|
@@ -10,14 +10,19 @@ module Mollie
|
|
10
10
|
def test_initialize
|
11
11
|
assert_equal "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM", client.api_key
|
12
12
|
|
13
|
-
assert_kind_of Mollie::API::Resource::Payments, client.payments
|
14
|
-
assert_kind_of Mollie::API::Resource::Issuers, client.issuers
|
15
|
-
assert_kind_of Mollie::API::Resource::Methods, client.methods
|
16
|
-
assert_kind_of Mollie::API::Resource::Payments::Refunds, client.payments_refunds
|
17
13
|
assert_kind_of Mollie::API::Resource::Customers, client.customers
|
18
14
|
assert_kind_of Mollie::API::Resource::Customers::Payments, client.customers_payments
|
19
15
|
assert_kind_of Mollie::API::Resource::Customers::Mandates, client.customers_mandates
|
20
16
|
assert_kind_of Mollie::API::Resource::Customers::Subscriptions, client.customers_subscriptions
|
17
|
+
assert_kind_of Mollie::API::Resource::Issuers, client.issuers
|
18
|
+
assert_kind_of Mollie::API::Resource::Methods, client.methods
|
19
|
+
assert_kind_of Mollie::API::Resource::Organizations, client.organizations
|
20
|
+
assert_kind_of Mollie::API::Resource::Payments, client.payments
|
21
|
+
assert_kind_of Mollie::API::Resource::Payments::Refunds, client.payments_refunds
|
22
|
+
assert_kind_of Mollie::API::Resource::Permissions, client.permissions
|
23
|
+
assert_kind_of Mollie::API::Resource::Profiles, client.profiles
|
24
|
+
assert_kind_of Mollie::API::Resource::Profiles::ApiKeys, client.profiles_api_keys
|
25
|
+
assert_kind_of Mollie::API::Resource::Settlements, client.settlements
|
21
26
|
end
|
22
27
|
|
23
28
|
def test_setting_the_api_endpoint
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
module API
|
5
|
+
module Object
|
6
|
+
class Customer
|
7
|
+
class MandateTest < Test::Unit::TestCase
|
8
|
+
def test_setting_attributes
|
9
|
+
attributes = {
|
10
|
+
id: "mdt_qtUgejVgMN",
|
11
|
+
status: "valid",
|
12
|
+
method: "creditcard",
|
13
|
+
customer_id: "cst_R6JLAuqEgm",
|
14
|
+
details: {
|
15
|
+
card_holder: "John Doe",
|
16
|
+
card_expiry_date: "2016-03-31"
|
17
|
+
},
|
18
|
+
created_datetime: "2016-04-13T11:32:38.0Z"
|
19
|
+
}
|
20
|
+
|
21
|
+
mandate = Mandate.new(attributes)
|
22
|
+
|
23
|
+
assert_equal 'mdt_qtUgejVgMN', mandate.id
|
24
|
+
assert_equal 'valid', mandate.status
|
25
|
+
assert_equal 'creditcard', mandate.method
|
26
|
+
assert_equal 'cst_R6JLAuqEgm', mandate.customer_id
|
27
|
+
assert_equal Time.parse('2016-04-13T11:32:38.0Z'), mandate.created_datetime
|
28
|
+
|
29
|
+
assert_equal 'John Doe', mandate.details.card_holder
|
30
|
+
assert_equal '2016-03-31', mandate.details.card_expiry_date
|
31
|
+
assert_equal nil, mandate.details.non_existing
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_valid_invalid
|
35
|
+
mandate = Mandate.new(status: Mandate::STATUS_VALID)
|
36
|
+
assert mandate.valid?
|
37
|
+
assert !mandate.invalid?
|
38
|
+
|
39
|
+
mandate = Mandate.new(status: Mandate::STATUS_INVALID)
|
40
|
+
assert !mandate.valid?
|
41
|
+
assert mandate.invalid?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
module API
|
5
|
+
module Object
|
6
|
+
class Customer
|
7
|
+
class SubscriptionTest < Test::Unit::TestCase
|
8
|
+
def test_setting_attributes
|
9
|
+
attributes = {
|
10
|
+
id: "sub_rVKGtNd6s3",
|
11
|
+
customer_id: "cst_stTC2WHAuS",
|
12
|
+
mode: "live",
|
13
|
+
created_datetime: "2016-06-01T12:23:34.0Z",
|
14
|
+
status: "active",
|
15
|
+
amount: "25.00",
|
16
|
+
times: 4,
|
17
|
+
interval: "3 months",
|
18
|
+
description: "Quarterly payment",
|
19
|
+
method: "creditcard",
|
20
|
+
cancelled_datetime: "2016-06-01T12:23:34.0Z",
|
21
|
+
links: {
|
22
|
+
'webhook_url' => "https://example.org/payments/webhook"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
subscription = Subscription.new(attributes)
|
27
|
+
|
28
|
+
assert_equal "sub_rVKGtNd6s3", subscription.id
|
29
|
+
assert_equal "cst_stTC2WHAuS", subscription.customer_id
|
30
|
+
assert_equal "live", subscription.mode
|
31
|
+
assert_equal Time.parse("2016-06-01T12:23:34.0Z"), subscription.created_datetime
|
32
|
+
assert_equal "active", subscription.status
|
33
|
+
assert_equal BigDecimal.new(25, 2), subscription.amount
|
34
|
+
assert_equal 4, subscription.times
|
35
|
+
assert_equal "3 months", subscription.interval
|
36
|
+
assert_equal "Quarterly payment", subscription.description
|
37
|
+
assert_equal "creditcard", subscription.method
|
38
|
+
assert_equal Time.parse("2016-06-01T12:23:34.0Z"), subscription.cancelled_datetime
|
39
|
+
assert_equal "https://example.org/payments/webhook", subscription.webhook_url
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_status_active
|
43
|
+
assert Subscription.new(status: Subscription::STATUS_ACTIVE).active?
|
44
|
+
assert !Subscription.new(status: 'not-active').active?
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_status_pending
|
48
|
+
assert Subscription.new(status: Subscription::STATUS_PENDING).pending?
|
49
|
+
assert !Subscription.new(status: 'not-pending').pending?
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_status_suspended
|
53
|
+
assert Subscription.new(status: Subscription::STATUS_SUSPENDED).suspended?
|
54
|
+
assert !Subscription.new(status: 'not-suspended').suspended?
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_status_cancelled
|
58
|
+
assert Subscription.new(status: Subscription::STATUS_CANCELLED).cancelled?
|
59
|
+
assert !Subscription.new(status: 'not-cancelled').cancelled?
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_status_completed
|
63
|
+
assert Subscription.new(status: Subscription::STATUS_COMPLETED).completed?
|
64
|
+
assert !Subscription.new(status: 'not-completed').completed?
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
module API
|
5
|
+
module Object
|
6
|
+
class OrganizationTest < Test::Unit::TestCase
|
7
|
+
def test_setting_attributes
|
8
|
+
attributes = {
|
9
|
+
id: 'org_1234567',
|
10
|
+
name: 'Mollie B.V.',
|
11
|
+
email: 'info@mollie.com',
|
12
|
+
address: 'Keizersgracht 313',
|
13
|
+
postal_code: '1016EE',
|
14
|
+
city: 'Amsterdam',
|
15
|
+
country: 'Netherlands',
|
16
|
+
country_code: 'NL',
|
17
|
+
registration_type: 'bv',
|
18
|
+
registration_number: '30204462',
|
19
|
+
registration_datetime: '2004-04-01T09:41:00.0Z',
|
20
|
+
verified_datetime: '2007-06-29T09:41:00.0Z'
|
21
|
+
}
|
22
|
+
|
23
|
+
organization = Organization.new(attributes)
|
24
|
+
|
25
|
+
assert_equal 'org_1234567', organization.id
|
26
|
+
assert_equal 'Mollie B.V.', organization.name
|
27
|
+
assert_equal 'info@mollie.com', organization.email
|
28
|
+
assert_equal 'Keizersgracht 313', organization.address
|
29
|
+
assert_equal '1016EE', organization.postal_code
|
30
|
+
assert_equal 'Amsterdam', organization.city
|
31
|
+
assert_equal 'Netherlands', organization.country
|
32
|
+
assert_equal 'NL', organization.country_code
|
33
|
+
assert_equal 'bv', organization.registration_type
|
34
|
+
assert_equal '30204462', organization.registration_number
|
35
|
+
assert_equal Time.parse('2004-04-01T09:41:00.0Z'), organization.registration_datetime
|
36
|
+
assert_equal Time.parse('2007-06-29T09:41:00.0Z'), organization.verified_datetime
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_registration_datetime_required
|
40
|
+
assert_raise ArgumentError.new('no time information in ""') do
|
41
|
+
Organization.new(registration_datetime: nil)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_verified_datetime_optional
|
46
|
+
assert_equal nil, Organization.new(verified_datetime: nil).verified_datetime
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
module API
|
5
|
+
module Object
|
6
|
+
class PermissionTest < Test::Unit::TestCase
|
7
|
+
def test_setting_attributes
|
8
|
+
attributes = {
|
9
|
+
id: 'payments.read',
|
10
|
+
description: 'View your payments',
|
11
|
+
warning: nil,
|
12
|
+
granted: true
|
13
|
+
}
|
14
|
+
|
15
|
+
permission = Permission.new(attributes)
|
16
|
+
|
17
|
+
assert_equal 'payments.read', permission.id
|
18
|
+
assert_equal 'View your payments', permission.description
|
19
|
+
assert_equal nil, permission.warning
|
20
|
+
assert_equal true, permission.granted
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
module API
|
5
|
+
module Object
|
6
|
+
class Profile
|
7
|
+
class ApiKeyTest < Test::Unit::TestCase
|
8
|
+
def test_setting_attributes
|
9
|
+
attributes = {
|
10
|
+
id: "live",
|
11
|
+
key: "live_eSf9fQRwpsdfPY8y3tUFFmqjADRKyA",
|
12
|
+
created_datetime: "2017-04-20T12:19:48.0Z"
|
13
|
+
}
|
14
|
+
|
15
|
+
api_key = ApiKey.new(attributes)
|
16
|
+
|
17
|
+
assert_equal Mollie::API::Client::MODE_LIVE, api_key.id
|
18
|
+
assert_equal "live_eSf9fQRwpsdfPY8y3tUFFmqjADRKyA", api_key.key
|
19
|
+
assert_equal Time.parse("2017-04-20T12:19:48.0Z"), api_key.created_datetime
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_testmode
|
23
|
+
assert ApiKey.new(id: Mollie::API::Client::MODE_TEST).testmode?
|
24
|
+
assert !ApiKey.new(id: 'not-test').testmode?
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_livemode
|
28
|
+
assert ApiKey.new(id: Mollie::API::Client::MODE_LIVE).livemode?
|
29
|
+
assert !ApiKey.new(id: 'not-live').livemode?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|