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,19 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class IssuerTest < Test::Unit::TestCase
5
+ def test_setting_attributes
6
+ attributes = {
7
+ id: 'ideal_ABNANL2A',
8
+ name: 'ABN AMRO',
9
+ method: 'ideal'
10
+ }
11
+
12
+ customer = Issuer.new(attributes)
13
+
14
+ assert_equal 'ideal_ABNANL2A', customer.id
15
+ assert_equal 'ABN AMRO', customer.name
16
+ assert_equal 'ideal', customer.method
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class ListTest < Test::Unit::TestCase
5
+ def test_setting_attributes
6
+ attributes = {
7
+ 'total_count' => 280,
8
+ 'offset' => 0,
9
+ 'count' => 10,
10
+ 'data' => [
11
+ { 'id' => "tr_1" },
12
+ { 'id' => "tr_2" },
13
+ ],
14
+ 'links' => {
15
+ 'first' => "https://api.mollie.nl/v1/payments?count=10&offset=0",
16
+ 'previous' => nil,
17
+ 'next' => "https://api.mollie.nl/v1/payments?count=10&offset=10",
18
+ 'last' => "https://api.mollie.nl/v1/payments?count=10&offset=270"
19
+ }
20
+ }
21
+
22
+ list = Mollie::List.new(attributes, Payment)
23
+
24
+ assert_equal 280, list.total_count
25
+ assert_equal 0, list.offset
26
+ assert_equal 10, list.count
27
+
28
+ assert_kind_of Payment, list.to_a[0]
29
+ assert_equal "tr_1", list.to_a[0].id
30
+
31
+ assert_kind_of Payment, list.to_a[1]
32
+ assert_equal "tr_2", list.to_a[1].id
33
+
34
+ assert_equal "https://api.mollie.nl/v1/payments?count=10&offset=0", list.first_url
35
+ assert_equal nil, list.previous_url
36
+ assert_equal "https://api.mollie.nl/v1/payments?count=10&offset=10", list.next_url
37
+ assert_equal "https://api.mollie.nl/v1/payments?count=10&offset=270", list.last_url
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,29 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class MethodTest < Test::Unit::TestCase
5
+ def test_setting_attributes
6
+ attributes = {
7
+ id: "creditcard",
8
+ description: "Credit card",
9
+ amount: {
10
+ 'minimum' => "0.31",
11
+ 'maximum' => "10000.00"
12
+ },
13
+ image: {
14
+ 'normal' => "https://www.mollie.com/images/payscreen/methods/creditcard.png",
15
+ 'bigger' => "https://www.mollie.com/images/payscreen/methods/creditcard@2x.png"
16
+ }
17
+ }
18
+
19
+ method = Method.new(attributes)
20
+
21
+ assert_equal "creditcard", method.id
22
+ assert_equal "Credit card", method.description
23
+ assert_equal BigDecimal.new("0.31"), method.minimum_amount
24
+ assert_equal BigDecimal.new("10000.0"), method.maximum_amount
25
+ assert_equal "https://www.mollie.com/images/payscreen/methods/creditcard.png", method.normal_image
26
+ assert_equal "https://www.mollie.com/images/payscreen/methods/creditcard@2x.png", method.bigger_image
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,41 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class OrganizationTest < Test::Unit::TestCase
5
+ def test_setting_attributes
6
+ attributes = {
7
+ id: 'org_1234567',
8
+ name: 'Mollie B.V.',
9
+ email: 'info@mollie.com',
10
+ address: 'Keizersgracht 313',
11
+ postal_code: '1016EE',
12
+ city: 'Amsterdam',
13
+ country: 'Netherlands',
14
+ country_code: 'NL',
15
+ registration_type: 'bv',
16
+ registration_number: '30204462',
17
+ registration_datetime: '2004-04-01T09:41:00.0Z',
18
+ verified_datetime: '2007-06-29T09:41:00.0Z'
19
+ }
20
+
21
+ organization = Organization.new(attributes)
22
+
23
+ assert_equal 'org_1234567', organization.id
24
+ assert_equal 'Mollie B.V.', organization.name
25
+ assert_equal 'info@mollie.com', organization.email
26
+ assert_equal 'Keizersgracht 313', organization.address
27
+ assert_equal '1016EE', organization.postal_code
28
+ assert_equal 'Amsterdam', organization.city
29
+ assert_equal 'Netherlands', organization.country
30
+ assert_equal 'NL', organization.country_code
31
+ assert_equal 'bv', organization.registration_type
32
+ assert_equal '30204462', organization.registration_number
33
+ assert_equal Time.parse('2004-04-01T09:41:00.0Z'), organization.registration_datetime
34
+ assert_equal Time.parse('2007-06-29T09:41:00.0Z'), organization.verified_datetime
35
+ end
36
+
37
+ def test_verified_datetime_optional
38
+ assert_equal nil, Organization.new(verified_datetime: nil).verified_datetime
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class Payment
5
+ class ChargebackTest < Test::Unit::TestCase
6
+ def test_kind_of_refund
7
+ chargeback = Mollie::Payment::Chargeback.new({})
8
+ assert_kind_of Mollie::Chargeback, chargeback
9
+ end
10
+
11
+ def test_list_chargebacks
12
+ stub_request(:get, "https://api.mollie.nl/v1/payments/pay-id/chargebacks?count=50&offset=0")
13
+ .to_return(:status => 200, :body => %{{"data" : [{"id":"re-id", "payment": {"id":"pay-id"}}]}}, :headers => {})
14
+
15
+ chargebacks = Mollie::Payment::Chargeback.all(payment_id: "pay-id")
16
+
17
+ assert_equal "re-id", chargebacks.first.id
18
+ assert_equal "pay-id", chargebacks.first.payment.id
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class Payment
5
+ class RefundTest < Test::Unit::TestCase
6
+ def test_kind_of_refund
7
+ refund = Mollie::Payment::Refund.new({})
8
+ assert_kind_of Mollie::Refund, refund
9
+ end
10
+
11
+ def test_list_refunds
12
+ stub_request(:get, "https://api.mollie.nl/v1/payments/pay-id/refunds?count=50&offset=0")
13
+ .to_return(:status => 200, :body => %{{"data" : [{"id":"re-id", "payment": {"id":"pay-id"}}]}}, :headers => {})
14
+
15
+ refunds = Mollie::Payment::Refund.all(payment_id: "pay-id")
16
+
17
+ assert_equal "re-id", refunds.first.id
18
+ assert_equal "pay-id", refunds.first.payment.id
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,161 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class PaymentTest < Test::Unit::TestCase
5
+ def test_setting_attributes
6
+ attributes = {
7
+ id: 'tr_WDqYK6vllg',
8
+ mode: 'test',
9
+ created_datetime: '2016-10-08T10:10:52.0Z',
10
+ status: 'paid',
11
+ paid_datetime: '2016-10-08T10:15:35.0Z',
12
+ amount: 35.07,
13
+ description: 'Order 33',
14
+ method: 'ideal',
15
+ country_code: 'NL',
16
+ metadata: {
17
+ order_id: '33'
18
+ },
19
+ details: {
20
+ consumer_name: "Hr E G H K\u00fcppers en\/of MW M.J. K\u00fcppers-Veeneman",
21
+ consumer_account: 'NL53INGB0618365937',
22
+ consumer_bic: 'INGBNL2A'
23
+ },
24
+ locale: 'nl',
25
+ profile_id: 'pfl_QkEhN94Ba',
26
+ links: {
27
+ 'webhook_url' => 'https://webshop.example.org/payments/webhook',
28
+ 'redirect_url' => 'https://webshop.example.org/order/33/',
29
+ 'payment_url' => 'https://webshop.example.org/payment/tr_WDqYK6vllg',
30
+ 'settlement' => 'https://webshop.example.org/payment/tr_WDqYK6vllg/settlement',
31
+ 'refunds' => 'https://webshop.example.org/payment/tr_WDqYK6vllg/refunds',
32
+ }
33
+ }
34
+
35
+ payment = Payment.new(attributes)
36
+
37
+ assert_equal 'tr_WDqYK6vllg', payment.id
38
+ assert_equal 'test', payment.mode
39
+ assert_equal Time.parse('2016-10-08T10:10:52.0Z'), payment.created_datetime
40
+ assert_equal 'paid', payment.status
41
+ assert_equal Time.parse('2016-10-08T10:15:35.0Z'), payment.paid_datetime
42
+ assert_equal 35.07, payment.amount
43
+ assert_equal 'Order 33', payment.description
44
+ assert_equal 'ideal', payment.method
45
+ assert_equal '33', payment.metadata.order_id
46
+ assert_equal "Hr E G H K\u00fcppers en\/of MW M.J. K\u00fcppers-Veeneman", payment.details.consumer_name
47
+ assert_equal 'NL53INGB0618365937', payment.details.consumer_account
48
+ assert_equal 'INGBNL2A', payment.details.consumer_bic
49
+ assert_equal 'nl', payment.locale
50
+ assert_equal 'NL', payment.country_code
51
+ assert_equal 'pfl_QkEhN94Ba', payment.profile_id
52
+ assert_equal 'https://webshop.example.org/payments/webhook', payment.webhook_url
53
+ assert_equal 'https://webshop.example.org/order/33/', payment.redirect_url
54
+ assert_equal 'https://webshop.example.org/payment/tr_WDqYK6vllg', payment.payment_url
55
+ assert_equal 'https://webshop.example.org/payment/tr_WDqYK6vllg/settlement', payment.settlement
56
+ assert_equal 'https://webshop.example.org/payment/tr_WDqYK6vllg/refunds', payment.refunds_url
57
+ end
58
+
59
+ def test_status_open
60
+ assert Payment.new(status: Payment::STATUS_OPEN).open?
61
+ assert !Payment.new(status: 'not-open').open?
62
+ end
63
+
64
+ def test_status_cancelled
65
+ assert Payment.new(status: Payment::STATUS_CANCELLED).cancelled?
66
+ assert !Payment.new(status: 'not-cancelled').cancelled?
67
+ end
68
+
69
+ def test_status_expired
70
+ assert Payment.new(status: Payment::STATUS_EXPIRED).expired?
71
+ assert !Payment.new(status: 'not-expired').expired?
72
+ end
73
+
74
+ def test_status_paidout
75
+ assert Payment.new(status: Payment::STATUS_PAIDOUT).paidout?
76
+ assert !Payment.new(status: 'not-paidout').paidout?
77
+ end
78
+
79
+ def test_status_refunded
80
+ assert Payment.new(status: Payment::STATUS_REFUNDED).refunded?
81
+ assert !Payment.new(status: 'not-refunded').refunded?
82
+ end
83
+
84
+ def test_status_paid
85
+ assert Payment.new(paid_datetime: Time.now).paid?
86
+ assert !Payment.new(paid_datetime: nil).paid?
87
+ end
88
+
89
+ def test_status_failed
90
+ assert Payment.new(status: Payment::STATUS_FAILED).failed?
91
+ assert !Payment.new(status: 'not-failed').failed?
92
+ end
93
+
94
+ def test_status_pending
95
+ assert Payment.new(status: Payment::STATUS_PENDING).pending?
96
+ assert !Payment.new(status: 'not-pending').pending?
97
+ end
98
+
99
+ def test_status_charged_back
100
+ assert Payment.new(status: Payment::STATUS_CHARGED_BACK).charged_back?
101
+ assert !Payment.new(status: 'not-charged-back').charged_back?
102
+ end
103
+
104
+ def test_list_refunds
105
+ stub_request(:get, "https://api.mollie.nl/v1/payments/pay-id/refunds?count=50&offset=0")
106
+ .to_return(:status => 200, :body => %{{"data" : [{"id":"ref-id", "payment_id":"pay-id"}]}}, :headers => {})
107
+
108
+ refunds = Payment.new(id: "pay-id").refunds.all
109
+
110
+ assert_equal "ref-id", refunds.first.id
111
+ end
112
+
113
+ def test_create_refund
114
+ stub_request(:post, "https://api.mollie.nl/v1/payments/pay-id/refunds")
115
+ .with(body: %{{"amount":1.95}})
116
+ .to_return(:status => 201, :body => %{{"id":"my-id", "amount":1.95}}, :headers => {})
117
+
118
+ refund = Payment.new(id: "pay-id").refunds.create(amount: 1.95)
119
+
120
+ assert_equal "my-id", refund.id
121
+ assert_equal BigDecimal.new("1.95"), refund.amount
122
+ end
123
+
124
+ def test_delete_refund
125
+ stub_request(:delete, "https://api.mollie.nl/v1/payments/pay-id/refunds/ref-id")
126
+ .to_return(:status => 204, :headers => {})
127
+
128
+ refund = Payment.new(id: "pay-id").refunds.delete("ref-id")
129
+ assert_equal nil, refund
130
+ end
131
+
132
+ def test_get_refund
133
+ stub_request(:get, "https://api.mollie.nl/v1/payments/pay-id/refunds/ref-id")
134
+ .to_return(:status => 200, :body => %{{"id":"ref-id", "payment":{"id":"pay-id"}}}, :headers => {})
135
+
136
+ refund = Payment.new(id: "pay-id").refunds.get("ref-id")
137
+
138
+ assert_equal "ref-id", refund.id
139
+ assert_equal "pay-id", refund.payment.id
140
+ end
141
+
142
+ def test_list_chargebacks
143
+ stub_request(:get, "https://api.mollie.nl/v1/payments/pay-id/chargebacks?count=50&offset=0")
144
+ .to_return(:status => 200, :body => %{{"data" : [{"id":"chb-id", "payment_id":"pay-id"}]}}, :headers => {})
145
+
146
+ chargebacks = Payment.new(id: "pay-id").chargebacks.all
147
+
148
+ assert_equal "chb-id", chargebacks.first.id
149
+ end
150
+
151
+ def test_get_chargeback
152
+ stub_request(:get, "https://api.mollie.nl/v1/payments/pay-id/chargebacks/chb-id")
153
+ .to_return(:status => 200, :body => %{{"id":"chb-id", "payment":{"id":"pay-id"}}}, :headers => {})
154
+
155
+ chargeback = Payment.new(id: "pay-id").chargebacks.get("chb-id")
156
+
157
+ assert_equal "chb-id", chargeback.id
158
+ assert_equal "pay-id", chargeback.payment.id
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,21 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class PermissionTest < Test::Unit::TestCase
5
+ def test_setting_attributes
6
+ attributes = {
7
+ id: 'payments.read',
8
+ description: 'View your payments',
9
+ warning: nil,
10
+ granted: true
11
+ }
12
+
13
+ permission = Permission.new(attributes)
14
+
15
+ assert_equal 'payments.read', permission.id
16
+ assert_equal 'View your payments', permission.description
17
+ assert_equal nil, permission.warning
18
+ assert_equal true, permission.granted
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class Profile
5
+ class ApiKeyTest < Test::Unit::TestCase
6
+ def test_setting_attributes
7
+ attributes = {
8
+ id: "live",
9
+ key: "live_eSf9fQRwpsdfPY8y3tUFFmqjADRKyA",
10
+ created_datetime: "2017-04-20T12:19:48.0Z"
11
+ }
12
+
13
+ api_key = ApiKey.new(attributes)
14
+
15
+ assert_equal Mollie::Client::MODE_LIVE, api_key.id
16
+ assert_equal "live_eSf9fQRwpsdfPY8y3tUFFmqjADRKyA", api_key.key
17
+ assert_equal Time.parse("2017-04-20T12:19:48.0Z"), api_key.created_datetime
18
+ end
19
+
20
+ def test_testmode
21
+ assert ApiKey.new(id: Mollie::Client::MODE_TEST).testmode?
22
+ assert !ApiKey.new(id: 'not-test').testmode?
23
+ end
24
+
25
+ def test_livemode
26
+ assert ApiKey.new(id: Mollie::Client::MODE_LIVE).livemode?
27
+ assert !ApiKey.new(id: 'not-live').livemode?
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,98 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ class ProfileTest < Test::Unit::TestCase
5
+ def test_setting_attributes
6
+ attributes = {
7
+ id: 'pfl_v9hTwCvYqw',
8
+ mode: 'live',
9
+ name: 'My website name',
10
+ website: 'https://www.mywebsite.com',
11
+ email: 'info@mywebsite.com',
12
+ phone: '31123456789',
13
+ category_code: 5399,
14
+ status: 'unverified',
15
+ review: {
16
+ status: 'pending'
17
+ },
18
+ created_datetime: '2017-04-20T09:03:58.0Z',
19
+ updated_datetime: '2017-04-20T09:03:58.0Z',
20
+ links: {
21
+ 'apikeys' => 'https://api.mollie.nl/v1/profiles/pfl_v9hTwCvYqw/apikeys',
22
+ 'checkout_preview_url' => 'https://www.mollie.com/beheer/account_profielen/preview-payscreen/1337',
23
+ }
24
+ }
25
+
26
+ profile = Profile.new(attributes)
27
+
28
+ assert_equal 'pfl_v9hTwCvYqw', profile.id
29
+ assert_equal 'live', profile.mode
30
+ assert_equal 'My website name', profile.name
31
+ assert_equal 'https://www.mywebsite.com', profile.website
32
+ assert_equal 'info@mywebsite.com', profile.email
33
+ assert_equal '31123456789', profile.phone
34
+ assert_equal 5399, profile.category_code
35
+ assert_equal Profile::STATUS_UNVERIFIED, profile.status
36
+ assert_equal Profile::REVIEW_STATUS_PENDING, profile.review.status
37
+ assert_equal Time.parse('2017-04-20T09:03:58.0Z'), profile.created_datetime
38
+ assert_equal Time.parse('2017-04-20T09:03:58.0Z'), profile.updated_datetime
39
+ assert_equal 'https://api.mollie.nl/v1/profiles/pfl_v9hTwCvYqw/apikeys', profile.apikeys_url
40
+ assert_equal 'https://www.mollie.com/beheer/account_profielen/preview-payscreen/1337', profile.checkout_preview_url
41
+ end
42
+
43
+ def test_status_unverified
44
+ assert Profile.new(status: Profile::STATUS_UNVERIFIED).unverified?
45
+ assert !Profile.new(status: 'not-unverified').unverified?
46
+ end
47
+
48
+ def test_status_verified
49
+ assert Profile.new(status: Profile::STATUS_VERIFIED).verified?
50
+ assert !Profile.new(status: 'not-verified').verified?
51
+ end
52
+
53
+ def test_status_blocked
54
+ assert Profile.new(status: Profile::STATUS_BLOCKED).blocked?
55
+ assert !Profile.new(status: 'not-blocked').blocked?
56
+ end
57
+
58
+ def test_review_status_pending
59
+ assert Profile.new(review: { status: Profile::REVIEW_STATUS_PENDING }).review_pending?
60
+ assert !Profile.new(review: { status: 'not-pending' }).review_pending?
61
+ end
62
+
63
+ def test_review_status_rejected
64
+ assert Profile.new(review: { status: Profile::REVIEW_STATUS_REJECTED }).review_rejected?
65
+ assert !Profile.new(review: { status: 'not-rejected' }).review_rejected?
66
+ end
67
+
68
+ def test_list_apikeys
69
+ stub_request(:get, "https://api.mollie.nl/v1/profiles/pfl-id/apikeys?count=50&offset=0")
70
+ .to_return(:status => 200, :body => %{{"data" : [{"id":"live", "key":"key"}]}}, :headers => {})
71
+
72
+ apikeys = Profile.new(id: "pfl-id").apikeys.all
73
+
74
+ assert_equal "live", apikeys.first.id
75
+ assert_equal "key", apikeys.first.key
76
+ end
77
+
78
+ def test_update_apikey
79
+ stub_request(:post, "https://api.mollie.nl/v1/profiles/pfl-id/apikeys/live")
80
+ .to_return(:status => 200, :body => %{{"id":"live", "key":"key"}}, :headers => {})
81
+
82
+ apikey = Profile.new(id: "pfl-id").apikeys.update("live")
83
+
84
+ assert_equal "live", apikey.id
85
+ assert_equal "key", apikey.key
86
+ end
87
+
88
+ def test_get_apikey
89
+ stub_request(:get, "https://api.mollie.nl/v1/profiles/pfl-id/apikeys/live")
90
+ .to_return(:status => 200, :body => %{{"id":"live", "key":"key"}}, :headers => {})
91
+
92
+ apikey = Profile.new(id: "pfl-id").apikeys.get("live")
93
+
94
+ assert_equal "live", apikey.id
95
+ assert_equal "key", apikey.key
96
+ end
97
+ end
98
+ end