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.
Files changed (197) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +7 -0
  3. data/README.md +37 -8
  4. data/examples/apis/api_docs.rb +1 -1
  5. data/examples/apis/chargebacks.rb +17 -0
  6. data/examples/apis/connect.rb +1 -1
  7. data/examples/apis/customers.rb +7 -6
  8. data/examples/apis/invoices.rb +2 -2
  9. data/examples/apis/issuers.rb +2 -2
  10. data/examples/apis/mandates.rb +5 -5
  11. data/examples/apis/methods.rb +2 -2
  12. data/examples/apis/organizations.rb +1 -1
  13. data/examples/apis/payments.rb +43 -9
  14. data/examples/apis/permissions.rb +2 -2
  15. data/examples/apis/profiles.rb +7 -7
  16. data/examples/apis/refunds.rb +1 -1
  17. data/examples/apis/settlements.rb +5 -5
  18. data/examples/apis/subscriptions.rb +7 -7
  19. data/examples/config.ru +6 -7
  20. data/lib/{mollie/api/cacert.pem → cacert.pem} +0 -0
  21. data/lib/mollie-api-ruby.rb +1 -0
  22. data/lib/mollie.rb +39 -0
  23. data/lib/mollie/base.rb +91 -0
  24. data/lib/mollie/chargeback.rb +36 -0
  25. data/lib/mollie/client.rb +125 -0
  26. data/lib/mollie/customer.rb +36 -0
  27. data/lib/mollie/customer/mandate.rb +33 -0
  28. data/lib/mollie/customer/payment.rb +6 -0
  29. data/lib/mollie/customer/subscription.rb +65 -0
  30. data/lib/mollie/exception.rb +8 -0
  31. data/lib/mollie/invoice.rb +66 -0
  32. data/lib/mollie/issuer.rb +5 -0
  33. data/lib/mollie/list.rb +40 -0
  34. data/lib/mollie/method.rb +38 -0
  35. data/lib/mollie/organization.rb +24 -0
  36. data/lib/mollie/payment.rb +142 -0
  37. data/lib/mollie/payment/chargeback.rb +6 -0
  38. data/lib/mollie/payment/refund.rb +6 -0
  39. data/lib/mollie/permission.rb +26 -0
  40. data/lib/mollie/profile.rb +78 -0
  41. data/lib/mollie/profile/api_key.rb +19 -0
  42. data/lib/mollie/refund.rb +42 -0
  43. data/lib/mollie/relation.rb +36 -0
  44. data/lib/mollie/settlement.rb +36 -0
  45. data/lib/mollie/settlement/chargeback.rb +6 -0
  46. data/lib/mollie/settlement/payment.rb +6 -0
  47. data/lib/mollie/settlement/refund.rb +6 -0
  48. data/lib/mollie/util.rb +57 -0
  49. data/lib/mollie/version.rb +3 -0
  50. data/mollie.gemspec +2 -2
  51. data/test/helper.rb +5 -1
  52. data/test/mollie/base_test.rb +182 -0
  53. data/test/mollie/chargeback_test.rb +35 -0
  54. data/test/mollie/client_test.rb +122 -0
  55. data/test/mollie/customer/mandate_test.rb +43 -0
  56. data/test/mollie/customer/payment_test.rb +23 -0
  57. data/test/mollie/customer/subscription_test.rb +66 -0
  58. data/test/mollie/customer_test.rb +128 -0
  59. data/test/mollie/invoice_test.rb +55 -0
  60. data/test/mollie/issuer_test.rb +19 -0
  61. data/test/mollie/list_test.rb +40 -0
  62. data/test/mollie/method_test.rb +29 -0
  63. data/test/mollie/organization_test.rb +41 -0
  64. data/test/mollie/payment/chargeback_test.rb +22 -0
  65. data/test/mollie/payment/refund_test.rb +22 -0
  66. data/test/mollie/payment_test.rb +161 -0
  67. data/test/mollie/permission_test.rb +21 -0
  68. data/test/mollie/profile/apikey_test.rb +31 -0
  69. data/test/mollie/profile_test.rb +98 -0
  70. data/test/mollie/refund_test.rb +40 -0
  71. data/test/mollie/settlement/chargeback_test.rb +22 -0
  72. data/test/mollie/settlement/payment_test.rb +22 -0
  73. data/test/mollie/settlement/refund_test.rb +22 -0
  74. data/test/mollie/settlement_test.rb +156 -0
  75. data/website-docs/chargebacks/list-all.rb +12 -0
  76. data/website-docs/connect/authorize.rb +15 -0
  77. data/website-docs/connect/tokens.rb +14 -0
  78. data/website-docs/customers/create-payment.rb +13 -0
  79. data/website-docs/customers/create.rb +12 -0
  80. data/website-docs/customers/delete.rb +10 -0
  81. data/website-docs/customers/get.rb +10 -0
  82. data/website-docs/customers/list-payments.rb +10 -0
  83. data/website-docs/customers/list.rb +12 -0
  84. data/website-docs/customers/update.rb +11 -0
  85. data/website-docs/invoices/get.rb +10 -0
  86. data/website-docs/invoices/list.rb +12 -0
  87. data/website-docs/issuers/get.rb +10 -0
  88. data/website-docs/issuers/list.rb +12 -0
  89. data/website-docs/mandates/create.rb +16 -0
  90. data/website-docs/mandates/delete.rb +10 -0
  91. data/website-docs/mandates/get.rb +10 -0
  92. data/website-docs/mandates/list.rb +12 -0
  93. data/website-docs/methods/get.rb +10 -0
  94. data/website-docs/methods/list.rb +12 -0
  95. data/website-docs/organisations/get.rb +10 -0
  96. data/website-docs/payments/create-refund.rb +14 -0
  97. data/website-docs/payments/create.rb +16 -0
  98. data/website-docs/payments/delete-refund.rb +13 -0
  99. data/website-docs/payments/delete.rb +12 -0
  100. data/website-docs/payments/get-chargeback.rb +11 -0
  101. data/website-docs/payments/get-refund.rb +11 -0
  102. data/website-docs/payments/get.rb +10 -0
  103. data/website-docs/payments/list-chargeback.rb +13 -0
  104. data/website-docs/payments/list-refunds.rb +13 -0
  105. data/website-docs/payments/list.rb +12 -0
  106. data/website-docs/payments/payment-webhook.rb +21 -0
  107. data/website-docs/permissions/get.rb +10 -0
  108. data/website-docs/permissions/list.rb +12 -0
  109. data/website-docs/profiles/create.rb +15 -0
  110. data/website-docs/profiles/delete.rb +10 -0
  111. data/website-docs/profiles/get-key.rb +11 -0
  112. data/website-docs/profiles/get.rb +10 -0
  113. data/website-docs/profiles/list-keys.rb +13 -0
  114. data/website-docs/profiles/list.rb +12 -0
  115. data/website-docs/profiles/reset-key.rb +13 -0
  116. data/website-docs/profiles/update.rb +12 -0
  117. data/website-docs/refunds/list.rb +12 -0
  118. data/website-docs/settlements/get.rb +10 -0
  119. data/website-docs/settlements/list-chargebacks.rb +13 -0
  120. data/website-docs/settlements/list-payments.rb +13 -0
  121. data/website-docs/settlements/list-refunds.rb +13 -0
  122. data/website-docs/settlements/list.rb +12 -0
  123. data/website-docs/settlements/next.rb +9 -0
  124. data/website-docs/settlements/open.rb +9 -0
  125. data/website-docs/subscriptions/create.rb +14 -0
  126. data/website-docs/subscriptions/delete.rb +10 -0
  127. data/website-docs/subscriptions/get.rb +10 -0
  128. data/website-docs/subscriptions/list.rb +12 -0
  129. metadata +134 -104
  130. data/lib/mollie/api/client.rb +0 -161
  131. data/lib/mollie/api/client/version.rb +0 -7
  132. data/lib/mollie/api/exception.rb +0 -10
  133. data/lib/mollie/api/object/base.rb +0 -18
  134. data/lib/mollie/api/object/customer.rb +0 -28
  135. data/lib/mollie/api/object/customer/mandate.rb +0 -37
  136. data/lib/mollie/api/object/customer/subscription.rb +0 -69
  137. data/lib/mollie/api/object/invoice.rb +0 -70
  138. data/lib/mollie/api/object/issuer.rb +0 -9
  139. data/lib/mollie/api/object/list.rb +0 -44
  140. data/lib/mollie/api/object/method.rb +0 -42
  141. data/lib/mollie/api/object/organization.rb +0 -28
  142. data/lib/mollie/api/object/payment.rb +0 -137
  143. data/lib/mollie/api/object/payment/refund.rb +0 -47
  144. data/lib/mollie/api/object/permission.rb +0 -12
  145. data/lib/mollie/api/object/profile.rb +0 -78
  146. data/lib/mollie/api/object/profile/apikey.rb +0 -23
  147. data/lib/mollie/api/object/settlement.rb +0 -32
  148. data/lib/mollie/api/resource/base.rb +0 -53
  149. data/lib/mollie/api/resource/customers.rb +0 -11
  150. data/lib/mollie/api/resource/customers/mandates.rb +0 -27
  151. data/lib/mollie/api/resource/customers/payments.rb +0 -27
  152. data/lib/mollie/api/resource/customers/subscriptions.rb +0 -27
  153. data/lib/mollie/api/resource/invoices.rb +0 -11
  154. data/lib/mollie/api/resource/issuers.rb +0 -11
  155. data/lib/mollie/api/resource/methods.rb +0 -11
  156. data/lib/mollie/api/resource/organizations.rb +0 -11
  157. data/lib/mollie/api/resource/payments.rb +0 -11
  158. data/lib/mollie/api/resource/payments/refunds.rb +0 -27
  159. data/lib/mollie/api/resource/permissions.rb +0 -31
  160. data/lib/mollie/api/resource/profiles.rb +0 -11
  161. data/lib/mollie/api/resource/profiles/apikeys.rb +0 -33
  162. data/lib/mollie/api/resource/refunds.rb +0 -11
  163. data/lib/mollie/api/resource/settlements.rb +0 -19
  164. data/lib/mollie/api/resource/settlements/payments.rb +0 -27
  165. data/lib/mollie/api/util.rb +0 -53
  166. data/test/mollie/api/client_test.rb +0 -111
  167. data/test/mollie/api/object/base_test.rb +0 -21
  168. data/test/mollie/api/object/customer/mandate_test.rb +0 -47
  169. data/test/mollie/api/object/customer/subscription_test.rb +0 -70
  170. data/test/mollie/api/object/customer_test.rb +0 -35
  171. data/test/mollie/api/object/invoice_test.rb +0 -59
  172. data/test/mollie/api/object/issuer_test.rb +0 -23
  173. data/test/mollie/api/object/list_test.rb +0 -44
  174. data/test/mollie/api/object/method_test.rb +0 -33
  175. data/test/mollie/api/object/organization_test.rb +0 -45
  176. data/test/mollie/api/object/payment/refund_test.rb +0 -46
  177. data/test/mollie/api/object/payment_test.rb +0 -106
  178. data/test/mollie/api/object/permission_test.rb +0 -25
  179. data/test/mollie/api/object/profile/apikey_test.rb +0 -35
  180. data/test/mollie/api/object/profile_test.rb +0 -72
  181. data/test/mollie/api/object/settlement_test.rb +0 -140
  182. data/test/mollie/api/resource/base_test.rb +0 -83
  183. data/test/mollie/api/resource/customers/mandates_test.rb +0 -23
  184. data/test/mollie/api/resource/customers/payments_test.rb +0 -23
  185. data/test/mollie/api/resource/customers/subscriptions_test.rb +0 -23
  186. data/test/mollie/api/resource/customers_test.rb +0 -13
  187. data/test/mollie/api/resource/invoices_test.rb +0 -13
  188. data/test/mollie/api/resource/issuers_test.rb +0 -13
  189. data/test/mollie/api/resource/methods_test.rb +0 -13
  190. data/test/mollie/api/resource/organizations_test.rb +0 -13
  191. data/test/mollie/api/resource/payments/refunds_test.rb +0 -23
  192. data/test/mollie/api/resource/payments_test.rb +0 -13
  193. data/test/mollie/api/resource/permissions_test.rb +0 -13
  194. data/test/mollie/api/resource/profiles/apikeys_test.rb +0 -23
  195. data/test/mollie/api/resource/profiles_test.rb +0 -13
  196. data/test/mollie/api/resource/settlements_test.rb +0 -13
  197. data/test/mollie/api/util_test.rb +0 -47
@@ -0,0 +1,35 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class ChargebackTest < Test::Unit::TestCase
5
+ def test_setting_attributes
6
+ attributes = {
7
+ id: "re_4qqhO89gsT",
8
+ payment: {
9
+ id: "tr_WDqYK6vllg",
10
+ },
11
+ amount: "5.95",
12
+ chargeback_datetime: "2016-10-08T07:59:53.0Z",
13
+ reversed_datetime: "2016-10-08T07:59:53.0Z",
14
+ }
15
+
16
+ chargeback = Chargeback.new(attributes)
17
+
18
+ assert_equal "re_4qqhO89gsT", chargeback.id
19
+ assert_equal BigDecimal.new("5.95"), chargeback.amount
20
+ assert_kind_of Payment, chargeback.payment
21
+ assert_equal Time.parse("2016-10-08T07:59:53.0Z"), chargeback.chargeback_datetime
22
+ assert_equal Time.parse("2016-10-08T07:59:53.0Z"), chargeback.reversed_datetime
23
+ end
24
+
25
+ def test_payment
26
+ assert_equal "pay-id", Chargeback.new(payment: "pay-id").payment
27
+ assert_equal "pay-id", Chargeback.new(payment: {id: "pay-id"}).payment.id
28
+ end
29
+
30
+ def test_reversed?
31
+ assert Chargeback.new(reversed_datetime: "2016-10-08T07:59:53.0Z").reversed?
32
+ assert !Chargeback.new(reversed_datetime: nil).reversed?
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,122 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class ClientTest < Test::Unit::TestCase
5
+ def client
6
+ Mollie::Client.new("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM")
7
+ end
8
+
9
+ def test_initialize
10
+ assert_equal "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM", client.api_key
11
+ end
12
+
13
+ def test_setting_the_api_endpoint
14
+ client = self.client
15
+ client.api_endpoint = "http://my.endpoint/"
16
+ assert_equal "http://my.endpoint", client.api_endpoint
17
+ end
18
+
19
+ def test_perform_http_call_defaults
20
+ stub_request(:any, "https://api.mollie.nl/v1/my-method")
21
+ .with(:headers => { 'Accept' => 'application/json',
22
+ 'Content-type' => 'application/json',
23
+ 'Authorization' => 'Bearer test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM',
24
+ 'User-Agent' => /^Mollie\/#{Mollie::VERSION} Ruby\/#{RUBY_VERSION} OpenSSL\/.*$/ })
25
+ .to_return(:status => 200, :body => "{}", :headers => {})
26
+ client.perform_http_call("GET", "my-method", nil, {})
27
+ end
28
+
29
+ def test_perform_http_call_key_override
30
+ stub_request(:any, "https://localhost/v1/my-method")
31
+ .with(:headers => { 'Accept' => 'application/json',
32
+ 'Content-type' => 'application/json',
33
+ 'Authorization' => 'Bearer my_key',
34
+ 'User-Agent' => /^Mollie\/#{Mollie::VERSION} Ruby\/#{RUBY_VERSION} OpenSSL\/.*$/ })
35
+ .to_return(:status => 200, :body => "{}", :headers => {})
36
+ client.perform_http_call("GET", "my-method", nil, {api_key: 'my_key', api_endpoint: 'https://localhost'})
37
+ client.perform_http_call("GET", "my-method", nil, {}, {api_key: 'my_key', api_endpoint: 'https://localhost'})
38
+ end
39
+
40
+ def test_perform_http_call_with_api_key_block
41
+ stub_request(:any, "https://api.mollie.nl/v1/my-method")
42
+ .with(:headers => { 'Accept' => 'application/json',
43
+ 'Content-type' => 'application/json',
44
+ 'Authorization' => 'Bearer my_key',
45
+ 'User-Agent' => /^Mollie\/#{Mollie::VERSION} Ruby\/#{RUBY_VERSION} OpenSSL\/.*$/ })
46
+ .to_return(:status => 200, :body => "{}", :headers => {})
47
+
48
+ Mollie::Client.instance.api_key = "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"
49
+ Mollie::Client.with_api_key("my_key") do
50
+ assert_equal "my_key", Mollie::Client.instance.api_key
51
+ Mollie::Client.instance.perform_http_call("GET", "my-method", nil, {})
52
+ end
53
+ assert_equal "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM", Mollie::Client.instance.api_key
54
+ end
55
+
56
+ def test_get_request_convert_to_camel_case
57
+ stub_request(:get, "https://api.mollie.nl/v1/my-method?myParam=ok")
58
+ .to_return(:status => 200, :body => "{}", :headers => {})
59
+ client.perform_http_call("GET", "my-method", nil, {}, { my_param: "ok" })
60
+ end
61
+
62
+ def test_get_response_convert_to_snake_case
63
+ response_body = <<-JSON
64
+ {
65
+ "someCamelCased" : {
66
+ "alsoNested": "camelCaseValue"
67
+ },
68
+ "evenLists": [
69
+ {
70
+ "withCamelCase": "camelCaseValue"
71
+ }
72
+ ]
73
+ }
74
+ JSON
75
+
76
+ expected_response = {
77
+ 'some_camel_cased' =>
78
+ { 'also_nested' => "camelCaseValue" },
79
+ 'even_lists' => [
80
+ { 'with_camel_case' => "camelCaseValue" }
81
+ ]
82
+ }
83
+
84
+ stub_request(:get, "https://api.mollie.nl/v1/my-method")
85
+ .to_return(:status => 200, :body => response_body, :headers => {})
86
+ response = client.perform_http_call("GET", "my-method", nil, {})
87
+
88
+ assert_equal expected_response, response
89
+ end
90
+
91
+ def test_post_requests_convert_to_camel_case
92
+ expected_body = %{{"redirectUrl":"my-url"}}
93
+
94
+ stub_request(:post, "https://api.mollie.nl/v1/my-method")
95
+ .with(body: expected_body)
96
+ .to_return(:status => 200, :body => "{}", :headers => {})
97
+
98
+ client.perform_http_call("POST", "my-method", nil, redirect_url: "my-url")
99
+ end
100
+
101
+ def test_delete_requests_with_no_content_responses
102
+ stub_request(:delete, "https://api.mollie.nl/v1/my-method/1")
103
+ .to_return(:status => 204, :body => "", :headers => {})
104
+
105
+ client.perform_http_call("DELETE", "my-method", "1")
106
+ end
107
+
108
+ def test_error_response
109
+ response = <<-JSON
110
+ {"error": {"message": "Error on field", "field": "my-field"}}
111
+ JSON
112
+ stub_request(:post, "https://api.mollie.nl/v1/my-method")
113
+ .to_return(:status => 500, :body => response, :headers => {})
114
+
115
+ e = assert_raise Mollie::Exception.new("Error on field") do
116
+ client.perform_http_call("POST", "my-method", nil, {})
117
+ end
118
+
119
+ assert_equal "my-field", e.field
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,43 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class Customer
5
+ class MandateTest < Test::Unit::TestCase
6
+ def test_setting_attributes
7
+ attributes = {
8
+ id: "mdt_qtUgejVgMN",
9
+ status: "valid",
10
+ method: "creditcard",
11
+ customer_id: "cst_R6JLAuqEgm",
12
+ details: {
13
+ card_holder: "John Doe",
14
+ card_expiry_date: "2016-03-31"
15
+ },
16
+ created_datetime: "2016-04-13T11:32:38.0Z"
17
+ }
18
+
19
+ mandate = Mandate.new(attributes)
20
+
21
+ assert_equal 'mdt_qtUgejVgMN', mandate.id
22
+ assert_equal 'valid', mandate.status
23
+ assert_equal 'creditcard', mandate.method
24
+ assert_equal 'cst_R6JLAuqEgm', mandate.customer_id
25
+ assert_equal Time.parse('2016-04-13T11:32:38.0Z'), mandate.created_datetime
26
+
27
+ assert_equal 'John Doe', mandate.details.card_holder
28
+ assert_equal '2016-03-31', mandate.details.card_expiry_date
29
+ assert_equal nil, mandate.details.non_existing
30
+ end
31
+
32
+ def test_valid_invalid
33
+ mandate = Mandate.new(status: Mandate::STATUS_VALID)
34
+ assert mandate.valid?
35
+ assert !mandate.invalid?
36
+
37
+ mandate = Mandate.new(status: Mandate::STATUS_INVALID)
38
+ assert !mandate.valid?
39
+ assert mandate.invalid?
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,23 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class Customer
5
+ class PaymentTest < Test::Unit::TestCase
6
+ def test_kind_of_payment
7
+ payment = Mollie::Customer::Payment.new({})
8
+ assert_kind_of Mollie::Payment, payment
9
+ end
10
+
11
+
12
+ def test_list_payments
13
+ stub_request(:get, "https://api.mollie.nl/v1/customers/cus-id/payments?count=50&offset=0")
14
+ .to_return(:status => 200, :body => %{{"data" : [{"id":"pay-id", "customer_id":"cus-id"}]}}, :headers => {})
15
+
16
+ payments = Payment.all(customer_id: "cus-id")
17
+
18
+ assert_equal "pay-id", payments.first.id
19
+ assert_equal "cus-id", payments.first.customer_id
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,66 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class Customer
5
+ class SubscriptionTest < Test::Unit::TestCase
6
+ def test_setting_attributes
7
+ attributes = {
8
+ id: "sub_rVKGtNd6s3",
9
+ customer_id: "cst_stTC2WHAuS",
10
+ mode: "live",
11
+ created_datetime: "2016-06-01T12:23:34.0Z",
12
+ status: "active",
13
+ amount: "25.00",
14
+ times: 4,
15
+ interval: "3 months",
16
+ description: "Quarterly payment",
17
+ method: "creditcard",
18
+ cancelled_datetime: "2016-06-01T12:23:34.0Z",
19
+ links: {
20
+ 'webhook_url' => "https://example.org/payments/webhook"
21
+ }
22
+ }
23
+
24
+ subscription = Subscription.new(attributes)
25
+
26
+ assert_equal "sub_rVKGtNd6s3", subscription.id
27
+ assert_equal "cst_stTC2WHAuS", subscription.customer_id
28
+ assert_equal "live", subscription.mode
29
+ assert_equal Time.parse("2016-06-01T12:23:34.0Z"), subscription.created_datetime
30
+ assert_equal "active", subscription.status
31
+ assert_equal BigDecimal.new(25, 2), subscription.amount
32
+ assert_equal 4, subscription.times
33
+ assert_equal "3 months", subscription.interval
34
+ assert_equal "Quarterly payment", subscription.description
35
+ assert_equal "creditcard", subscription.method
36
+ assert_equal Time.parse("2016-06-01T12:23:34.0Z"), subscription.cancelled_datetime
37
+ assert_equal "https://example.org/payments/webhook", subscription.webhook_url
38
+ end
39
+
40
+ def test_status_active
41
+ assert Subscription.new(status: Subscription::STATUS_ACTIVE).active?
42
+ assert !Subscription.new(status: 'not-active').active?
43
+ end
44
+
45
+ def test_status_pending
46
+ assert Subscription.new(status: Subscription::STATUS_PENDING).pending?
47
+ assert !Subscription.new(status: 'not-pending').pending?
48
+ end
49
+
50
+ def test_status_suspended
51
+ assert Subscription.new(status: Subscription::STATUS_SUSPENDED).suspended?
52
+ assert !Subscription.new(status: 'not-suspended').suspended?
53
+ end
54
+
55
+ def test_status_cancelled
56
+ assert Subscription.new(status: Subscription::STATUS_CANCELLED).cancelled?
57
+ assert !Subscription.new(status: 'not-cancelled').cancelled?
58
+ end
59
+
60
+ def test_status_completed
61
+ assert Subscription.new(status: Subscription::STATUS_COMPLETED).completed?
62
+ assert !Subscription.new(status: 'not-completed').completed?
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,128 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class CustomerTest < Test::Unit::TestCase
5
+ def test_setting_attributes
6
+ attributes = {
7
+ id: 'cst_vsKJpSsabw',
8
+ mode: 'test',
9
+ name: 'Customer A',
10
+ email: 'customer@example.org',
11
+ locale: 'nl_NL',
12
+ metadata: { my_field: 'value' },
13
+ recently_used_methods: 'creditcard',
14
+ created_datetime: '2016-04-06T13:23:21.0Z'
15
+ }
16
+
17
+ customer = Customer.new(attributes)
18
+
19
+ assert_equal 'cst_vsKJpSsabw', customer.id
20
+ assert_equal 'test', customer.mode
21
+ assert_equal 'Customer A', customer.name
22
+ assert_equal 'customer@example.org', customer.email
23
+ assert_equal 'nl_NL', customer.locale
24
+ assert_equal ['creditcard'], customer.recently_used_methods
25
+ assert_equal Time.parse('2016-04-06T13:23:21.0Z'), customer.created_datetime
26
+
27
+ assert_equal 'value', customer.metadata.my_field
28
+ assert_equal nil, customer.metadata.non_existing
29
+ end
30
+
31
+ def test_list_mandates
32
+ stub_request(:get, "https://api.mollie.nl/v1/customers/cus-id/mandates?count=50&offset=0")
33
+ .to_return(:status => 200, :body => %{{"data" : [{"id":"man-id", "customer_id":"cus-id"}]}}, :headers => {})
34
+
35
+ mandates = Customer.new(id: "cus-id").mandates.all
36
+
37
+ assert_equal "man-id", mandates.first.id
38
+ end
39
+
40
+ def test_create_mandate
41
+ stub_request(:post, "https://api.mollie.nl/v1/customers/cus-id/mandates")
42
+ .with(body: %{{"method":"directdebit"}})
43
+ .to_return(:status => 201, :body => %{{"id":"my-id", "method":"directdebit"}}, :headers => {})
44
+
45
+ mandate = Customer.new(id: "cus-id").mandates.create(method: "directdebit")
46
+
47
+ assert_equal "my-id", mandate.id
48
+ assert_equal "directdebit", mandate.method
49
+ end
50
+
51
+ def test_delete_mandate
52
+ stub_request(:delete, "https://api.mollie.nl/v1/customers/cus-id/mandates/man-id")
53
+ .to_return(:status => 204, :headers => {})
54
+
55
+ mandate = Customer.new(id: "cus-id").mandates.delete("man-id")
56
+ assert_equal nil, mandate
57
+ end
58
+
59
+ def test_get_mandate
60
+ stub_request(:get, "https://api.mollie.nl/v1/customers/cus-id/mandates/man-id")
61
+ .to_return(:status => 200, :body => %{{"id":"man-id", "customer_id":"cus-id"}}, :headers => {})
62
+
63
+ mandate = Customer.new(id: "cus-id").mandates.get("man-id")
64
+
65
+ assert_equal "man-id", mandate.id
66
+ assert_equal "cus-id", mandate.customer_id
67
+ end
68
+
69
+ def test_list_subscriptions
70
+ stub_request(:get, "https://api.mollie.nl/v1/customers/cus-id/subscriptions?count=50&offset=0")
71
+ .to_return(:status => 200, :body => %{{"data" : [{"id":"sub-id", "customer_id":"cus-id"}]}}, :headers => {})
72
+
73
+ subscriptions = Customer.new(id: "cus-id").subscriptions.all
74
+
75
+ assert_equal "sub-id", subscriptions.first.id
76
+ end
77
+
78
+ def test_create_subscription
79
+ stub_request(:post, "https://api.mollie.nl/v1/customers/cus-id/subscriptions")
80
+ .with(body: %{{"amount":1.95}})
81
+ .to_return(:status => 201, :body => %{{"id":"my-id", "amount":1.95}}, :headers => {})
82
+
83
+ subscription = Customer.new(id: "cus-id").subscriptions.create(amount: 1.95)
84
+
85
+ assert_equal "my-id", subscription.id
86
+ assert_equal BigDecimal.new("1.95"), subscription.amount
87
+ end
88
+
89
+ def test_delete_subscription
90
+ stub_request(:delete, "https://api.mollie.nl/v1/customers/cus-id/subscriptions/sub-id")
91
+ .to_return(:status => 204, :headers => {})
92
+
93
+ subscription = Customer.new(id: "cus-id").subscriptions.delete("sub-id")
94
+ assert_equal nil, subscription
95
+ end
96
+
97
+ def test_get_subscription
98
+ stub_request(:get, "https://api.mollie.nl/v1/customers/cus-id/subscriptions/sub-id")
99
+ .to_return(:status => 200, :body => %{{"id":"sub-id", "customer_id":"cus-id"}}, :headers => {})
100
+
101
+ subscription = Customer.new(id: "cus-id").subscriptions.get("sub-id")
102
+
103
+ assert_equal "sub-id", subscription.id
104
+ assert_equal "cus-id", subscription.customer_id
105
+ end
106
+
107
+ def test_list_payments
108
+ stub_request(:get, "https://api.mollie.nl/v1/customers/cus-id/payments?count=50&offset=0")
109
+ .to_return(:status => 200, :body => %{{"data" : [{"id":"sub-id", "customer_id":"cus-id"}]}}, :headers => {})
110
+
111
+ payments = Customer.new(id: "cus-id").payments.all
112
+
113
+ assert_equal "sub-id", payments.first.id
114
+ end
115
+
116
+ def test_create_payment
117
+ stub_request(:post, "https://api.mollie.nl/v1/customers/cus-id/payments")
118
+ .with(body: %{{"amount":1.95}})
119
+ .to_return(:status => 201, :body => %{{"id":"my-id", "amount":1.95}}, :headers => {})
120
+
121
+ payment = Customer.new(id: "cus-id").payments.create(amount: 1.95)
122
+
123
+ assert_kind_of Mollie::Payment, payment
124
+ assert_equal "my-id", payment.id
125
+ assert_equal BigDecimal.new("1.95"), payment.amount
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,55 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class InvoiceTest < Test::Unit::TestCase
5
+ def test_setting_attributes
6
+ attributes = {
7
+ resource: "invoice",
8
+ id: "inv_xBEbP9rvAq",
9
+ reference: "2016.10000",
10
+ vat_number: "NL001234567B01",
11
+ status: "open",
12
+ issue_date: "2016-08-31",
13
+ due_date: "2016-09-14",
14
+ amount: {
15
+ net: "45.00",
16
+ vat: "9.45",
17
+ gross: "54.45"
18
+ },
19
+ lines: [{
20
+ period: "2016-09",
21
+ description: "iDEAL transactiekosten",
22
+ count: 100,
23
+ vat_percentage: 21,
24
+ amount: "45.00"
25
+ }],
26
+ links: {
27
+ 'pdf' => "https://www.mollie.com/beheer/facturen/2016.10000/52981a39788e5e0acaf71bbf570e941f/"
28
+ }
29
+ }
30
+
31
+ invoice = Invoice.new(attributes)
32
+
33
+ assert_equal "invoice", invoice.resource
34
+ assert_equal "inv_xBEbP9rvAq", invoice.id
35
+ assert_equal "2016.10000", invoice.reference
36
+ assert_equal "NL001234567B01", invoice.vat_number
37
+ assert_equal "open", invoice.status
38
+ assert_equal Time.parse("2016-08-31"), invoice.issue_date
39
+ assert_equal Time.parse("2016-09-14"), invoice.due_date
40
+ assert_equal 45.0, invoice.amount.net
41
+ assert_equal BigDecimal.new(9.45, 3), invoice.amount.vat
42
+ assert_equal 54.45, invoice.amount.gross
43
+
44
+ line = invoice.lines.first
45
+ assert_equal "2016-09", line.period
46
+ assert_equal "iDEAL transactiekosten", line.description
47
+ assert_equal 100, line.count
48
+ assert_equal 21, line.vat_percentage
49
+ assert_equal 45.0, line.amount
50
+
51
+
52
+ assert_equal "https://www.mollie.com/beheer/facturen/2016.10000/52981a39788e5e0acaf71bbf570e941f/", invoice.pdf
53
+ end
54
+ end
55
+ end