mollie-api-ruby 1.4.2 → 2.0.0

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 (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
@@ -2,9 +2,7 @@ module Mollie
2
2
  module API
3
3
  module Object
4
4
  class Issuer < Base
5
- attr_accessor :id,
6
- :name,
7
- :method
5
+ attr_accessor :id, :name, :method
8
6
  end
9
7
  end
10
8
  end
@@ -0,0 +1,44 @@
1
+ module Mollie
2
+ module API
3
+ module Object
4
+ class List < Base
5
+ include Enumerable
6
+
7
+ attr_accessor :total_count,
8
+ :offset,
9
+ :count,
10
+ :links,
11
+ :data
12
+
13
+ def initialize(list_attributes, klass)
14
+ list_attributes['data'] ||= []
15
+ super list_attributes
16
+
17
+ @data = self.data.map do |attributes|
18
+ klass.new attributes
19
+ end
20
+ end
21
+
22
+ def each(&block)
23
+ @data.each(&block)
24
+ end
25
+
26
+ def first_url
27
+ links && links['first']
28
+ end
29
+
30
+ def previous_url
31
+ links && links['previous']
32
+ end
33
+
34
+ def next_url
35
+ links && links['next']
36
+ end
37
+
38
+ def last_url
39
+ links && links['last']
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ module Mollie
2
+ module API
3
+ module Object
4
+ class Mandate < Base
5
+ STATUS_VALID = "valid"
6
+ STATUS_INVALID = "invalid"
7
+
8
+ attr_accessor :id,
9
+ :status,
10
+ :method,
11
+ :customer_id,
12
+ :details,
13
+ :created_datetime,
14
+ :mandate_reference
15
+
16
+
17
+ def details=(details)
18
+ @details = OpenStruct.new(details) if details.is_a?(Hash)
19
+ end
20
+
21
+ def created_datetime=(created_datetime)
22
+ @created_datetime = Time.parse(created_datetime.to_s) rescue nil
23
+ end
24
+
25
+ def valid?
26
+ status == STATUS_VALID
27
+ end
28
+
29
+ def invalid?
30
+ status == STATUS_INVALID
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -20,12 +20,20 @@ module Mollie
20
20
  :amount,
21
21
  :image
22
22
 
23
- def getMinimumAmount
24
- @amount.minimum
23
+ def normal_image
24
+ image['normal']
25
25
  end
26
26
 
27
- def getMaximumAmount
28
- @amount.maximum
27
+ def bigger_image
28
+ image['bigger']
29
+ end
30
+
31
+ def minimum_amount
32
+ BigDecimal.new(amount['minimum'].to_s)
33
+ end
34
+
35
+ def maximum_amount
36
+ BigDecimal.new(amount['maximum'].to_s)
29
37
  end
30
38
  end
31
39
  end
@@ -0,0 +1,123 @@
1
+ module Mollie
2
+ module API
3
+ module Object
4
+ class Payment < Base
5
+ STATUS_OPEN = "open"
6
+ STATUS_CANCELLED = "cancelled"
7
+ STATUS_EXPIRED = "expired"
8
+ STATUS_PAID = "paid"
9
+ STATUS_PAIDOUT = "paidout"
10
+ STATUS_FAILED = "failed"
11
+ STATUS_REFUNDED = "refunded"
12
+
13
+ RECURRINGTYPE_NONE = nil
14
+ RECURRINGTYPE_FIRST = "first"
15
+ RECURRINGTYPE_RECURRING = "recurring"
16
+
17
+ attr_accessor :id,
18
+ :mode,
19
+ :created_datetime,
20
+ :status,
21
+ :paid_datetime,
22
+ :cancelled_datetime,
23
+ :expired_datetime,
24
+ :expiry_period,
25
+ :amount,
26
+ :amount_refunded,
27
+ :amount_remaining,
28
+ :description,
29
+ :method,
30
+ :metadata,
31
+ :locale,
32
+ :profile_id,
33
+ :settlement_id,
34
+ :customer_id,
35
+ :recurring_type,
36
+ :mandate_id,
37
+ :subscription_id,
38
+ :links,
39
+ :details
40
+
41
+ def open?
42
+ status == STATUS_OPEN
43
+ end
44
+
45
+ def cancelled?
46
+ status == STATUS_CANCELLED
47
+ end
48
+
49
+ def expired?
50
+ status == STATUS_EXPIRED
51
+ end
52
+
53
+ def paid?
54
+ !!paid_datetime
55
+ end
56
+
57
+ def paidout?
58
+ status == STATUS_PAIDOUT
59
+ end
60
+
61
+ def refunded?
62
+ status == STATUS_REFUNDED
63
+ end
64
+
65
+ def details=(details)
66
+ @details = OpenStruct.new(details) if details.is_a?(Hash)
67
+ end
68
+
69
+ def metadata=(metadata)
70
+ @metadata = OpenStruct.new(metadata) if metadata.is_a?(Hash)
71
+ end
72
+
73
+ def created_datetime=(created_datetime)
74
+ @created_datetime = Time.parse(created_datetime.to_s) rescue nil
75
+ end
76
+
77
+ def paid_datetime=(paid_datetime)
78
+ @paid_datetime = Time.parse(paid_datetime.to_s) rescue nil
79
+ end
80
+
81
+ def cancelled_datetime=(cancelled_datetime)
82
+ @cancelled_datetime = Time.parse(cancelled_datetime.to_s) rescue nil
83
+ end
84
+
85
+ def expired_datetime=(expired_datetime)
86
+ @expired_datetime = Time.parse(expired_datetime.to_s) rescue nil
87
+ end
88
+
89
+ def amount=(amount)
90
+ @amount = BigDecimal.new(amount.to_s) if amount
91
+ end
92
+
93
+ def amount_remaining=(amount_remaining)
94
+ @amount_remaining = BigDecimal.new(amount_remaining.to_s) if amount_remaining
95
+ end
96
+
97
+ def amount_refunded=(amount_refunded)
98
+ @amount_refunded = BigDecimal.new(amount_refunded.to_s) if amount_refunded
99
+ end
100
+
101
+ def payment_url
102
+ links && links['payment_url']
103
+ end
104
+
105
+ def webhook_url
106
+ links && links['webhook_url']
107
+ end
108
+
109
+ def redirect_url
110
+ links && links['redirect_url']
111
+ end
112
+
113
+ def settlement
114
+ links && links['settlement']
115
+ end
116
+
117
+ def refunds
118
+ links && links['refunds']
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,43 @@
1
+ module Mollie
2
+ module API
3
+ module Object
4
+ class Payment
5
+ class Refund < Base
6
+ STATUS_PENDING = "pending"
7
+ STATUS_PROCESSING = "processing"
8
+ STATUS_REFUNDED = "refunded"
9
+
10
+ attr_accessor :id,
11
+ :payment,
12
+ :amount,
13
+ :status,
14
+ :refunded_datetime
15
+
16
+ def pending?
17
+ status == STATUS_PENDING
18
+ end
19
+
20
+ def processing?
21
+ status == STATUS_PROCESSING
22
+ end
23
+
24
+ def refunded?
25
+ status == STATUS_REFUNDED
26
+ end
27
+
28
+ def refunded_datetime=(refunded_datetime)
29
+ @refunded_datetime = Time.parse(refunded_datetime) rescue nil
30
+ end
31
+
32
+ def amount=(amount)
33
+ @amount = BigDecimal.new(amount.to_s) if amount
34
+ end
35
+
36
+ def payment=(payment)
37
+ @payment = Payment.new(payment)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,67 @@
1
+ module Mollie
2
+ module API
3
+ module Object
4
+ class Subscription < Base
5
+ STATUS_ACTIVE = "active"
6
+ STATUS_PENDING = "pending" # Waiting for a valid mandate.
7
+ STATUS_CANCELLED = "cancelled"
8
+ STATUS_SUSPENDED = "suspended" # Active, but mandate became invalid.
9
+ STATUS_COMPLETED = "completed"
10
+
11
+ attr_accessor :resource,
12
+ :id,
13
+ :customer_id,
14
+ :mode,
15
+ :created_datetime,
16
+ :status,
17
+ :amount,
18
+ :times,
19
+ :interval,
20
+ :description,
21
+ :method,
22
+ :cancelled_datetime,
23
+ :links
24
+
25
+ def active?
26
+ status == STATUS_ACTIVE
27
+ end
28
+
29
+ def pending?
30
+ status == STATUS_PENDING
31
+ end
32
+
33
+ def suspended?
34
+ status == STATUS_SUSPENDED
35
+ end
36
+
37
+ def cancelled?
38
+ status == STATUS_CANCELLED
39
+ end
40
+
41
+ def completed?
42
+ status == STATUS_COMPLETED
43
+ end
44
+
45
+ def created_datetime=(created_datetime)
46
+ @created_datetime = Time.parse(created_datetime.to_s) rescue nil
47
+ end
48
+
49
+ def cancelled_datetime=(cancelled_datetime)
50
+ @cancelled_datetime = Time.parse(cancelled_datetime.to_s) rescue nil
51
+ end
52
+
53
+ def amount=(amount)
54
+ @amount = BigDecimal.new(amount.to_s)
55
+ end
56
+
57
+ def times=(times)
58
+ @times = times.to_i
59
+ end
60
+
61
+ def webhook_url
62
+ links && links['webhook_url']
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -6,25 +6,25 @@ module Mollie
6
6
  @client = client
7
7
  end
8
8
 
9
- def getResourceName
9
+ def resource_name
10
10
  self.class.name.downcase.split("::").slice(3..-1).join "/"
11
11
  end
12
12
 
13
13
  def create(data = {})
14
14
  request("POST", nil, data) { |response|
15
- newResourceObject response
15
+ new_resource_object response
16
16
  }
17
17
  end
18
18
 
19
19
  def get(id)
20
20
  request("GET", id, {}) { |response|
21
- newResourceObject response
21
+ new_resource_object response
22
22
  }
23
23
  end
24
24
 
25
25
  def update(id, data = {})
26
26
  request("POST", id, data) { |response|
27
- newResourceObject response
27
+ new_resource_object response
28
28
  }
29
29
  end
30
30
 
@@ -34,16 +34,16 @@ module Mollie
34
34
 
35
35
  def all
36
36
  request("GET", nil, {}) { |response|
37
- Mollie::API::Object::List.new response, getResourceObject
37
+ Object::List.new response, resource_object
38
38
  }
39
39
  end
40
40
 
41
- def newResourceObject(response)
42
- getResourceObject.new response
41
+ def new_resource_object(response)
42
+ resource_object.new response
43
43
  end
44
44
 
45
45
  def request(method, id = 0, data = {})
46
- response = @client.performHttpCall method, getResourceName, id, data
46
+ response = @client.perform_http_call method, resource_name, id, data
47
47
 
48
48
  yield(response) if block_given?
49
49
  end
@@ -2,8 +2,8 @@ module Mollie
2
2
  module API
3
3
  module Resource
4
4
  class Customers < Base
5
- def getResourceObject
6
- Mollie::API::Object::Customer
5
+ def resource_object
6
+ Object::Customer
7
7
  end
8
8
  end
9
9
  end
@@ -7,17 +7,17 @@ module Mollie
7
7
  class Mandates < Base
8
8
  @customer_id = nil
9
9
 
10
- def getResourceObject
11
- Mollie::API::Object::Mandate
10
+ def resource_object
11
+ Object::Mandate
12
12
  end
13
13
 
14
- def getResourceName
14
+ def resource_name
15
15
  customer_id = URI::encode(@customer_id)
16
16
  "customers/#{customer_id}/mandates"
17
17
  end
18
18
 
19
- def with(customer)
20
- @customer_id = customer.id
19
+ def with(customer_or_id)
20
+ @customer_id = customer_or_id.is_a?(Object::Customer) ? customer_or_id.id : customer_or_id
21
21
  self
22
22
  end
23
23
  end
@@ -7,17 +7,17 @@ module Mollie
7
7
  class Payments < Base
8
8
  @customer_id = nil
9
9
 
10
- def getResourceObject
11
- Mollie::API::Object::Payment
10
+ def resource_object
11
+ Object::Payment
12
12
  end
13
13
 
14
- def getResourceName
14
+ def resource_name
15
15
  customer_id = URI::encode(@customer_id)
16
16
  "customers/#{customer_id}/payments"
17
17
  end
18
18
 
19
- def with(customer)
20
- @customer_id = customer.id
19
+ def with(customer_or_id)
20
+ @customer_id = customer_or_id.is_a?(Object::Customer) ? customer_or_id.id : customer_or_id
21
21
  self
22
22
  end
23
23
  end