mollie-api-ruby 1.4.2 → 2.0.0
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/.travis.yml +12 -0
- data/CHANGELOG.md +6 -0
- data/README.mdown +5 -5
- data/Rakefile +6 -0
- data/examples/1-new-payment.rb +4 -5
- data/examples/2-webhook-verification.rb +2 -2
- data/examples/4-ideal-payment.rb +3 -3
- data/examples/5-payments-history.rb +3 -3
- data/examples/6-list-activated-methods.rb +3 -3
- data/examples/7-refund-payment.rb +5 -5
- data/lib/{Mollie/API → mollie/api}/cacert.pem +0 -0
- data/lib/mollie/api/client.rb +120 -0
- data/lib/{Mollie/API/Client/Version.rb → mollie/api/client/version.rb} +1 -1
- data/lib/{Mollie/API/Exception.rb → mollie/api/exception.rb} +0 -0
- data/lib/mollie/api/object/base.rb +18 -0
- data/lib/mollie/api/object/customer.rb +28 -0
- data/lib/{Mollie/API/Object/Issuer.rb → mollie/api/object/issuer.rb} +1 -3
- data/lib/mollie/api/object/list.rb +44 -0
- data/lib/mollie/api/object/mandate.rb +35 -0
- data/lib/{Mollie/API/Object/Method.rb → mollie/api/object/method.rb} +12 -4
- data/lib/mollie/api/object/payment.rb +123 -0
- data/lib/mollie/api/object/payment/refund.rb +43 -0
- data/lib/mollie/api/object/subscription.rb +67 -0
- data/lib/{Mollie/API/Resource/Base.rb → mollie/api/resource/base.rb} +8 -8
- data/lib/{Mollie/API/Resource/Customers.rb → mollie/api/resource/customers.rb} +2 -2
- data/lib/{Mollie/API/Resource/Customers/Mandates.rb → mollie/api/resource/customers/mandates.rb} +5 -5
- data/lib/{Mollie/API/Resource/Customers/Payments.rb → mollie/api/resource/customers/payments.rb} +5 -5
- data/lib/mollie/api/resource/customers/subscriptions.rb +27 -0
- data/lib/{Mollie/API/Resource/Issuers.rb → mollie/api/resource/issuers.rb} +2 -2
- data/lib/{Mollie/API/Resource/Methods.rb → mollie/api/resource/methods.rb} +2 -2
- data/lib/{Mollie/API/Resource/Payments.rb → mollie/api/resource/payments.rb} +2 -2
- data/lib/{Mollie/API/Resource/Payments/Refunds.rb → mollie/api/resource/payments/refunds.rb} +5 -5
- data/lib/mollie/api/util.rb +37 -0
- data/mollie.gemspec +16 -14
- data/test/helper.rb +4 -0
- data/test/mollie/api/client_test.rb +99 -0
- data/test/mollie/api/object/base_test.rb +21 -0
- data/test/mollie/api/object/customer_test.rb +35 -0
- data/test/mollie/api/object/issuer_test.rb +23 -0
- data/test/mollie/api/object/list_test.rb +44 -0
- data/test/mollie/api/object/mandate_test.rb +45 -0
- data/test/mollie/api/object/method_test.rb +33 -0
- data/test/mollie/api/object/payment/refund_test.rb +46 -0
- data/test/mollie/api/object/payment_test.rb +91 -0
- data/test/mollie/api/object/subscription_test.rb +68 -0
- data/test/mollie/api/resource/base_test.rb +83 -0
- data/test/mollie/api/resource/customers/mandates_test.rb +23 -0
- data/test/mollie/api/resource/customers/payments_test.rb +23 -0
- data/test/mollie/api/resource/customers/subscriptions_test.rb +23 -0
- data/test/mollie/api/resource/customers_test.rb +13 -0
- data/test/mollie/api/resource/issuers_test.rb +13 -0
- data/test/mollie/api/resource/methods_test.rb +13 -0
- data/test/mollie/api/resource/payments/refunds_test.rb +23 -0
- data/test/mollie/api/resource/payments_test.rb +13 -0
- data/test/run-test.rb +15 -0
- metadata +99 -52
- data/lib/Mollie/API/Client.rb +0 -130
- data/lib/Mollie/API/Object/Base.rb +0 -18
- data/lib/Mollie/API/Object/Customer.rb +0 -16
- data/lib/Mollie/API/Object/List.rb +0 -35
- data/lib/Mollie/API/Object/Mandate.rb +0 -22
- data/lib/Mollie/API/Object/Payment.rb +0 -68
- data/lib/Mollie/API/Object/Payment/Refund.rb +0 -15
- data/lib/Mollie/API/Object/Subscription.rb +0 -26
- data/lib/Mollie/API/Resource/Customers/Subscriptions.rb +0 -27
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
module API
|
5
|
+
module Resource
|
6
|
+
class Customers
|
7
|
+
class Subscriptions < Base
|
8
|
+
@customer_id = nil
|
9
|
+
|
10
|
+
def resource_object
|
11
|
+
Object::Subscription
|
12
|
+
end
|
13
|
+
|
14
|
+
def resource_name
|
15
|
+
customer_id = URI::encode(@customer_id)
|
16
|
+
"customers/#{customer_id}/subscriptions"
|
17
|
+
end
|
18
|
+
|
19
|
+
def with(customer_or_id)
|
20
|
+
@customer_id = customer_or_id.is_a?(Object::Customer) ? customer_or_id.id : customer_or_id
|
21
|
+
self
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/{Mollie/API/Resource/Payments/Refunds.rb → mollie/api/resource/payments/refunds.rb}
RENAMED
@@ -7,17 +7,17 @@ module Mollie
|
|
7
7
|
class Refunds < Base
|
8
8
|
@payment_id = nil
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def resource_object
|
11
|
+
Object::Payment::Refund
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def resource_name
|
15
15
|
payment_id = URI::encode(@payment_id)
|
16
16
|
"payments/#{payment_id}/refunds"
|
17
17
|
end
|
18
18
|
|
19
|
-
def with(
|
20
|
-
@payment_id =
|
19
|
+
def with(payment_or_id)
|
20
|
+
@payment_id = payment_or_id.is_a?(Object::Payment) ? payment_or_id.id : payment_or_id
|
21
21
|
self
|
22
22
|
end
|
23
23
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Util
|
2
|
+
extend self
|
3
|
+
|
4
|
+
def nested_underscore_keys(hash)
|
5
|
+
hash.each_with_object({}) do |(key, value), underscored|
|
6
|
+
if value.is_a?(Hash)
|
7
|
+
underscored[underscore(key)] = nested_underscore_keys(value)
|
8
|
+
elsif value.is_a?(Array)
|
9
|
+
underscored[underscore(key)] = value.map { |v| nested_underscore_keys(v) }
|
10
|
+
else
|
11
|
+
underscored[underscore(key)] = value
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def camelize_keys(hash)
|
17
|
+
hash.each_with_object({}) do |(key, value), camelized|
|
18
|
+
camelized[camelize(key)] = value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def underscore(string)
|
23
|
+
string.to_s.gsub(/::/, '/').
|
24
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
25
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
26
|
+
tr("-", "_").
|
27
|
+
downcase.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
def camelize(term)
|
31
|
+
string = term.to_s
|
32
|
+
string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
|
33
|
+
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
|
34
|
+
string.gsub!('/'.freeze, '::'.freeze)
|
35
|
+
string
|
36
|
+
end
|
37
|
+
end
|
data/mollie.gemspec
CHANGED
@@ -1,24 +1,26 @@
|
|
1
|
-
$:.
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'mollie/api/client/version'
|
4
4
|
|
5
|
-
|
5
|
+
Gem::Specification.new do |s|
|
6
6
|
s.name = 'mollie-api-ruby'
|
7
|
-
s.version = Mollie::API::Client::
|
7
|
+
s.version = Mollie::API::Client::VERSION
|
8
8
|
s.summary = 'Official Mollie API Client for Ruby'
|
9
|
-
s.description =
|
10
|
-
|
9
|
+
s.description = %(Accepting iDEAL, Bancontact/Mister Cash, SOFORT Banking,
|
10
|
+
Creditcard, SEPA Bank transfer, SEPA Direct debit, Bitcoin,
|
11
|
+
PayPal, KBC Payment Button, CBC Payment Button, Belfius Direct
|
12
|
+
Net, paysafecard and PODIUM Cadeaukaart online payments without
|
13
|
+
fixed monthly costs or any punishing registration procedures.')
|
14
|
+
s.authors = ['Mollie B.V.']
|
11
15
|
s.email = ['info@mollie.nl']
|
12
16
|
s.homepage = 'https://github.com/mollie/mollie-api-ruby'
|
13
17
|
s.license = 'BSD'
|
14
|
-
s.required_ruby_version = '>=
|
15
|
-
|
16
|
-
s.add_dependency('rest-client', '~> 1.8')
|
17
|
-
s.add_dependency('json', '~> 1.8')
|
18
|
-
s.add_dependency('mime-types', '< 3')
|
18
|
+
s.required_ruby_version = '>= 2.0.0'
|
19
19
|
|
20
20
|
s.files = `git ls-files`.split("\n")
|
21
|
-
s.test_files
|
22
|
-
|
23
|
-
s.
|
21
|
+
s.test_files = Dir['test/**/*']
|
22
|
+
|
23
|
+
s.add_development_dependency("rake")
|
24
|
+
s.add_development_dependency("test-unit")
|
25
|
+
s.add_development_dependency("webmock")
|
24
26
|
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
module API
|
5
|
+
class ClientTest < Test::Unit::TestCase
|
6
|
+
def client
|
7
|
+
Client.new("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM")
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_initialize
|
11
|
+
assert_equal "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM", client.api_key
|
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
|
+
assert_kind_of Mollie::API::Resource::Customers, client.customers
|
18
|
+
assert_kind_of Mollie::API::Resource::Customers::Payments, client.customers_payments
|
19
|
+
assert_kind_of Mollie::API::Resource::Customers::Mandates, client.customers_mandates
|
20
|
+
assert_kind_of Mollie::API::Resource::Customers::Subscriptions, client.customers_subscriptions
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_setting_the_api_endpoint
|
24
|
+
client = self.client
|
25
|
+
client.api_endpoint = "http://my.endpoint/"
|
26
|
+
assert_equal "http://my.endpoint", client.api_endpoint
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_perform_http_call_defaults
|
30
|
+
stub_request(:any, "https://api.mollie.nl/v1/my-method")
|
31
|
+
.with(:headers => { 'Accept' => 'application/json',
|
32
|
+
'Authorization' => 'Bearer test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM',
|
33
|
+
'User-Agent' => /^Mollie\/#{Mollie::API::Client::VERSION} Ruby\/#{RUBY_VERSION} OpenSSL\/.*$/ })
|
34
|
+
.to_return(:status => 200, :body => "{}", :headers => {})
|
35
|
+
client.perform_http_call("GET", "my-method", nil, {})
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_get_requests_convert_to_snake_case
|
39
|
+
response_body = <<-JSON
|
40
|
+
{
|
41
|
+
"someCamelCased" : {
|
42
|
+
"alsoNested": "camelCaseValue"
|
43
|
+
},
|
44
|
+
"evenLists": [
|
45
|
+
{
|
46
|
+
"withCamelCase": "camelCaseValue"
|
47
|
+
}
|
48
|
+
]
|
49
|
+
}
|
50
|
+
JSON
|
51
|
+
|
52
|
+
expected_response = {
|
53
|
+
'some_camel_cased' =>
|
54
|
+
{ 'also_nested' => "camelCaseValue" },
|
55
|
+
'even_lists' => [
|
56
|
+
{ 'with_camel_case' => "camelCaseValue" }
|
57
|
+
]
|
58
|
+
}
|
59
|
+
|
60
|
+
stub_request(:get, "https://api.mollie.nl/v1/my-method")
|
61
|
+
.to_return(:status => 200, :body => response_body, :headers => {})
|
62
|
+
response = client.perform_http_call("GET", "my-method", nil, {})
|
63
|
+
|
64
|
+
assert_equal expected_response, response
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_post_requests_convert_to_camel_case
|
68
|
+
expected_body = %{{"redirectUrl":"my-url"}}
|
69
|
+
|
70
|
+
stub_request(:post, "https://api.mollie.nl/v1/my-method")
|
71
|
+
.with(body: expected_body)
|
72
|
+
.to_return(:status => 200, :body => "{}", :headers => {})
|
73
|
+
|
74
|
+
client.perform_http_call("POST", "my-method", nil, redirect_url: "my-url")
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_delete_requests_with_no_content_responses
|
78
|
+
stub_request(:delete, "https://api.mollie.nl/v1/my-method/1")
|
79
|
+
.to_return(:status => 204, :body => "", :headers => {})
|
80
|
+
|
81
|
+
client.perform_http_call("DELETE", "my-method", "1")
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_error_response
|
85
|
+
response = <<-JSON
|
86
|
+
{"error": {"message": "Error on field", "field": "my-field"}}
|
87
|
+
JSON
|
88
|
+
stub_request(:post, "https://api.mollie.nl/v1/my-method")
|
89
|
+
.to_return(:status => 500, :body => response, :headers => {})
|
90
|
+
|
91
|
+
e = assert_raise Mollie::API::Exception.new("Error on field") do
|
92
|
+
client.perform_http_call("POST", "my-method", nil, {})
|
93
|
+
end
|
94
|
+
|
95
|
+
assert_equal "my-field", e.field
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
module API
|
5
|
+
module Object
|
6
|
+
class TestObject < Base
|
7
|
+
attr_accessor :my_field
|
8
|
+
end
|
9
|
+
|
10
|
+
class BaseTest < Test::Unit::TestCase
|
11
|
+
def test_setting_attributes
|
12
|
+
attributes = {my_field: "my value", extra_field: "extra"}
|
13
|
+
object = TestObject.new(attributes)
|
14
|
+
|
15
|
+
assert_equal "my value", object.my_field
|
16
|
+
assert_equal attributes, object.attributes
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
module API
|
5
|
+
module Object
|
6
|
+
class CustomerTest < Test::Unit::TestCase
|
7
|
+
def test_setting_attributes
|
8
|
+
attributes = {
|
9
|
+
id: 'cst_vsKJpSsabw',
|
10
|
+
mode: 'test',
|
11
|
+
name: 'Customer A',
|
12
|
+
email: 'customer@example.org',
|
13
|
+
locale: 'nl_NL',
|
14
|
+
metadata: { my_field: 'value' },
|
15
|
+
recently_used_methods: 'creditcard',
|
16
|
+
created_datetime: '2016-04-06T13:23:21.0Z'
|
17
|
+
}
|
18
|
+
|
19
|
+
customer = Customer.new(attributes)
|
20
|
+
|
21
|
+
assert_equal 'cst_vsKJpSsabw', customer.id
|
22
|
+
assert_equal 'test', customer.mode
|
23
|
+
assert_equal 'Customer A', customer.name
|
24
|
+
assert_equal 'customer@example.org', customer.email
|
25
|
+
assert_equal 'nl_NL', customer.locale
|
26
|
+
assert_equal ['creditcard'], customer.recently_used_methods
|
27
|
+
assert_equal Time.parse('2016-04-06T13:23:21.0Z'), customer.created_datetime
|
28
|
+
|
29
|
+
assert_equal 'value', customer.metadata.my_field
|
30
|
+
assert_equal nil, customer.metadata.non_existing
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
module API
|
5
|
+
module Object
|
6
|
+
class IssuerTest < Test::Unit::TestCase
|
7
|
+
def test_setting_attributes
|
8
|
+
attributes = {
|
9
|
+
id: 'ideal_ABNANL2A',
|
10
|
+
name: 'ABN AMRO',
|
11
|
+
method: 'ideal'
|
12
|
+
}
|
13
|
+
|
14
|
+
customer = Issuer.new(attributes)
|
15
|
+
|
16
|
+
assert_equal 'ideal_ABNANL2A', customer.id
|
17
|
+
assert_equal 'ABN AMRO', customer.name
|
18
|
+
assert_equal 'ideal', customer.method
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
module API
|
5
|
+
module Object
|
6
|
+
class ListTest < Test::Unit::TestCase
|
7
|
+
def test_setting_attributes
|
8
|
+
attributes = {
|
9
|
+
'total_count' => 280,
|
10
|
+
'offset' => 0,
|
11
|
+
'count' => 10,
|
12
|
+
'data' => [
|
13
|
+
{ 'id' => "tr_1" },
|
14
|
+
{ 'id' => "tr_2" },
|
15
|
+
],
|
16
|
+
'links' => {
|
17
|
+
'first' => "https://api.mollie.nl/v1/payments?count=10&offset=0",
|
18
|
+
'previous' => nil,
|
19
|
+
'next' => "https://api.mollie.nl/v1/payments?count=10&offset=10",
|
20
|
+
'last' => "https://api.mollie.nl/v1/payments?count=10&offset=270"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
list = List.new(attributes, Payment)
|
25
|
+
|
26
|
+
assert_equal 280, list.total_count
|
27
|
+
assert_equal 0, list.offset
|
28
|
+
assert_equal 10, list.count
|
29
|
+
|
30
|
+
assert_kind_of Payment, list.to_a[0]
|
31
|
+
assert_equal "tr_1", list.to_a[0].id
|
32
|
+
|
33
|
+
assert_kind_of Payment, list.to_a[1]
|
34
|
+
assert_equal "tr_2", list.to_a[1].id
|
35
|
+
|
36
|
+
assert_equal "https://api.mollie.nl/v1/payments?count=10&offset=0", list.first_url
|
37
|
+
assert_equal nil, list.previous_url
|
38
|
+
assert_equal "https://api.mollie.nl/v1/payments?count=10&offset=10", list.next_url
|
39
|
+
assert_equal "https://api.mollie.nl/v1/payments?count=10&offset=270", list.last_url
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
module API
|
5
|
+
module Object
|
6
|
+
class MandateTest < Test::Unit::TestCase
|
7
|
+
def test_setting_attributes
|
8
|
+
attributes = {
|
9
|
+
id: "mdt_qtUgejVgMN",
|
10
|
+
status: "valid",
|
11
|
+
method: "creditcard",
|
12
|
+
customer_id: "cst_R6JLAuqEgm",
|
13
|
+
details: {
|
14
|
+
card_holder: "John Doe",
|
15
|
+
card_expiry_date: "2016-03-31"
|
16
|
+
},
|
17
|
+
created_datetime: "2016-04-13T11:32:38.0Z"
|
18
|
+
}
|
19
|
+
|
20
|
+
mandate = Mandate.new(attributes)
|
21
|
+
|
22
|
+
assert_equal 'mdt_qtUgejVgMN', mandate.id
|
23
|
+
assert_equal 'valid', mandate.status
|
24
|
+
assert_equal 'creditcard', mandate.method
|
25
|
+
assert_equal 'cst_R6JLAuqEgm', mandate.customer_id
|
26
|
+
assert_equal Time.parse('2016-04-13T11:32:38.0Z'), mandate.created_datetime
|
27
|
+
|
28
|
+
assert_equal 'John Doe', mandate.details.card_holder
|
29
|
+
assert_equal '2016-03-31', mandate.details.card_expiry_date
|
30
|
+
assert_equal nil, mandate.details.non_existing
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_valid_invalid
|
34
|
+
mandate = Mandate.new(status: Mandate::STATUS_VALID)
|
35
|
+
assert mandate.valid?
|
36
|
+
assert !mandate.invalid?
|
37
|
+
|
38
|
+
mandate = Mandate.new(status: Mandate::STATUS_INVALID)
|
39
|
+
assert !mandate.valid?
|
40
|
+
assert mandate.invalid?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|