mollie-api-ruby 1.4.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +12 -0
  3. data/CHANGELOG.md +6 -0
  4. data/README.mdown +5 -5
  5. data/Rakefile +6 -0
  6. data/examples/1-new-payment.rb +4 -5
  7. data/examples/2-webhook-verification.rb +2 -2
  8. data/examples/4-ideal-payment.rb +3 -3
  9. data/examples/5-payments-history.rb +3 -3
  10. data/examples/6-list-activated-methods.rb +3 -3
  11. data/examples/7-refund-payment.rb +5 -5
  12. data/lib/{Mollie/API → mollie/api}/cacert.pem +0 -0
  13. data/lib/mollie/api/client.rb +120 -0
  14. data/lib/{Mollie/API/Client/Version.rb → mollie/api/client/version.rb} +1 -1
  15. data/lib/{Mollie/API/Exception.rb → mollie/api/exception.rb} +0 -0
  16. data/lib/mollie/api/object/base.rb +18 -0
  17. data/lib/mollie/api/object/customer.rb +28 -0
  18. data/lib/{Mollie/API/Object/Issuer.rb → mollie/api/object/issuer.rb} +1 -3
  19. data/lib/mollie/api/object/list.rb +44 -0
  20. data/lib/mollie/api/object/mandate.rb +35 -0
  21. data/lib/{Mollie/API/Object/Method.rb → mollie/api/object/method.rb} +12 -4
  22. data/lib/mollie/api/object/payment.rb +123 -0
  23. data/lib/mollie/api/object/payment/refund.rb +43 -0
  24. data/lib/mollie/api/object/subscription.rb +67 -0
  25. data/lib/{Mollie/API/Resource/Base.rb → mollie/api/resource/base.rb} +8 -8
  26. data/lib/{Mollie/API/Resource/Customers.rb → mollie/api/resource/customers.rb} +2 -2
  27. data/lib/{Mollie/API/Resource/Customers/Mandates.rb → mollie/api/resource/customers/mandates.rb} +5 -5
  28. data/lib/{Mollie/API/Resource/Customers/Payments.rb → mollie/api/resource/customers/payments.rb} +5 -5
  29. data/lib/mollie/api/resource/customers/subscriptions.rb +27 -0
  30. data/lib/{Mollie/API/Resource/Issuers.rb → mollie/api/resource/issuers.rb} +2 -2
  31. data/lib/{Mollie/API/Resource/Methods.rb → mollie/api/resource/methods.rb} +2 -2
  32. data/lib/{Mollie/API/Resource/Payments.rb → mollie/api/resource/payments.rb} +2 -2
  33. data/lib/{Mollie/API/Resource/Payments/Refunds.rb → mollie/api/resource/payments/refunds.rb} +5 -5
  34. data/lib/mollie/api/util.rb +37 -0
  35. data/mollie.gemspec +16 -14
  36. data/test/helper.rb +4 -0
  37. data/test/mollie/api/client_test.rb +99 -0
  38. data/test/mollie/api/object/base_test.rb +21 -0
  39. data/test/mollie/api/object/customer_test.rb +35 -0
  40. data/test/mollie/api/object/issuer_test.rb +23 -0
  41. data/test/mollie/api/object/list_test.rb +44 -0
  42. data/test/mollie/api/object/mandate_test.rb +45 -0
  43. data/test/mollie/api/object/method_test.rb +33 -0
  44. data/test/mollie/api/object/payment/refund_test.rb +46 -0
  45. data/test/mollie/api/object/payment_test.rb +91 -0
  46. data/test/mollie/api/object/subscription_test.rb +68 -0
  47. data/test/mollie/api/resource/base_test.rb +83 -0
  48. data/test/mollie/api/resource/customers/mandates_test.rb +23 -0
  49. data/test/mollie/api/resource/customers/payments_test.rb +23 -0
  50. data/test/mollie/api/resource/customers/subscriptions_test.rb +23 -0
  51. data/test/mollie/api/resource/customers_test.rb +13 -0
  52. data/test/mollie/api/resource/issuers_test.rb +13 -0
  53. data/test/mollie/api/resource/methods_test.rb +13 -0
  54. data/test/mollie/api/resource/payments/refunds_test.rb +23 -0
  55. data/test/mollie/api/resource/payments_test.rb +13 -0
  56. data/test/run-test.rb +15 -0
  57. metadata +99 -52
  58. data/lib/Mollie/API/Client.rb +0 -130
  59. data/lib/Mollie/API/Object/Base.rb +0 -18
  60. data/lib/Mollie/API/Object/Customer.rb +0 -16
  61. data/lib/Mollie/API/Object/List.rb +0 -35
  62. data/lib/Mollie/API/Object/Mandate.rb +0 -22
  63. data/lib/Mollie/API/Object/Payment.rb +0 -68
  64. data/lib/Mollie/API/Object/Payment/Refund.rb +0 -15
  65. data/lib/Mollie/API/Object/Subscription.rb +0 -26
  66. data/lib/Mollie/API/Resource/Customers/Subscriptions.rb +0 -27
@@ -0,0 +1,23 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ module API
5
+ module Resource
6
+ class Payments
7
+ class RefundsTest < Test::Unit::TestCase
8
+ def test_resource_object
9
+ assert_equal Object::Payment::Refund, Refunds.new(nil).resource_object
10
+ end
11
+
12
+ def test_resource_name_and_with
13
+ refunds = Refunds.new(nil).with("payment-id")
14
+ assert_equal "payments/payment-id/refunds", refunds.resource_name
15
+
16
+ refunds = Refunds.new(nil).with(Object::Payment.new(id: "payment-id"))
17
+ assert_equal "payments/payment-id/refunds", refunds.resource_name
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ module API
5
+ module Resource
6
+ class PaymentsTest < Test::Unit::TestCase
7
+ def test_resource_object
8
+ assert_equal Object::Payment, Payments.new(nil).resource_object
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
data/test/run-test.rb ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # From https://github.com/test-unit/test-unit/blob/master/test/run-test.rb
4
+
5
+ $KCODE = "utf8" unless "".respond_to?(:encoding)
6
+
7
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
8
+ lib_dir = File.join(base_dir, "lib")
9
+ test_dir = File.join(base_dir, "test")
10
+
11
+ $LOAD_PATH.unshift(lib_dir)
12
+
13
+ require 'test/unit'
14
+
15
+ exit Test::Unit::AutoRunner.run(true, test_dir)
metadata CHANGED
@@ -1,72 +1,76 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mollie-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Rick Wong
7
+ - Mollie B.V.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-19 00:00:00.000000000 Z
11
+ date: 2016-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rest-client
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '1.8'
20
- type: :runtime
19
+ version: '0'
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: '1.8'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: json
28
+ name: test-unit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: '1.8'
34
- type: :runtime
33
+ version: '0'
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: '1.8'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: mime-types
42
+ name: webmock
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "<"
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
- version: '3'
48
- type: :runtime
47
+ version: '0'
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "<"
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
- version: '3'
55
- description: Accepting iDEAL, Bancontact/Mister Cash, SOFORT Banking, Creditcard,
56
- SEPA Bank transfer, SEPA Direct debit, Bitcoin, PayPal, KBC Payment Button, CBC
57
- Payment Button, Belfius Direct Net, paysafecard and PODIUM Cadeaukaart online payments
58
- without fixed monthly costs or any punishing registration procedures.
54
+ version: '0'
55
+ description: |-
56
+ Accepting iDEAL, Bancontact/Mister Cash, SOFORT Banking,
57
+ Creditcard, SEPA Bank transfer, SEPA Direct debit, Bitcoin,
58
+ PayPal, KBC Payment Button, CBC Payment Button, Belfius Direct
59
+ Net, paysafecard and PODIUM Cadeaukaart online payments without
60
+ fixed monthly costs or any punishing registration procedures.'
59
61
  email:
60
62
  - info@mollie.nl
61
63
  executables: []
62
64
  extensions: []
63
65
  extra_rdoc_files: []
64
66
  files:
65
- - ".gitignore"
67
+ - .gitignore
68
+ - .travis.yml
66
69
  - CHANGELOG.md
67
70
  - Gemfile
68
71
  - LICENSE
69
72
  - README.mdown
73
+ - Rakefile
70
74
  - examples/1-new-payment.rb
71
75
  - examples/2-webhook-verification.rb
72
76
  - examples/3-return-page.rb
@@ -76,29 +80,51 @@ files:
76
80
  - examples/7-refund-payment.rb
77
81
  - examples/app.rb
78
82
  - examples/orders/.gitignore
79
- - lib/Mollie/API/Client.rb
80
- - lib/Mollie/API/Client/Version.rb
81
- - lib/Mollie/API/Exception.rb
82
- - lib/Mollie/API/Object/Base.rb
83
- - lib/Mollie/API/Object/Customer.rb
84
- - lib/Mollie/API/Object/Issuer.rb
85
- - lib/Mollie/API/Object/List.rb
86
- - lib/Mollie/API/Object/Mandate.rb
87
- - lib/Mollie/API/Object/Method.rb
88
- - lib/Mollie/API/Object/Payment.rb
89
- - lib/Mollie/API/Object/Payment/Refund.rb
90
- - lib/Mollie/API/Object/Subscription.rb
91
- - lib/Mollie/API/Resource/Base.rb
92
- - lib/Mollie/API/Resource/Customers.rb
93
- - lib/Mollie/API/Resource/Customers/Mandates.rb
94
- - lib/Mollie/API/Resource/Customers/Payments.rb
95
- - lib/Mollie/API/Resource/Customers/Subscriptions.rb
96
- - lib/Mollie/API/Resource/Issuers.rb
97
- - lib/Mollie/API/Resource/Methods.rb
98
- - lib/Mollie/API/Resource/Payments.rb
99
- - lib/Mollie/API/Resource/Payments/Refunds.rb
100
- - lib/Mollie/API/cacert.pem
83
+ - lib/mollie/api/cacert.pem
84
+ - lib/mollie/api/client.rb
85
+ - lib/mollie/api/client/version.rb
86
+ - lib/mollie/api/exception.rb
87
+ - lib/mollie/api/object/base.rb
88
+ - lib/mollie/api/object/customer.rb
89
+ - lib/mollie/api/object/issuer.rb
90
+ - lib/mollie/api/object/list.rb
91
+ - lib/mollie/api/object/mandate.rb
92
+ - lib/mollie/api/object/method.rb
93
+ - lib/mollie/api/object/payment.rb
94
+ - lib/mollie/api/object/payment/refund.rb
95
+ - lib/mollie/api/object/subscription.rb
96
+ - lib/mollie/api/resource/base.rb
97
+ - lib/mollie/api/resource/customers.rb
98
+ - lib/mollie/api/resource/customers/mandates.rb
99
+ - lib/mollie/api/resource/customers/payments.rb
100
+ - lib/mollie/api/resource/customers/subscriptions.rb
101
+ - lib/mollie/api/resource/issuers.rb
102
+ - lib/mollie/api/resource/methods.rb
103
+ - lib/mollie/api/resource/payments.rb
104
+ - lib/mollie/api/resource/payments/refunds.rb
105
+ - lib/mollie/api/util.rb
101
106
  - mollie.gemspec
107
+ - test/helper.rb
108
+ - test/mollie/api/client_test.rb
109
+ - test/mollie/api/object/base_test.rb
110
+ - test/mollie/api/object/customer_test.rb
111
+ - test/mollie/api/object/issuer_test.rb
112
+ - test/mollie/api/object/list_test.rb
113
+ - test/mollie/api/object/mandate_test.rb
114
+ - test/mollie/api/object/method_test.rb
115
+ - test/mollie/api/object/payment/refund_test.rb
116
+ - test/mollie/api/object/payment_test.rb
117
+ - test/mollie/api/object/subscription_test.rb
118
+ - test/mollie/api/resource/base_test.rb
119
+ - test/mollie/api/resource/customers/mandates_test.rb
120
+ - test/mollie/api/resource/customers/payments_test.rb
121
+ - test/mollie/api/resource/customers/subscriptions_test.rb
122
+ - test/mollie/api/resource/customers_test.rb
123
+ - test/mollie/api/resource/issuers_test.rb
124
+ - test/mollie/api/resource/methods_test.rb
125
+ - test/mollie/api/resource/payments/refunds_test.rb
126
+ - test/mollie/api/resource/payments_test.rb
127
+ - test/run-test.rb
102
128
  homepage: https://github.com/mollie/mollie-api-ruby
103
129
  licenses:
104
130
  - BSD
@@ -109,12 +135,12 @@ require_paths:
109
135
  - lib
110
136
  required_ruby_version: !ruby/object:Gem::Requirement
111
137
  requirements:
112
- - - ">="
138
+ - - '>='
113
139
  - !ruby/object:Gem::Version
114
- version: 1.9.3
140
+ version: 2.0.0
115
141
  required_rubygems_version: !ruby/object:Gem::Requirement
116
142
  requirements:
117
- - - ">="
143
+ - - '>='
118
144
  - !ruby/object:Gem::Version
119
145
  version: '0'
120
146
  requirements: []
@@ -123,4 +149,25 @@ rubygems_version: 2.4.8
123
149
  signing_key:
124
150
  specification_version: 4
125
151
  summary: Official Mollie API Client for Ruby
126
- test_files: []
152
+ test_files:
153
+ - test/helper.rb
154
+ - test/mollie/api/client_test.rb
155
+ - test/mollie/api/object/base_test.rb
156
+ - test/mollie/api/object/customer_test.rb
157
+ - test/mollie/api/object/issuer_test.rb
158
+ - test/mollie/api/object/list_test.rb
159
+ - test/mollie/api/object/mandate_test.rb
160
+ - test/mollie/api/object/method_test.rb
161
+ - test/mollie/api/object/payment/refund_test.rb
162
+ - test/mollie/api/object/payment_test.rb
163
+ - test/mollie/api/object/subscription_test.rb
164
+ - test/mollie/api/resource/base_test.rb
165
+ - test/mollie/api/resource/customers/mandates_test.rb
166
+ - test/mollie/api/resource/customers/payments_test.rb
167
+ - test/mollie/api/resource/customers/subscriptions_test.rb
168
+ - test/mollie/api/resource/customers_test.rb
169
+ - test/mollie/api/resource/issuers_test.rb
170
+ - test/mollie/api/resource/methods_test.rb
171
+ - test/mollie/api/resource/payments/refunds_test.rb
172
+ - test/mollie/api/resource/payments_test.rb
173
+ - test/run-test.rb
@@ -1,130 +0,0 @@
1
- require "json"
2
- require "rest_client"
3
-
4
- ["Exception",
5
- "Client/Version",
6
- "Resource/Base",
7
- "Resource/Customers",
8
- "Resource/Customers/Payments",
9
- "Resource/Customers/Mandates",
10
- "Resource/Customers/Subscriptions",
11
- "Resource/Payments",
12
- "Resource/Payments/Refunds",
13
- "Resource/Issuers",
14
- "Resource/Methods",
15
- "Object/Base",
16
- "Object/List",
17
- "Object/Customer",
18
- "Object/Mandate",
19
- "Object/Subscription",
20
- "Object/Payment",
21
- "Object/Payment/Refund",
22
- "Object/Issuer",
23
- "Object/Method"].each {|file| require File.expand_path file, File.dirname(__FILE__) }
24
-
25
- module Mollie
26
- module API
27
- class Client
28
- API_ENDPOINT = "https://api.mollie.nl"
29
- API_VERSION = "v1"
30
-
31
- attr_reader :payments, :issuers, :methods, :payments_refunds, :customers, :customers_payments, :customers_mandates, :customers_subscriptions
32
-
33
- def initialize
34
- @payments = Mollie::API::Resource::Payments.new self
35
- @issuers = Mollie::API::Resource::Issuers.new self
36
- @methods = Mollie::API::Resource::Methods.new self
37
- @payments_refunds = Mollie::API::Resource::Payments::Refunds.new self
38
- @customers = Mollie::API::Resource::Customers.new self
39
- @customers_payments = Mollie::API::Resource::Customers::Payments.new self
40
- @customers_mandates = Mollie::API::Resource::Customers::Mandates.new self
41
- @customers_subscriptions = Mollie::API::Resource::Customers::Subscriptions.new self
42
-
43
- @api_endpoint = API_ENDPOINT
44
- @api_key = ""
45
- @version_strings = []
46
-
47
- addVersionString "Mollie/" << CLIENT_VERSION
48
- addVersionString "Ruby/" << RUBY_VERSION
49
- addVersionString OpenSSL::OPENSSL_VERSION.split(" ").slice(0, 2).join "/"
50
- end
51
-
52
- def setApiEndpoint(api_endpoint)
53
- @api_endpoint = api_endpoint.chomp "/"
54
- end
55
-
56
- alias_method :api_endpoint=, :setApiEndpoint
57
-
58
- def getApiEndpoint
59
- @api_endpoint
60
- end
61
-
62
- alias_method :api_endpoint, :getApiEndpoint
63
-
64
- def setApiKey(api_key)
65
- @api_key = api_key
66
- end
67
-
68
- alias_method :api_key=, :setApiKey
69
-
70
- def addVersionString(version_string)
71
- @version_strings << (version_string.gsub /\s+/, "-")
72
- end
73
-
74
- def _getRestClient(request_url, request_headers)
75
- RestClient::Resource.new request_url,
76
- :headers => request_headers,
77
- :ssl_ca_file => (File.expand_path "cacert.pem", File.dirname(__FILE__)),
78
- :verify_ssl => OpenSSL::SSL::VERIFY_PEER
79
- end
80
-
81
- def performHttpCall(http_method, api_method, id = nil, http_body = nil)
82
- request_headers = {
83
- :accept => :json,
84
- :authorization => "Bearer #{@api_key}",
85
- :user_agent => @version_strings.join(" "),
86
- "X-Mollie-Client-Info" => getUname
87
- }
88
-
89
- if http_body.respond_to? :delete_if
90
- http_body.delete_if { |k, v| v.nil? }
91
- end
92
-
93
- http_code = nil
94
- begin
95
- request_url = "#{@api_endpoint}/#{API_VERSION}/#{api_method}/#{id}".chomp "/"
96
- rest_client = _getRestClient request_url, request_headers
97
-
98
- case http_method
99
- when "GET"
100
- response = rest_client.get
101
- when "POST"
102
- response = rest_client.post http_body
103
- when "DELETE"
104
- response = rest_client.delete
105
- end
106
- response = JSON.parse response, :symbolize_names => true
107
- rescue RestClient::ExceptionWithResponse => e
108
- http_code = e.http_code
109
- response = JSON.parse e.response, :symbolize_names => true
110
- raise e if response[:error].nil?
111
- end
112
-
113
- unless response[:error].nil?
114
- exception = Mollie::API::Exception.new response[:error][:message]
115
- exception.code = http_code
116
- exception.field = response[:error][:field] unless response[:error][:field].nil?
117
- raise exception
118
- end
119
-
120
- response
121
- end
122
-
123
- def getUname
124
- `uname -a 2>/dev/null`.strip if RUBY_PLATFORM =~ /linux|darwin/i
125
- rescue Errno::ENOMEM
126
- "uname lookup failed"
127
- end
128
- end
129
- end
130
- end
@@ -1,18 +0,0 @@
1
- module Mollie
2
- module API
3
- module Object
4
- class Base
5
- def initialize(hash)
6
- hash.each { |key, value|
7
- if value.respond_to? :each
8
- value = Base.new value
9
- end
10
-
11
- instance_variable_set "@#{key}", value
12
- self.class.send :attr_accessor, key
13
- }
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,16 +0,0 @@
1
- module Mollie
2
- module API
3
- module Object
4
- class Customer < Base
5
- attr_accessor :resource,
6
- :id,
7
- :name,
8
- :email,
9
- :locale,
10
- :metadata,
11
- :recentlyUsedMethods,
12
- :createdDatetime
13
- end
14
- end
15
- end
16
- end
@@ -1,35 +0,0 @@
1
- module Mollie
2
- module API
3
- module Object
4
- class List < Base
5
- include Enumerable
6
-
7
- attr_accessor :totalCount,
8
- :offset,
9
- :count,
10
- :data
11
-
12
- def initialize(hash, classResourceObject)
13
- data = hash[:data] || []
14
- hash[:data] = nil
15
- super hash
16
-
17
- @data = []
18
- data.each { |hash|
19
- @data << (classResourceObject.new hash)
20
- }
21
- end
22
-
23
- def each(&block)
24
- @data.each { |object|
25
- if block_given?
26
- block.call object
27
- else
28
- yield object
29
- end
30
- }
31
- end
32
- end
33
- end
34
- end
35
- end