mollie-api-ruby 1.4.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +12 -0
  3. data/CHANGELOG.md +6 -0
  4. data/README.mdown +5 -5
  5. data/Rakefile +6 -0
  6. data/examples/1-new-payment.rb +4 -5
  7. data/examples/2-webhook-verification.rb +2 -2
  8. data/examples/4-ideal-payment.rb +3 -3
  9. data/examples/5-payments-history.rb +3 -3
  10. data/examples/6-list-activated-methods.rb +3 -3
  11. data/examples/7-refund-payment.rb +5 -5
  12. data/lib/{Mollie/API → mollie/api}/cacert.pem +0 -0
  13. data/lib/mollie/api/client.rb +120 -0
  14. data/lib/{Mollie/API/Client/Version.rb → mollie/api/client/version.rb} +1 -1
  15. data/lib/{Mollie/API/Exception.rb → mollie/api/exception.rb} +0 -0
  16. data/lib/mollie/api/object/base.rb +18 -0
  17. data/lib/mollie/api/object/customer.rb +28 -0
  18. data/lib/{Mollie/API/Object/Issuer.rb → mollie/api/object/issuer.rb} +1 -3
  19. data/lib/mollie/api/object/list.rb +44 -0
  20. data/lib/mollie/api/object/mandate.rb +35 -0
  21. data/lib/{Mollie/API/Object/Method.rb → mollie/api/object/method.rb} +12 -4
  22. data/lib/mollie/api/object/payment.rb +123 -0
  23. data/lib/mollie/api/object/payment/refund.rb +43 -0
  24. data/lib/mollie/api/object/subscription.rb +67 -0
  25. data/lib/{Mollie/API/Resource/Base.rb → mollie/api/resource/base.rb} +8 -8
  26. data/lib/{Mollie/API/Resource/Customers.rb → mollie/api/resource/customers.rb} +2 -2
  27. data/lib/{Mollie/API/Resource/Customers/Mandates.rb → mollie/api/resource/customers/mandates.rb} +5 -5
  28. data/lib/{Mollie/API/Resource/Customers/Payments.rb → mollie/api/resource/customers/payments.rb} +5 -5
  29. data/lib/mollie/api/resource/customers/subscriptions.rb +27 -0
  30. data/lib/{Mollie/API/Resource/Issuers.rb → mollie/api/resource/issuers.rb} +2 -2
  31. data/lib/{Mollie/API/Resource/Methods.rb → mollie/api/resource/methods.rb} +2 -2
  32. data/lib/{Mollie/API/Resource/Payments.rb → mollie/api/resource/payments.rb} +2 -2
  33. data/lib/{Mollie/API/Resource/Payments/Refunds.rb → mollie/api/resource/payments/refunds.rb} +5 -5
  34. data/lib/mollie/api/util.rb +37 -0
  35. data/mollie.gemspec +16 -14
  36. data/test/helper.rb +4 -0
  37. data/test/mollie/api/client_test.rb +99 -0
  38. data/test/mollie/api/object/base_test.rb +21 -0
  39. data/test/mollie/api/object/customer_test.rb +35 -0
  40. data/test/mollie/api/object/issuer_test.rb +23 -0
  41. data/test/mollie/api/object/list_test.rb +44 -0
  42. data/test/mollie/api/object/mandate_test.rb +45 -0
  43. data/test/mollie/api/object/method_test.rb +33 -0
  44. data/test/mollie/api/object/payment/refund_test.rb +46 -0
  45. data/test/mollie/api/object/payment_test.rb +91 -0
  46. data/test/mollie/api/object/subscription_test.rb +68 -0
  47. data/test/mollie/api/resource/base_test.rb +83 -0
  48. data/test/mollie/api/resource/customers/mandates_test.rb +23 -0
  49. data/test/mollie/api/resource/customers/payments_test.rb +23 -0
  50. data/test/mollie/api/resource/customers/subscriptions_test.rb +23 -0
  51. data/test/mollie/api/resource/customers_test.rb +13 -0
  52. data/test/mollie/api/resource/issuers_test.rb +13 -0
  53. data/test/mollie/api/resource/methods_test.rb +13 -0
  54. data/test/mollie/api/resource/payments/refunds_test.rb +23 -0
  55. data/test/mollie/api/resource/payments_test.rb +13 -0
  56. data/test/run-test.rb +15 -0
  57. metadata +99 -52
  58. data/lib/Mollie/API/Client.rb +0 -130
  59. data/lib/Mollie/API/Object/Base.rb +0 -18
  60. data/lib/Mollie/API/Object/Customer.rb +0 -16
  61. data/lib/Mollie/API/Object/List.rb +0 -35
  62. data/lib/Mollie/API/Object/Mandate.rb +0 -22
  63. data/lib/Mollie/API/Object/Payment.rb +0 -68
  64. data/lib/Mollie/API/Object/Payment/Refund.rb +0 -15
  65. data/lib/Mollie/API/Object/Subscription.rb +0 -26
  66. data/lib/Mollie/API/Resource/Customers/Subscriptions.rb +0 -27
@@ -0,0 +1,33 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ module API
5
+ module Object
6
+ class MethodTest < Test::Unit::TestCase
7
+ def test_setting_attributes
8
+ attributes = {
9
+ id: "creditcard",
10
+ description: "Credit card",
11
+ amount: {
12
+ 'minimum' => "0.31",
13
+ 'maximum' => "10000.00"
14
+ },
15
+ image: {
16
+ 'normal' => "https://www.mollie.com/images/payscreen/methods/creditcard.png",
17
+ 'bigger' => "https://www.mollie.com/images/payscreen/methods/creditcard@2x.png"
18
+ }
19
+ }
20
+
21
+ method = Method.new(attributes)
22
+
23
+ assert_equal "creditcard", method.id
24
+ assert_equal "Credit card", method.description
25
+ assert_equal BigDecimal.new("0.31"), method.minimum_amount
26
+ assert_equal BigDecimal.new("10000.0"), method.maximum_amount
27
+ assert_equal "https://www.mollie.com/images/payscreen/methods/creditcard.png", method.normal_image
28
+ assert_equal "https://www.mollie.com/images/payscreen/methods/creditcard@2x.png", method.bigger_image
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,46 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ module API
5
+ module Object
6
+ class Payment
7
+ class RefundTest < Test::Unit::TestCase
8
+ def test_setting_attributes
9
+ attributes = {
10
+ id: "re_4qqhO89gsT",
11
+ payment: {
12
+ id: "tr_WDqYK6vllg",
13
+ },
14
+ amount: "5.95",
15
+ refunded_datetime: "2016-10-08T07:59:53.0Z",
16
+ status: "pending"
17
+ }
18
+
19
+ refund = Refund.new(attributes)
20
+
21
+ assert_equal "re_4qqhO89gsT", refund.id
22
+ assert_equal BigDecimal.new("5.95"), refund.amount
23
+ assert_kind_of Payment, refund.payment
24
+ assert_equal Time.parse("2016-10-08T07:59:53.0Z"), refund.refunded_datetime
25
+ assert_equal Refund::STATUS_PENDING, refund.status
26
+ end
27
+
28
+ def test_pending?
29
+ assert Refund.new(status: Refund::STATUS_PENDING).pending?
30
+ assert !Refund.new(status: 'not-pending').pending?
31
+ end
32
+
33
+ def test_processing?
34
+ assert Refund.new(status: Refund::STATUS_PROCESSING).processing?
35
+ assert !Refund.new(status: 'not-processing').processing?
36
+ end
37
+
38
+ def test_refunded?
39
+ assert Refund.new(status: Refund::STATUS_REFUNDED).refunded?
40
+ assert !Refund.new(status: 'not-refunded').refunded?
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,91 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ module API
5
+ module Object
6
+ class PaymentTest < Test::Unit::TestCase
7
+ def test_setting_attributes
8
+ attributes = {
9
+ id: 'tr_WDqYK6vllg',
10
+ mode: 'test',
11
+ created_datetime: '2016-10-08T10:10:52.0Z',
12
+ status: 'paid',
13
+ paid_datetime: '2016-10-08T10:15:35.0Z',
14
+ amount: 35.07,
15
+ description: 'Order 33',
16
+ method: 'ideal',
17
+ metadata: {
18
+ order_id: '33'
19
+ },
20
+ details: {
21
+ consumer_name: "Hr E G H K\u00fcppers en\/of MW M.J. K\u00fcppers-Veeneman",
22
+ consumer_account: 'NL53INGB0618365937',
23
+ consumer_bic: 'INGBNL2A'
24
+ },
25
+ locale: 'nl',
26
+ profile_id: 'pfl_QkEhN94Ba',
27
+ links: {
28
+ 'webhook_url' => 'https://webshop.example.org/payments/webhook',
29
+ 'redirect_url' => 'https://webshop.example.org/order/33/',
30
+ 'payment_url' => 'https://webshop.example.org/payment/tr_WDqYK6vllg',
31
+ 'settlement' => 'https://webshop.example.org/payment/tr_WDqYK6vllg/settlement',
32
+ 'refunds' => 'https://webshop.example.org/payment/tr_WDqYK6vllg/refunds',
33
+ }
34
+ }
35
+
36
+ payment = Payment.new(attributes)
37
+
38
+ assert_equal 'tr_WDqYK6vllg', payment.id
39
+ assert_equal 'test', payment.mode
40
+ assert_equal Time.parse('2016-10-08T10:10:52.0Z'), payment.created_datetime
41
+ assert_equal 'paid', payment.status
42
+ assert_equal Time.parse('2016-10-08T10:15:35.0Z'), payment.paid_datetime
43
+ assert_equal 35.07, payment.amount
44
+ assert_equal 'Order 33', payment.description
45
+ assert_equal 'ideal', payment.method
46
+ assert_equal '33', payment.metadata.order_id
47
+ assert_equal "Hr E G H K\u00fcppers en\/of MW M.J. K\u00fcppers-Veeneman", payment.details.consumer_name
48
+ assert_equal 'NL53INGB0618365937', payment.details.consumer_account
49
+ assert_equal 'INGBNL2A', payment.details.consumer_bic
50
+ assert_equal 'nl', payment.locale
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
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
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,68 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ module API
5
+ module Object
6
+ class SubscriptionTest < Test::Unit::TestCase
7
+ def test_setting_attributes
8
+ attributes = {
9
+ id: "sub_rVKGtNd6s3",
10
+ customer_id: "cst_stTC2WHAuS",
11
+ mode: "live",
12
+ created_datetime: "2016-06-01T12:23:34.0Z",
13
+ status: "active",
14
+ amount: "25.00",
15
+ times: 4,
16
+ interval: "3 months",
17
+ description: "Quarterly payment",
18
+ method: "creditcard",
19
+ cancelled_datetime: "2016-06-01T12:23:34.0Z",
20
+ links: {
21
+ 'webhook_url' => "https://example.org/payments/webhook"
22
+ }
23
+ }
24
+
25
+ subscription = Subscription.new(attributes)
26
+
27
+ assert_equal "sub_rVKGtNd6s3", subscription.id
28
+ assert_equal "cst_stTC2WHAuS", subscription.customer_id
29
+ assert_equal "live", subscription.mode
30
+ assert_equal Time.parse("2016-06-01T12:23:34.0Z"), subscription.created_datetime
31
+ assert_equal "active", subscription.status
32
+ assert_equal BigDecimal.new(25, 2), subscription.amount
33
+ assert_equal 4, subscription.times
34
+ assert_equal "3 months", subscription.interval
35
+ assert_equal "Quarterly payment", subscription.description
36
+ assert_equal "creditcard", subscription.method
37
+ assert_equal Time.parse("2016-06-01T12:23:34.0Z"), subscription.cancelled_datetime
38
+ assert_equal "https://example.org/payments/webhook", subscription.webhook_url
39
+ end
40
+
41
+ def test_status_active
42
+ assert Subscription.new(status: Subscription::STATUS_ACTIVE).active?
43
+ assert !Subscription.new(status: 'not-active').active?
44
+ end
45
+
46
+ def test_status_pending
47
+ assert Subscription.new(status: Subscription::STATUS_PENDING).pending?
48
+ assert !Subscription.new(status: 'not-pending').pending?
49
+ end
50
+
51
+ def test_status_suspended
52
+ assert Subscription.new(status: Subscription::STATUS_SUSPENDED).suspended?
53
+ assert !Subscription.new(status: 'not-suspended').suspended?
54
+ end
55
+
56
+ def test_status_cancelled
57
+ assert Subscription.new(status: Subscription::STATUS_CANCELLED).cancelled?
58
+ assert !Subscription.new(status: 'not-cancelled').cancelled?
59
+ end
60
+
61
+ def test_status_completed
62
+ assert Subscription.new(status: Subscription::STATUS_COMPLETED).completed?
63
+ assert !Subscription.new(status: 'not-completed').completed?
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,83 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ module API
5
+ module Resource
6
+ class TestObject < Object::Base
7
+ attr_accessor :id, :amount
8
+ end
9
+
10
+ class TestResource < Base
11
+ def resource_object
12
+ TestObject
13
+ end
14
+ end
15
+
16
+ class BaseTest < Test::Unit::TestCase
17
+ def test_resource_name
18
+ test_resource = TestResource.new(nil)
19
+ assert_equal "testresource", test_resource.resource_name
20
+ end
21
+
22
+ def test_get
23
+ stub_request(:get, "https://api.mollie.nl/v1/testresource/my-id")
24
+ .to_return(:status => 200, :body => %{{"id":"my-id"}}, :headers => {})
25
+
26
+ client = Client.new("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM")
27
+ test_resource = TestResource.new(client)
28
+ resource = test_resource.get("my-id")
29
+
30
+ assert_equal "my-id", resource.id
31
+ end
32
+
33
+ def test_create
34
+ stub_request(:post, "https://api.mollie.nl/v1/testresource")
35
+ .with(body: %{{"amount":1.95}})
36
+ .to_return(:status => 201, :body => %{{"id":"my-id", "amount":1.00}}, :headers => {})
37
+
38
+ client = Client.new("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM")
39
+ test_resource = TestResource.new(client)
40
+ resource = test_resource.create(amount: 1.95)
41
+
42
+ assert_equal "my-id", resource.id
43
+ assert_equal BigDecimal.new("1.00"), resource.amount
44
+ end
45
+
46
+ def test_update
47
+ stub_request(:post, "https://api.mollie.nl/v1/testresource/my-id")
48
+ .with(body: %{{"amount":1.95}})
49
+ .to_return(:status => 201, :body => %{{"id":"my-id", "amount":1.00}}, :headers => {})
50
+
51
+ client = Client.new("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM")
52
+ test_resource = TestResource.new(client)
53
+ resource = test_resource.update("my-id", amount: 1.95)
54
+
55
+ assert_equal "my-id", resource.id
56
+ assert_equal BigDecimal.new("1.00"), resource.amount
57
+ end
58
+
59
+ def test_delete
60
+ stub_request(:delete, "https://api.mollie.nl/v1/testresource/my-id")
61
+ .to_return(:status => 204, :headers => {})
62
+
63
+ client = Client.new("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM")
64
+ test_resource = TestResource.new(client)
65
+ resource = test_resource.delete("my-id")
66
+
67
+ assert_equal nil, resource
68
+ end
69
+
70
+ def test_all
71
+ stub_request(:get, "https://api.mollie.nl/v1/testresource")
72
+ .to_return(:status => 200, :body => %{{"data":[{"id":"my-id"}]}}, :headers => {})
73
+
74
+ client = Client.new("test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM")
75
+ test_resource = TestResource.new(client)
76
+ resource = test_resource.all
77
+
78
+ assert_equal "my-id", resource.first.id
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,23 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ module API
5
+ module Resource
6
+ class Customers
7
+ class MandatesTest < Test::Unit::TestCase
8
+ def test_resource_object
9
+ assert_equal Object::Mandate, Mandates.new(nil).resource_object
10
+ end
11
+
12
+ def test_resource_name_and_with
13
+ mandates = Mandates.new(nil).with("customer-id")
14
+ assert_equal "customers/customer-id/mandates", mandates.resource_name
15
+
16
+ mandates = Mandates.new(nil).with(Object::Customer.new(id: "customer-id"))
17
+ assert_equal "customers/customer-id/mandates", mandates.resource_name
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ module API
5
+ module Resource
6
+ class Customers
7
+ class PaymentsTest < Test::Unit::TestCase
8
+ def test_resource_object
9
+ assert_equal Object::Payment, Payments.new(nil).resource_object
10
+ end
11
+
12
+ def test_resource_name_and_with
13
+ payments = Payments.new(nil).with("customer-id")
14
+ assert_equal "customers/customer-id/payments", payments.resource_name
15
+
16
+ payments = Payments.new(nil).with(Object::Customer.new(id: "customer-id"))
17
+ assert_equal "customers/customer-id/payments", payments.resource_name
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ module API
5
+ module Resource
6
+ class Customers
7
+ class SubscriptionsTest < Test::Unit::TestCase
8
+ def test_resource_object
9
+ assert_equal Object::Subscription, Subscriptions.new(nil).resource_object
10
+ end
11
+
12
+ def test_resource_name_and_with
13
+ subscriptions = Subscriptions.new(nil).with("customer-id")
14
+ assert_equal "customers/customer-id/subscriptions", subscriptions.resource_name
15
+
16
+ subscriptions = Subscriptions.new(nil).with(Object::Customer.new(id: "customer-id"))
17
+ assert_equal "customers/customer-id/subscriptions", subscriptions.resource_name
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ module API
5
+ module Resource
6
+ class CustomersTest < Test::Unit::TestCase
7
+ def test_resource_object
8
+ assert_equal Object::Customer, Customers.new(nil).resource_object
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ module API
5
+ module Resource
6
+ class IssuersTest < Test::Unit::TestCase
7
+ def test_resource_object
8
+ assert_equal Object::Issuer, Issuers.new(nil).resource_object
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'helper'
2
+
3
+ module Mollie
4
+ module API
5
+ module Resource
6
+ class MethodsTest < Test::Unit::TestCase
7
+ def test_resource_object
8
+ assert_equal Object::Method, Methods.new(nil).resource_object
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end