mollie-api-ruby 3.1.5 → 4.0.0.pre.alpha.1

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.
Files changed (220) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +0 -3
  3. data/CHANGELOG.md +6 -0
  4. data/README.md +63 -119
  5. data/bin/console +15 -0
  6. data/bin/setup +8 -0
  7. data/docs/migration_v2_2_x.md +67 -0
  8. data/docs/migration_v3_x.md +227 -0
  9. data/examples/chargebacks/get.rb +4 -0
  10. data/examples/chargebacks/list.rb +1 -0
  11. data/{website-docs → examples}/connect/authorize.rb +3 -2
  12. data/{website-docs → examples}/connect/tokens.rb +1 -1
  13. data/examples/customers/create-payment.rb +6 -0
  14. data/examples/customers/create.rb +5 -0
  15. data/examples/customers/delete.rb +1 -0
  16. data/examples/customers/get.rb +1 -0
  17. data/examples/customers/list-payments.rb +1 -0
  18. data/examples/customers/list.rb +1 -0
  19. data/examples/customers/update.rb +4 -0
  20. data/examples/invoices/get.rb +1 -0
  21. data/examples/invoices/list.rb +1 -0
  22. data/examples/mandates/create.rb +9 -0
  23. data/examples/mandates/delete.rb +1 -0
  24. data/examples/mandates/get.rb +1 -0
  25. data/examples/mandates/list.rb +1 -0
  26. data/examples/methods/get.rb +4 -0
  27. data/examples/methods/list.rb +4 -0
  28. data/examples/organisations/get-current.rb +1 -0
  29. data/examples/organisations/get.rb +1 -0
  30. data/examples/payments/create.rb +9 -0
  31. data/examples/payments/delete.rb +1 -0
  32. data/examples/payments/get-customer.rb +2 -0
  33. data/examples/payments/get-mandate.rb +2 -0
  34. data/examples/payments/get-settlement.rb +2 -0
  35. data/examples/payments/get-subscription.rb +2 -0
  36. data/examples/payments/get.rb +1 -0
  37. data/examples/payments/list.rb +1 -0
  38. data/examples/payments/webhook.rb +12 -0
  39. data/examples/permissions/get.rb +1 -0
  40. data/examples/permissions/list.rb +1 -0
  41. data/examples/profiles/create.rb +8 -0
  42. data/examples/profiles/delete.rb +1 -0
  43. data/examples/profiles/get.rb +1 -0
  44. data/examples/profiles/list-chargebacks.rb +2 -0
  45. data/examples/profiles/list-methods.rb +2 -0
  46. data/examples/profiles/list-payments.rb +2 -0
  47. data/examples/profiles/list-refunds.rb +2 -0
  48. data/examples/profiles/list.rb +1 -0
  49. data/examples/profiles/update.rb +5 -0
  50. data/examples/refunds/create.rb +5 -0
  51. data/examples/refunds/delete.rb +4 -0
  52. data/examples/refunds/get-payment.rb +2 -0
  53. data/examples/refunds/get.rb +4 -0
  54. data/examples/refunds/list.rb +1 -0
  55. data/examples/settlements/get.rb +1 -0
  56. data/examples/settlements/list-chargebacks.rb +1 -0
  57. data/examples/settlements/list-payments.rb +1 -0
  58. data/examples/settlements/list-refunds.rb +1 -0
  59. data/examples/settlements/list.rb +1 -0
  60. data/examples/settlements/next.rb +1 -0
  61. data/examples/settlements/open.rb +1 -0
  62. data/examples/subscriptions/create.rb +8 -0
  63. data/examples/subscriptions/delete.rb +4 -0
  64. data/examples/subscriptions/get.rb +4 -0
  65. data/examples/subscriptions/list.rb +1 -0
  66. data/examples/subscriptions/update.rb +5 -0
  67. data/lib/cacert.pem +168 -48
  68. data/lib/mollie.rb +1 -3
  69. data/lib/mollie/amount.rb +20 -0
  70. data/lib/mollie/base.rb +9 -8
  71. data/lib/mollie/chargeback.rb +25 -15
  72. data/lib/mollie/client.rb +33 -13
  73. data/lib/mollie/customer.rb +9 -14
  74. data/lib/mollie/customer/mandate.rb +17 -5
  75. data/lib/mollie/customer/subscription.rb +14 -15
  76. data/lib/mollie/exception.rb +15 -3
  77. data/lib/mollie/invoice.rb +30 -26
  78. data/lib/mollie/list.rb +27 -18
  79. data/lib/mollie/method.rb +17 -25
  80. data/lib/mollie/organization.rb +5 -11
  81. data/lib/mollie/payment.rb +89 -61
  82. data/lib/mollie/permission.rb +0 -1
  83. data/lib/mollie/profile.rb +18 -13
  84. data/lib/mollie/refund.rb +27 -7
  85. data/lib/mollie/settlement.rb +50 -9
  86. data/lib/mollie/util.rb +11 -0
  87. data/lib/mollie/version.rb +1 -1
  88. data/mollie-api-ruby.gemspec +0 -7
  89. data/test/mollie/amount_test.rb +30 -0
  90. data/test/mollie/base_test.rb +44 -44
  91. data/test/mollie/chargeback_test.rb +78 -17
  92. data/test/mollie/client_test.rb +29 -12
  93. data/test/mollie/customer/mandate_test.rb +85 -9
  94. data/test/mollie/customer/payment_test.rb +2 -2
  95. data/test/mollie/customer/subscription_test.rb +71 -20
  96. data/test/mollie/customer_test.rb +17 -89
  97. data/test/mollie/invoice_test.rb +40 -24
  98. data/test/mollie/list_test.rb +62 -18
  99. data/test/mollie/method_test.rb +2 -8
  100. data/test/mollie/organization_test.rb +28 -23
  101. data/test/mollie/payment/chargeback_test.rb +2 -3
  102. data/test/mollie/payment/refund_test.rb +2 -3
  103. data/test/mollie/payment_test.rb +272 -86
  104. data/test/mollie/permission_test.rb +0 -2
  105. data/test/mollie/profile_test.rb +129 -35
  106. data/test/mollie/refund_test.rb +90 -10
  107. data/test/mollie/settlement/chargeback_test.rb +2 -4
  108. data/test/mollie/settlement/payment_test.rb +2 -2
  109. data/test/mollie/settlement/refund_test.rb +2 -3
  110. data/test/mollie/settlement_test.rb +199 -98
  111. data/test/mollie/util_test.rb +31 -0
  112. metadata +96 -239
  113. data/examples/apis/api_docs.rb +0 -37
  114. data/examples/apis/chargebacks.rb +0 -17
  115. data/examples/apis/connect.rb +0 -58
  116. data/examples/apis/customers.rb +0 -116
  117. data/examples/apis/invoices.rb +0 -38
  118. data/examples/apis/issuers.rb +0 -35
  119. data/examples/apis/mandates.rb +0 -83
  120. data/examples/apis/methods.rb +0 -50
  121. data/examples/apis/organizations.rb +0 -16
  122. data/examples/apis/payments.rb +0 -174
  123. data/examples/apis/permissions.rb +0 -32
  124. data/examples/apis/profiles.rb +0 -126
  125. data/examples/apis/refunds.rb +0 -17
  126. data/examples/apis/settlements.rb +0 -84
  127. data/examples/apis/subscriptions.rb +0 -165
  128. data/examples/config.ru +0 -57
  129. data/examples/public/images/collapse.gif +0 -0
  130. data/examples/public/images/expand.gif +0 -0
  131. data/examples/public/images/explorer_icons.png +0 -0
  132. data/examples/public/images/favicon-16x16.png +0 -0
  133. data/examples/public/images/favicon-32x32.png +0 -0
  134. data/examples/public/images/favicon.ico +0 -0
  135. data/examples/public/images/logo_small.png +0 -0
  136. data/examples/public/images/pet_store_api.png +0 -0
  137. data/examples/public/images/throbber.gif +0 -0
  138. data/examples/public/images/wordnik_api.png +0 -0
  139. data/examples/public/index.html +0 -101
  140. data/examples/public/javascripts/lib/backbone-min.js +0 -1
  141. data/examples/public/javascripts/lib/es5-shim.js +0 -1
  142. data/examples/public/javascripts/lib/handlebars-4.0.5.js +0 -3
  143. data/examples/public/javascripts/lib/highlight.9.1.0.pack.js +0 -1
  144. data/examples/public/javascripts/lib/highlight.9.1.0.pack_extended.js +0 -1
  145. data/examples/public/javascripts/lib/jquery-1.8.0.min.js +0 -3
  146. data/examples/public/javascripts/lib/jquery.ba-bbq.min.js +0 -1
  147. data/examples/public/javascripts/lib/jquery.slideto.min.js +0 -1
  148. data/examples/public/javascripts/lib/jquery.wiggle.min.js +0 -1
  149. data/examples/public/javascripts/lib/js-yaml.min.js +0 -2
  150. data/examples/public/javascripts/lib/jsoneditor.min.js +0 -5
  151. data/examples/public/javascripts/lib/lodash.min.js +0 -2
  152. data/examples/public/javascripts/lib/marked.js +0 -1
  153. data/examples/public/javascripts/lib/object-assign-pollyfill.js +0 -1
  154. data/examples/public/javascripts/lib/sanitize-html.min.js +0 -4
  155. data/examples/public/javascripts/lib/swagger-oauth.js +0 -1
  156. data/examples/public/javascripts/swagger-ui.js +0 -25378
  157. data/examples/public/javascripts/swagger-ui.min.js +0 -15
  158. data/examples/public/javascripts/swagger_docs.js +0 -14
  159. data/examples/public/o2c.html +0 -20
  160. data/examples/public/stylesheets/reset.css +0 -1
  161. data/examples/public/stylesheets/screen.css +0 -1545
  162. data/examples/public/stylesheets/swagger_docs.css +0 -4
  163. data/examples/public/stylesheets/typography.css +0 -0
  164. data/lib/mollie/issuer.rb +0 -5
  165. data/lib/mollie/profile/api_key.rb +0 -19
  166. data/lib/mollie/relation.rb +0 -36
  167. data/test/mollie/issuer_test.rb +0 -19
  168. data/test/mollie/profile/apikey_test.rb +0 -31
  169. data/website-docs/chargebacks/list-all.rb +0 -12
  170. data/website-docs/customers/create-payment.rb +0 -13
  171. data/website-docs/customers/create.rb +0 -12
  172. data/website-docs/customers/delete.rb +0 -10
  173. data/website-docs/customers/get.rb +0 -10
  174. data/website-docs/customers/list-payments.rb +0 -10
  175. data/website-docs/customers/list.rb +0 -12
  176. data/website-docs/customers/update.rb +0 -11
  177. data/website-docs/invoices/get.rb +0 -10
  178. data/website-docs/invoices/list.rb +0 -12
  179. data/website-docs/issuers/get.rb +0 -10
  180. data/website-docs/issuers/list.rb +0 -12
  181. data/website-docs/mandates/create.rb +0 -16
  182. data/website-docs/mandates/delete.rb +0 -10
  183. data/website-docs/mandates/get.rb +0 -10
  184. data/website-docs/mandates/list.rb +0 -12
  185. data/website-docs/methods/get.rb +0 -10
  186. data/website-docs/methods/list.rb +0 -12
  187. data/website-docs/organisations/get.rb +0 -10
  188. data/website-docs/payments/create-refund.rb +0 -14
  189. data/website-docs/payments/create.rb +0 -16
  190. data/website-docs/payments/delete-refund.rb +0 -13
  191. data/website-docs/payments/delete.rb +0 -12
  192. data/website-docs/payments/get-chargeback.rb +0 -11
  193. data/website-docs/payments/get-refund.rb +0 -11
  194. data/website-docs/payments/get.rb +0 -10
  195. data/website-docs/payments/list-chargeback.rb +0 -13
  196. data/website-docs/payments/list-refunds.rb +0 -13
  197. data/website-docs/payments/list.rb +0 -12
  198. data/website-docs/payments/payment-webhook.rb +0 -21
  199. data/website-docs/permissions/get.rb +0 -10
  200. data/website-docs/permissions/list.rb +0 -12
  201. data/website-docs/profiles/create.rb +0 -15
  202. data/website-docs/profiles/delete.rb +0 -10
  203. data/website-docs/profiles/get-key.rb +0 -11
  204. data/website-docs/profiles/get.rb +0 -10
  205. data/website-docs/profiles/list-keys.rb +0 -13
  206. data/website-docs/profiles/list.rb +0 -12
  207. data/website-docs/profiles/reset-key.rb +0 -13
  208. data/website-docs/profiles/update.rb +0 -12
  209. data/website-docs/refunds/list.rb +0 -12
  210. data/website-docs/settlements/get.rb +0 -10
  211. data/website-docs/settlements/list-chargebacks.rb +0 -13
  212. data/website-docs/settlements/list-payments.rb +0 -13
  213. data/website-docs/settlements/list-refunds.rb +0 -13
  214. data/website-docs/settlements/list.rb +0 -12
  215. data/website-docs/settlements/next.rb +0 -9
  216. data/website-docs/settlements/open.rb +0 -9
  217. data/website-docs/subscriptions/create.rb +0 -14
  218. data/website-docs/subscriptions/delete.rb +0 -10
  219. data/website-docs/subscriptions/get.rb +0 -10
  220. data/website-docs/subscriptions/list.rb +0 -12
@@ -4,50 +4,66 @@ module Mollie
4
4
  class InvoiceTest < Test::Unit::TestCase
5
5
  def test_setting_attributes
6
6
  attributes = {
7
- resource: "invoice",
8
7
  id: "inv_xBEbP9rvAq",
9
8
  reference: "2016.10000",
10
9
  vat_number: "NL001234567B01",
11
10
  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"
11
+ issued_at: "2016-08-31",
12
+ due_at: "2016-09-14",
13
+ net_amount: {
14
+ value: "45.00",
15
+ currency: "EUR"
18
16
  },
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/"
17
+ vat_amount: {
18
+ value: "9.45",
19
+ currency: "EUR"
20
+ },
21
+ gross_amount: {
22
+ value: "54.45",
23
+ currency: "EUR"
24
+ },
25
+ lines: [
26
+ {
27
+ period: "2016-09",
28
+ description: "iDEAL transactiekosten",
29
+ count: 100,
30
+ vat_percentage: 21,
31
+ amount: {
32
+ value: "45.00",
33
+ currency: "EUR"
34
+ }
35
+ }
36
+ ],
37
+ _links: {
38
+ "pdf" => {
39
+ "href" => "https://www.mollie.com/beheer/facturen/2016.10000/52981a39788e5e0acaf71bbf570e941f/",
40
+ "type" => "application/pdf"
41
+ }
28
42
  }
29
43
  }
30
44
 
31
45
  invoice = Invoice.new(attributes)
32
46
 
33
- assert_equal "invoice", invoice.resource
34
47
  assert_equal "inv_xBEbP9rvAq", invoice.id
35
48
  assert_equal "2016.10000", invoice.reference
36
49
  assert_equal "NL001234567B01", invoice.vat_number
37
50
  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
51
+ assert_equal Time.parse("2016-08-31"), invoice.issued_at
52
+ assert_equal Time.parse("2016-09-14"), invoice.due_at
53
+ assert_equal 45.0, invoice.net_amount.value
54
+ assert_equal 'EUR', invoice.net_amount.currency
55
+ assert_equal BigDecimal.new(9.45, 3), invoice.vat_amount.value
56
+ assert_equal 'EUR', invoice.vat_amount.currency
57
+ assert_equal 54.45, invoice.gross_amount.value
58
+ assert_equal 'EUR', invoice.gross_amount.currency
43
59
 
44
60
  line = invoice.lines.first
45
61
  assert_equal "2016-09", line.period
46
62
  assert_equal "iDEAL transactiekosten", line.description
47
63
  assert_equal 100, line.count
48
64
  assert_equal 21, line.vat_percentage
49
- assert_equal 45.0, line.amount
50
-
65
+ assert_equal 45.0, line.amount.value
66
+ assert_equal 'EUR', line.amount.currency
51
67
 
52
68
  assert_equal "https://www.mollie.com/beheer/facturen/2016.10000/52981a39788e5e0acaf71bbf570e941f/", invoice.pdf
53
69
  end
@@ -4,37 +4,81 @@ module Mollie
4
4
  class ListTest < Test::Unit::TestCase
5
5
  def test_setting_attributes
6
6
  attributes = {
7
- 'total_count' => 280,
8
- 'offset' => 0,
9
- 'count' => 10,
10
- 'data' => [
7
+ '_embedded' => { "payments" => [
11
8
  { 'id' => "tr_1" },
12
9
  { '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"
10
+ ] },
11
+ 'count' => 2,
12
+ '_links' => {
13
+ "self" => {
14
+ "href" => "https://api.mollie.com/v2/payments?limit=5",
15
+ "type" => "application/hal+json"
16
+ },
17
+ "previous" => {
18
+ "href" => "https://api.mollie.com/v2/payments?from=tr_1&limit=1",
19
+ "type" => "application/hal+json"
20
+ },
21
+ "next" => {
22
+ "href" => "https://api.mollie.com/v2/payments?from=tr_2&limit=1",
23
+ "type" => "application/hal+json"
24
+ },
25
+ "documentation" => {
26
+ "href" => "https://docs.mollie.com/reference/payments/list",
27
+ "type" => "text/html"
28
+ }
19
29
  }
20
30
  }
21
31
 
22
32
  list = Mollie::List.new(attributes, Payment)
23
33
 
24
- assert_equal 280, list.total_count
25
- assert_equal 0, list.offset
26
- assert_equal 10, list.count
27
-
34
+ assert_equal 2, list.count
28
35
  assert_kind_of Payment, list.to_a[0]
29
36
  assert_equal "tr_1", list.to_a[0].id
30
37
 
31
38
  assert_kind_of Payment, list.to_a[1]
32
39
  assert_equal "tr_2", list.to_a[1].id
40
+ end
41
+
42
+ def test_next_page
43
+ stub_request(:get, "https://api.mollie.com/v2/payments?from=tr_WDqYK6vllg&limit=10").
44
+ to_return(
45
+ status: 200,
46
+ body: %{{"_embedded":{"payments":[{"id":"tr_1"},{"id":"tr_2"}]},"count":2}},
47
+ headers: {}
48
+ )
49
+
50
+ attributes = {
51
+ '_links' => {
52
+ 'next' => {
53
+ 'href' => 'https://api.mollie.com/v2/payments?from=tr_WDqYK6vllg&limit=10',
54
+ 'type' => 'application/hal+json'
55
+ }
56
+ }
57
+ }
58
+
59
+ list = Mollie::List.new(attributes, Payment)
60
+ assert_equal 2, list.next.count
61
+ end
62
+
63
+ def test_previous_page
64
+ stub_request(:get, "https://api.mollie.com/v2/payments?from=tr_SDkzMggpvx&limit=10").
65
+ to_return(
66
+ status: 200,
67
+ body: %{{"_embedded":{"payments":[{"id":"tr_1"},{"id":"tr_2"}]},"count":2}},
68
+ headers: {}
69
+ )
70
+
71
+ attributes = {
72
+ '_links' => {
73
+ 'previous' => {
74
+ 'href' => 'https://api.mollie.com/v2/payments?from=tr_SDkzMggpvx&limit=10',
75
+ 'type' => 'application/hal+json'
76
+ }
77
+ }
78
+ }
33
79
 
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
80
+ list = Mollie::List.new(attributes, Payment)
81
+ assert_equal 2, list.previous.count
38
82
  end
39
83
  end
40
84
  end
@@ -6,13 +6,9 @@ module Mollie
6
6
  attributes = {
7
7
  id: "creditcard",
8
8
  description: "Credit card",
9
- amount: {
10
- 'minimum' => "0.31",
11
- 'maximum' => "10000.00"
12
- },
13
9
  image: {
14
- 'normal' => "https://www.mollie.com/images/payscreen/methods/creditcard.png",
15
- 'bigger' => "https://www.mollie.com/images/payscreen/methods/creditcard@2x.png"
10
+ 'size1x' => "https://www.mollie.com/images/payscreen/methods/creditcard.png",
11
+ 'size2x' => "https://www.mollie.com/images/payscreen/methods/creditcard@2x.png"
16
12
  }
17
13
  }
18
14
 
@@ -20,8 +16,6 @@ module Mollie
20
16
 
21
17
  assert_equal "creditcard", method.id
22
18
  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
19
  assert_equal "https://www.mollie.com/images/payscreen/methods/creditcard.png", method.normal_image
26
20
  assert_equal "https://www.mollie.com/images/payscreen/methods/creditcard@2x.png", method.bigger_image
27
21
  end
@@ -4,38 +4,43 @@ module Mollie
4
4
  class OrganizationTest < Test::Unit::TestCase
5
5
  def test_setting_attributes
6
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'
7
+ id: 'org_12345678',
8
+ name: 'Mollie B.V.',
9
+ email: 'info@mollie.com',
10
+ address: {
11
+ street_and_number: "Keizersgracht 313",
12
+ postal_code: "1016 EE",
13
+ city: "Amsterdam",
14
+ country: "NL"
15
+ },
16
+ registration_number: '30204462',
17
+ vat_number: 'NL815839091B01',
19
18
  }
20
19
 
21
20
  organization = Organization.new(attributes)
22
21
 
23
- assert_equal 'org_1234567', organization.id
22
+ assert_equal 'org_12345678', organization.id
24
23
  assert_equal 'Mollie B.V.', organization.name
25
24
  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
25
+ assert_equal 'Keizersgracht 313', organization.address.street_and_number
26
+ assert_equal '1016 EE', organization.address.postal_code
27
+ assert_equal 'Amsterdam', organization.address.city
28
+ assert_equal 'NL', organization.address.country
32
29
  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
30
+ assert_equal 'NL815839091B01', organization.vat_number
35
31
  end
36
32
 
37
- def test_verified_datetime_optional
38
- assert_equal nil, Organization.new(verified_datetime: nil).verified_datetime
33
+ def test_current_organization
34
+ stub_request(:get, "https://api.mollie.com/v2/organizations/me")
35
+ .to_return(:status => 200, :body => %{
36
+ {
37
+ "resource": "organization",
38
+ "id": "org_12345678"
39
+ }
40
+ }, :headers => {})
41
+
42
+ organization = Organization.current
43
+ assert_equal "org_12345678", organization.id
39
44
  end
40
45
  end
41
46
  end
@@ -9,13 +9,12 @@ module Mollie
9
9
  end
10
10
 
11
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 => {})
12
+ stub_request(:get, "https://api.mollie.com/v2/payments/pay-id/chargebacks")
13
+ .to_return(:status => 200, :body => %{{"_embedded" : {"chargebacks" : [{"id":"re-id"}]}}}, :headers => {})
14
14
 
15
15
  chargebacks = Mollie::Payment::Chargeback.all(payment_id: "pay-id")
16
16
 
17
17
  assert_equal "re-id", chargebacks.first.id
18
- assert_equal "pay-id", chargebacks.first.payment.id
19
18
  end
20
19
  end
21
20
  end
@@ -9,13 +9,12 @@ module Mollie
9
9
  end
10
10
 
11
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 => {})
12
+ stub_request(:get, "https://api.mollie.com/v2/payments/pay-id/refunds")
13
+ .to_return(:status => 200, :body => %{{"_embedded" : { "refunds" : [{"id":"re-id"}]}}}, :headers => {})
14
14
 
15
15
  refunds = Mollie::Payment::Refund.all(payment_id: "pay-id")
16
16
 
17
17
  assert_equal "re-id", refunds.first.id
18
- assert_equal "pay-id", refunds.first.payment.id
19
18
  end
20
19
  end
21
20
  end
@@ -4,56 +4,75 @@ module Mollie
4
4
  class PaymentTest < Test::Unit::TestCase
5
5
  def test_setting_attributes
6
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'
7
+ resource: "payment",
8
+ id: "tr_7UhSN1zuXS",
9
+ mode: "test",
10
+ created_at: "2018-03-20T09:13:37+00:00",
11
+ amount: {
12
+ "value" => "10.00",
13
+ "currency" => "EUR"
18
14
  },
19
- details: {
15
+ description: "My first payment",
16
+ method: "ideal",
17
+ country_code: "NL",
18
+ metadata: {
19
+ order_id: "12345"
20
+ },
21
+ details: {
20
22
  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
+ consumer_account: "NL53INGB0618365937",
24
+ consumer_bic: "INGBNL2A"
23
25
  },
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',
26
+ status: "paid",
27
+ paid_at: "2018-03-20T09:14:37+00:00",
28
+ is_cancelable: false,
29
+ expires_at: "2018-03-20T09:28:37+00:00",
30
+ locale: "nl_NL",
31
+ profile_id: "pfl_QkEhN94Ba",
32
+ sequence_type: "oneoff",
33
+ redirect_url: "https://webshop.example.org/order/12345",
34
+ webhook_url: "https://webshop.example.org/payments/webhook",
35
+ _links: {
36
+ "self" => {
37
+ "href" => "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS",
38
+ "type" => "application/json"
39
+ },
40
+ "checkout" => {
41
+ "href" => "https://www.mollie.com/payscreen/select-method/7UhSN1zuXS",
42
+ "type" => "text/html"
43
+ },
44
+ "settlement" => {
45
+ "href" => "https://webshop.example.org/payment/tr_WDqYK6vllg/settlement",
46
+ },
47
+ "refunds" => {
48
+ "href" => "https://webshop.example.org/payment/tr_WDqYK6vllg/refunds",
49
+ "type" => "text/html"
50
+ }
32
51
  }
33
52
  }
34
53
 
35
54
  payment = Payment.new(attributes)
36
55
 
37
- assert_equal 'tr_WDqYK6vllg', payment.id
56
+ assert_equal 'tr_7UhSN1zuXS', payment.id
38
57
  assert_equal 'test', payment.mode
39
- assert_equal Time.parse('2016-10-08T10:10:52.0Z'), payment.created_datetime
58
+ assert_equal Time.parse('2018-03-20T09:13:37+00:00'), payment.created_at
40
59
  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
60
+ assert_equal true, payment.paid?
61
+ assert_equal Time.parse('2018-03-20T09:14:37+00:00'), payment.paid_at
62
+ assert_equal 10.00, payment.amount.value
63
+ assert_equal 'EUR', payment.amount.currency
64
+ assert_equal 'My first payment', payment.description
44
65
  assert_equal 'ideal', payment.method
45
- assert_equal '33', payment.metadata.order_id
66
+ assert_equal '12345', payment.metadata.order_id
46
67
  assert_equal "Hr E G H K\u00fcppers en\/of MW M.J. K\u00fcppers-Veeneman", payment.details.consumer_name
47
68
  assert_equal 'NL53INGB0618365937', payment.details.consumer_account
48
69
  assert_equal 'INGBNL2A', payment.details.consumer_bic
49
- assert_equal 'nl', payment.locale
70
+ assert_equal 'nl_NL', payment.locale
50
71
  assert_equal 'NL', payment.country_code
51
72
  assert_equal 'pfl_QkEhN94Ba', payment.profile_id
52
73
  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
74
+ assert_equal 'https://webshop.example.org/order/12345', payment.redirect_url
75
+ assert_equal 'https://www.mollie.com/payscreen/select-method/7UhSN1zuXS', payment.checkout_url
57
76
  end
58
77
 
59
78
  def test_status_open
@@ -61,9 +80,14 @@ module Mollie
61
80
  assert !Payment.new(status: 'not-open').open?
62
81
  end
63
82
 
64
- def test_status_cancelled
65
- assert Payment.new(status: Payment::STATUS_CANCELLED).cancelled?
66
- assert !Payment.new(status: 'not-cancelled').cancelled?
83
+ def test_status_canceled
84
+ assert Payment.new(status: Payment::STATUS_CANCELED).canceled?
85
+ assert !Payment.new(status: 'not-canceled').canceled?
86
+ end
87
+
88
+ def test_status_pending
89
+ assert Payment.new(status: Payment::STATUS_PENDING).pending?
90
+ assert !Payment.new(status: 'not-pending').pending?
67
91
  end
68
92
 
69
93
  def test_status_expired
@@ -71,91 +95,253 @@ module Mollie
71
95
  assert !Payment.new(status: 'not-expired').expired?
72
96
  end
73
97
 
74
- def test_status_paidout
75
- assert Payment.new(status: Payment::STATUS_PAIDOUT).paidout?
76
- assert !Payment.new(status: 'not-paidout').paidout?
98
+ def test_status_failed
99
+ assert Payment.new(status: Payment::STATUS_FAILED).failed?
100
+ assert !Payment.new(status: 'not-failed').failed?
77
101
  end
78
102
 
79
- def test_status_refunded
80
- assert Payment.new(status: Payment::STATUS_REFUNDED).refunded?
81
- assert !Payment.new(status: 'not-refunded').refunded?
103
+ def test_status_paid
104
+ assert Payment.new(status: Payment::STATUS_PAID).paid?
105
+ assert !Payment.new(status: nil).paid?
82
106
  end
83
107
 
84
- def test_status_paid
85
- assert Payment.new(paid_datetime: Time.now).paid?
86
- assert !Payment.new(paid_datetime: nil).paid?
108
+ def test_create_payment
109
+ stub_request(:post, "https://api.mollie.com/v2/payments")
110
+ .with(body: %{{"amount":{"value":1.95,"currency":"EUR"}}})
111
+ .to_return(:status => 201, :body => %{{"id":"my-id", "amount":{ "value" : 1.95, "currency" : "EUR"}}}, :headers => {})
112
+
113
+ payment = Payment.create(amount: { value: 1.95, currency: "EUR" })
114
+
115
+ assert_kind_of Mollie::Payment, payment
116
+ assert_equal "my-id", payment.id
117
+ assert_equal BigDecimal.new("1.95"), payment.amount.value
118
+ assert_equal 'EUR', payment.amount.currency
87
119
  end
88
120
 
89
- def test_status_failed
90
- assert Payment.new(status: Payment::STATUS_FAILED).failed?
91
- assert !Payment.new(status: 'not-failed').failed?
121
+ def test_create_payment_for_customer
122
+ stub_request(:post, "https://api.mollie.com/v2/payments")
123
+ .with(body: %{{"customerId":"cst_8wmqcHMN4U","amount":{"value":1.95,"currency":"EUR"}}})
124
+ .to_return(:status => 201, :body => %{{"id":"my-id", "amount":{ "value" : 1.95, "currency" : "EUR"}, "customerId":"cst_8wmqcHMN4U"}}, :headers => {})
125
+
126
+ payment = Payment.create(
127
+ customer_id: 'cst_8wmqcHMN4U',
128
+ amount: { value: 1.95, currency: "EUR" }
129
+ )
130
+
131
+ assert_kind_of Mollie::Payment, payment
132
+ assert_equal "cst_8wmqcHMN4U", payment.customer_id
92
133
  end
93
134
 
94
- def test_status_pending
95
- assert Payment.new(status: Payment::STATUS_PENDING).pending?
96
- assert !Payment.new(status: 'not-pending').pending?
135
+ def test_refund!
136
+ stub_request(:get, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg")
137
+ .to_return(:status => 200, :body => %{
138
+ {
139
+ "resource": "payment",
140
+ "id": "tr_WDqYK6vllg",
141
+ "amount": {
142
+ "value": "42.10",
143
+ "currency": "EUR"
144
+ }
145
+ }
146
+ }, :headers => {})
147
+
148
+ stub_request(:post, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds")
149
+ .to_return(:status => 200, :body => %{
150
+ {
151
+ "resource": "refund",
152
+ "id": "re_4qqhO89gsT"
153
+ }
154
+ }, :headers => {})
155
+
156
+ payment = Payment.get("tr_WDqYK6vllg")
157
+ refund = payment.refund!
158
+ assert_equal "re_4qqhO89gsT", refund.id
97
159
  end
98
160
 
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?
161
+ def test_refund_with_custom_amount_and_description
162
+ stub_request(:get, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg")
163
+ .to_return(:status => 200, :body => %{
164
+ {
165
+ "resource": "payment",
166
+ "id": "tr_WDqYK6vllg",
167
+ "amount": {
168
+ "value": "42.10",
169
+ "currency": "EUR"
170
+ }
171
+ }
172
+ }, :headers => {})
173
+
174
+ stub_request(:post, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds")
175
+ .with(body: %{{"amount":{"value":"9.95","currency":"EUR"},"description":"Test refund"}})
176
+ .to_return(:status => 200, :body => %{
177
+ {
178
+ "resource": "refund",
179
+ "id": "re_4qqhO89gsT"
180
+ }
181
+ }, :headers => {})
182
+
183
+ payment = Payment.get("tr_WDqYK6vllg")
184
+ refund = payment.refund!(
185
+ amount: { value: "9.95", currency: "EUR" },
186
+ description: 'Test refund'
187
+ )
188
+
189
+ assert_equal "re_4qqhO89gsT", refund.id
190
+ end
191
+
192
+ def test_application_fee
193
+ stub_request(:get, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg")
194
+ .to_return(:status => 200, :body => %{
195
+ {
196
+ "application_fee": {
197
+ "amount": {
198
+ "value": "42.10",
199
+ "currency": "EUR"
200
+ },
201
+ "description": "Example application fee"
202
+ }
203
+ }
204
+ }, :headers => {})
205
+
206
+ payment = Payment.get("tr_WDqYK6vllg")
207
+ assert_equal 42.10, payment.application_fee.amount.value
208
+ assert_equal "EUR", payment.application_fee.amount.currency
102
209
  end
103
210
 
104
211
  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 => {})
212
+ stub_request(:get, "https://api.mollie.com/v2/payments/pay-id/refunds")
213
+ .to_return(:status => 200, :body => %{{"_embedded" : {"refunds" : [{"id":"ref-id", "payment_id":"pay-id"}]}}}, :headers => {})
107
214
 
108
- refunds = Payment.new(id: "pay-id").refunds.all
215
+ refunds = Payment.new(id: "pay-id").refunds
109
216
 
110
217
  assert_equal "ref-id", refunds.first.id
111
218
  end
112
219
 
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 => {})
220
+ def test_list_chargebacks
221
+ stub_request(:get, "https://api.mollie.com/v2/payments/pay-id/chargebacks")
222
+ .to_return(:status => 200, :body => %{{"_embedded" : {"chargebacks" :[{"id":"chb-id", "payment_id":"pay-id"}]}}}, :headers => {})
223
+
224
+ chargebacks = Payment.new(id: "pay-id").chargebacks
225
+ assert_equal "chb-id", chargebacks.first.id
226
+ end
117
227
 
118
- refund = Payment.new(id: "pay-id").refunds.create(amount: 1.95)
228
+ def test_get_settlement
229
+ stub_request(:get, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg")
230
+ .to_return(:status => 200, :body => %{
231
+ {
232
+ "resource": "payment",
233
+ "id": "tr_WDqYK6vllg",
234
+ "settlement_id": "stl_jDk30akdN"
235
+ }
236
+ }, :headers => {})
119
237
 
120
- assert_equal "my-id", refund.id
121
- assert_equal BigDecimal.new("1.95"), refund.amount
238
+ stub_request(:get, "https://api.mollie.com/v2/settlements/stl_jDk30akdN")
239
+ .to_return(:status => 200, :body => %{
240
+ {
241
+ "resource": "settlement",
242
+ "id": "stl_jDk30akdN"
243
+ }
244
+ }, :headers => {})
245
+
246
+ payment = Payment.get("tr_WDqYK6vllg")
247
+ settlement = payment.settlement
248
+ assert_equal "stl_jDk30akdN", settlement.id
249
+ end
250
+
251
+ def test_nil_settlement
252
+ payment = Payment.new(id: "tr_WDqYK6vllg")
253
+ assert payment.settlement.nil?
122
254
  end
123
255
 
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 => {})
256
+ def test_get_mandate
257
+ stub_request(:get, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg")
258
+ .to_return(:status => 200, :body => %{
259
+ {
260
+ "resource": "payment",
261
+ "id": "tr_WDqYK6vllg",
262
+ "mandate_id": "mdt_h3gAaD5zP"
263
+ }
264
+ }, :headers => {})
265
+
266
+ stub_request(:get, "https://api.mollie.com/v2/mandates/mdt_h3gAaD5zP")
267
+ .to_return(:status => 200, :body => %{
268
+ {
269
+ "resource": "mandate",
270
+ "id": "mdt_h3gAaD5zP"
271
+ }
272
+ }, :headers => {})
273
+
274
+ payment = Payment.get("tr_WDqYK6vllg")
275
+ mandate = payment.mandate
276
+ assert_equal "mdt_h3gAaD5zP", mandate.id
277
+ end
127
278
 
128
- refund = Payment.new(id: "pay-id").refunds.delete("ref-id")
129
- assert_equal nil, refund
279
+ def test_nil_mandate
280
+ payment = Payment.new(id: "tr_WDqYK6vllg")
281
+ assert payment.mandate.nil?
130
282
  end
131
283
 
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 => {})
284
+ def test_get_subscription
285
+ stub_request(:get, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg")
286
+ .to_return(:status => 200, :body => %{
287
+ {
288
+ "resource": "payment",
289
+ "id": "tr_WDqYK6vllg",
290
+ "subscription_id": "sub_rVKGtNd6s3",
291
+ "customer_id": "cst_8wmqcHMN4U"
292
+ }
293
+ }, :headers => {})
135
294
 
136
- refund = Payment.new(id: "pay-id").refunds.get("ref-id")
295
+ stub_request(:get, "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions/sub_rVKGtNd6s3")
296
+ .to_return(:status => 200, :body => %{
297
+ {
298
+ "resource": "subscription",
299
+ "id": "sub_rVKGtNd6s3"
300
+ }
301
+ }, :headers => {})
137
302
 
138
- assert_equal "ref-id", refund.id
139
- assert_equal "pay-id", refund.payment.id
303
+ payment = Payment.get("tr_WDqYK6vllg")
304
+ subscription = payment.subscription
305
+ assert_equal "sub_rVKGtNd6s3", subscription.id
140
306
  end
141
307
 
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 => {})
308
+ def test_nil_subscription
309
+ payment = Payment.new(id: "tr_WDqYK6vllg")
310
+ assert payment.subscription.nil?
145
311
 
146
- chargebacks = Payment.new(id: "pay-id").chargebacks.all
312
+ payment = Payment.new(id: "tr_WDqYK6vllg", customer_id: "cst_8wmqcHMN4U")
313
+ assert payment.subscription.nil?
147
314
 
148
- assert_equal "chb-id", chargebacks.first.id
315
+ payment = Payment.new(id: "tr_WDqYK6vllg", subscription_id: "sub_rVKGtNd6s3")
316
+ assert payment.subscription.nil?
149
317
  end
150
318
 
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 => {})
319
+ def test_get_customer
320
+ stub_request(:get, "https://api.mollie.com/v2/payments/tr_WDqYK6vllg")
321
+ .to_return(:status => 200, :body => %{
322
+ {
323
+ "resource": "payment",
324
+ "id": "tr_WDqYK6vllg",
325
+ "customer_id": "cst_8wmqcHMN4U"
326
+ }
327
+ }, :headers => {})
154
328
 
155
- chargeback = Payment.new(id: "pay-id").chargebacks.get("chb-id")
329
+ stub_request(:get, "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U")
330
+ .to_return(:status => 200, :body => %{
331
+ {
332
+ "resource": "customer",
333
+ "id": "cst_8wmqcHMN4U"
334
+ }
335
+ }, :headers => {})
336
+
337
+ payment = Payment.get("tr_WDqYK6vllg")
338
+ customer = payment.customer
339
+ assert_equal "cst_8wmqcHMN4U", customer.id
340
+ end
156
341
 
157
- assert_equal "chb-id", chargeback.id
158
- assert_equal "pay-id", chargeback.payment.id
342
+ def test_nil_customer
343
+ payment = Payment.new(id: "tr_WDqYK6vllg")
344
+ assert payment.customer.nil?
159
345
  end
160
346
  end
161
347
  end