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

Sign up to get free protection for your applications and to get access to all the features.
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
data/lib/mollie/list.rb CHANGED
@@ -2,39 +2,48 @@ module Mollie
2
2
  class List < Base
3
3
  include Enumerable
4
4
 
5
- attr_accessor :total_count,
6
- :offset,
7
- :count,
8
- :links,
9
- :data
5
+ attr_accessor :klass, :items, :_links
6
+ alias_method :links, :_links
10
7
 
11
8
  def initialize(list_attributes, klass)
12
- list_attributes['data'] ||= []
9
+ @klass = klass
10
+
11
+ if list_attributes['_embedded']
12
+ list_attributes['items'] ||= list_attributes['_embedded'].fetch(klass.resource_name, [])
13
+ else
14
+ list_attributes['items'] ||= []
15
+ end
13
16
  super list_attributes
14
17
 
15
- @data = self.data.map do |attributes|
18
+ @items = self.items.map do |attributes|
16
19
  klass.new attributes
17
20
  end
18
21
  end
19
22
 
20
23
  def each(&block)
21
- @data.each(&block)
24
+ @items.each(&block)
22
25
  end
23
26
 
24
- def first_url
25
- links && links['first']
26
- end
27
+ def next(options = {})
28
+ if links['next'].nil?
29
+ return self.class.new({}, klass)
30
+ end
27
31
 
28
- def previous_url
29
- links && links['previous']
30
- end
32
+ href = URI.parse(links['next']['href'])
33
+ query = URI.decode_www_form(href.query).to_h
31
34
 
32
- def next_url
33
- links && links['next']
35
+ klass.all(options.merge(query))
34
36
  end
35
37
 
36
- def last_url
37
- links && links['last']
38
+ def previous(options = {})
39
+ if links['previous'].nil?
40
+ return self.class.new({}, klass)
41
+ end
42
+
43
+ href = URI.parse(links['previous']['href'])
44
+ query = URI.decode_www_form(href.query).to_h
45
+
46
+ klass.all(options.merge(query))
38
47
  end
39
48
  end
40
49
  end
data/lib/mollie/method.rb CHANGED
@@ -1,40 +1,32 @@
1
1
  module Mollie
2
2
  class Method < Base
3
- IDEAL = "ideal"
4
- CREDITCARD = "creditcard"
5
- MISTERCASH = "mistercash"
6
- SOFORT = "sofort"
7
- BANKTRANSFER = "banktransfer"
8
- DIRECTDEBIT = "directdebit"
9
- BITCOIN = "bitcoin"
10
- PAYPAL = "paypal"
11
- KBC = "kbc"
12
- BELFIUS = "belfius"
13
- PAYSAFECARD = "paysafecard"
14
- PODIUMCADEAUKAART = "podiumcadeaukaart"
15
- GIFTCARD = "giftcard"
16
- INGHOMEPAY = "inghomepay"
3
+ BANCONTACT = "bancontact"
4
+ BANKTRANSFER = "banktransfer"
5
+ BELFIUS = "belfius"
6
+ BITCOIN = "bitcoin"
7
+ CREDITCARD = "creditcard"
8
+ DIRECTDEBIT = "directdebit"
9
+ EPS = "eps"
10
+ GIFTCARD = "giftcard"
11
+ GIROPAY = "giropay"
12
+ IDEAL = "ideal"
13
+ INGHOMEPAY = "inghomepay"
14
+ KBC = "kbc"
15
+ PAYPAL = "paypal"
16
+ PAYSAFECARD = "paysafecard"
17
+ SOFORT = "sofort"
17
18
 
18
19
  attr_accessor :id,
19
20
  :description,
20
- :amount,
21
21
  :image,
22
22
  :issuers
23
23
 
24
24
  def normal_image
25
- image['normal']
25
+ image['size1x']
26
26
  end
27
27
 
28
28
  def bigger_image
29
- image['bigger']
30
- end
31
-
32
- def minimum_amount
33
- BigDecimal.new(amount['minimum'].to_s)
34
- end
35
-
36
- def maximum_amount
37
- BigDecimal.new(amount['maximum'].to_s)
29
+ image['size2x']
38
30
  end
39
31
  end
40
32
  end
@@ -4,21 +4,15 @@ module Mollie
4
4
  :name,
5
5
  :email,
6
6
  :address,
7
- :postal_code,
8
- :city,
9
- :country,
10
- :country_code,
11
- :registration_type,
12
7
  :registration_number,
13
- :registration_datetime,
14
- :verified_datetime
8
+ :vat_number
15
9
 
16
- def registration_datetime=(registration_datetime)
17
- @registration_datetime = Time.parse(registration_datetime.to_s) rescue nil
10
+ def self.current(options = {})
11
+ self.get("me", options)
18
12
  end
19
13
 
20
- def verified_datetime=(verified_datetime)
21
- @verified_datetime = Time.parse(verified_datetime.to_s) rescue nil
14
+ def address=(address)
15
+ @address = OpenStruct.new(address) if address.is_a?(Hash)
22
16
  end
23
17
  end
24
18
  end
@@ -1,14 +1,11 @@
1
1
  module Mollie
2
2
  class Payment < Base
3
- STATUS_OPEN = "open"
4
- STATUS_CANCELLED = "cancelled"
5
- STATUS_EXPIRED = "expired"
6
- STATUS_PAID = "paid"
7
- STATUS_PAIDOUT = "paidout"
8
- STATUS_FAILED = "failed"
9
- STATUS_REFUNDED = "refunded"
10
- STATUS_PENDING = "pending"
11
- STATUS_CHARGED_BACK = "charged_back"
3
+ STATUS_OPEN = "open"
4
+ STATUS_CANCELED = "canceled"
5
+ STATUS_PENDING = "pending"
6
+ STATUS_EXPIRED = "expired"
7
+ STATUS_FAILED = "failed"
8
+ STATUS_PAID = "paid"
12
9
 
13
10
  RECURRINGTYPE_NONE = nil
14
11
  RECURRINGTYPE_FIRST = "first"
@@ -16,12 +13,14 @@ module Mollie
16
13
 
17
14
  attr_accessor :id,
18
15
  :mode,
19
- :created_datetime,
16
+ :created_at,
20
17
  :status,
21
- :paid_datetime,
22
- :cancelled_datetime,
23
- :expired_datetime,
24
- :expiry_period,
18
+ :paid_at,
19
+ :is_cancelable,
20
+ :canceled_at,
21
+ :expired_at,
22
+ :expires_at,
23
+ :failed_at,
25
24
  :amount,
26
25
  :amount_refunded,
27
26
  :amount_remaining,
@@ -29,50 +28,54 @@ module Mollie
29
28
  :method,
30
29
  :metadata,
31
30
  :locale,
31
+ :country_code,
32
32
  :profile_id,
33
+ :settlement_amount,
33
34
  :settlement_id,
34
35
  :customer_id,
35
- :recurring_type,
36
+ :sequence_type,
36
37
  :mandate_id,
37
38
  :subscription_id,
38
- :country_code,
39
- :links,
40
- :details
39
+ :application_fee,
40
+ :_links,
41
+ :details,
42
+ :redirect_url,
43
+ :webhook_url
44
+
45
+ alias_method :links, :_links
41
46
 
42
47
  def open?
43
48
  status == STATUS_OPEN
44
49
  end
45
50
 
46
- def cancelled?
47
- status == STATUS_CANCELLED
48
- end
49
-
50
- def expired?
51
- status == STATUS_EXPIRED
51
+ def canceled?
52
+ status == STATUS_CANCELED
52
53
  end
53
54
 
54
- def paid?
55
- !!paid_datetime
56
- end
57
-
58
- def paidout?
59
- status == STATUS_PAIDOUT
55
+ def pending?
56
+ status == STATUS_PENDING
60
57
  end
61
58
 
62
- def refunded?
63
- status == STATUS_REFUNDED
59
+ def expired?
60
+ status == STATUS_EXPIRED
64
61
  end
65
62
 
66
63
  def failed?
67
64
  status == STATUS_FAILED
68
65
  end
69
66
 
70
- def pending?
71
- status == STATUS_PENDING
67
+ def paid?
68
+ status == STATUS_PAID
72
69
  end
73
70
 
74
- def charged_back?
75
- status == STATUS_CHARGED_BACK
71
+ def application_fee=(application_fee)
72
+ amount = Amount.new(application_fee["amount"])
73
+ description = application_fee["description"]
74
+
75
+ @application_fee = OpenStruct.new(
76
+ amount: amount,
77
+ description: description
78
+ )
76
79
  end
77
80
 
78
81
  def details=(details)
@@ -83,60 +86,85 @@ module Mollie
83
86
  @metadata = OpenStruct.new(metadata) if metadata.is_a?(Hash)
84
87
  end
85
88
 
86
- def created_datetime=(created_datetime)
87
- @created_datetime = Time.parse(created_datetime.to_s) rescue nil
89
+ def created_at=(created_at)
90
+ @created_at = Time.parse(created_at.to_s) rescue nil
91
+ end
92
+
93
+ def paid_at=(paid_at)
94
+ @paid_at = Time.parse(paid_at.to_s) rescue nil
88
95
  end
89
96
 
90
- def paid_datetime=(paid_datetime)
91
- @paid_datetime = Time.parse(paid_datetime.to_s) rescue nil
97
+ def canceled_at=(canceled_at)
98
+ @canceled_at = Time.parse(canceled_at.to_s) rescue nil
92
99
  end
93
100
 
94
- def cancelled_datetime=(cancelled_datetime)
95
- @cancelled_datetime = Time.parse(cancelled_datetime.to_s) rescue nil
101
+ def expired_at=(expired_at)
102
+ @expired_at = Time.parse(expired_at.to_s) rescue nil
96
103
  end
97
104
 
98
- def expired_datetime=(expired_datetime)
99
- @expired_datetime = Time.parse(expired_datetime.to_s) rescue nil
105
+ def expires_at=(expires_at)
106
+ @expires_at = Time.parse(expires_at.to_s) rescue nil
107
+ end
108
+
109
+ def failed_at=(failed_at)
110
+ @failed_at = Time.parse(failed_at)
100
111
  end
101
112
 
102
113
  def amount=(amount)
103
- @amount = BigDecimal.new(amount.to_s) if amount
114
+ @amount = Mollie::Amount.new(amount)
115
+ end
116
+
117
+ def settlement_amount=(settlement_amount)
118
+ @settlement_amount = Mollie::Amount.new(settlement_amount)
104
119
  end
105
120
 
106
121
  def amount_remaining=(amount_remaining)
107
- @amount_remaining = BigDecimal.new(amount_remaining.to_s) if amount_remaining
122
+ @amount_remaining = Mollie::Amount.new(amount_remaining)
108
123
  end
109
124
 
110
125
  def amount_refunded=(amount_refunded)
111
- @amount_refunded = BigDecimal.new(amount_refunded.to_s) if amount_refunded
126
+ @amount_refunded = Mollie::Amount.new(amount_refunded)
127
+ end
128
+
129
+ def checkout_url
130
+ Util.extract_url(links, 'checkout')
112
131
  end
113
132
 
114
- def payment_url
115
- links && links['payment_url']
133
+ def refund!(options = {})
134
+ options[:payment_id] = id
135
+ # refund full amount by default
136
+ options[:amount] ||= amount.to_h
137
+ Payment::Refund.create(options)
116
138
  end
117
139
 
118
- def webhook_url
119
- links && links['webhook_url']
140
+ def refunds(options = {})
141
+ Payment::Refund.all(options.merge(payment_id: id))
120
142
  end
121
143
 
122
- def redirect_url
123
- links && links['redirect_url']
144
+ def chargebacks(options = {})
145
+ Payment::Chargeback.all(options.merge(payment_id: id))
124
146
  end
125
147
 
126
- def refunds_url
127
- links && links['refunds']
148
+ def customer(options = {})
149
+ return if customer_id.nil?
150
+ Customer.get(customer_id, options)
128
151
  end
129
152
 
130
- def settlement
131
- links && links['settlement']
153
+ def mandate(options = {})
154
+ return if mandate_id.nil?
155
+ Customer::Mandate.get(mandate_id, options)
132
156
  end
133
157
 
134
- def refunds
135
- Relation.new(self, Payment::Refund)
158
+ def settlement(options = {})
159
+ return if settlement_id.nil?
160
+ Settlement.get(settlement_id, options)
136
161
  end
137
162
 
138
- def chargebacks
139
- Relation.new(self, Payment::Chargeback)
163
+ def subscription(options = {})
164
+ return if customer_id.nil?
165
+ return if subscription_id.nil?
166
+ options = options.merge(customer_id: customer_id)
167
+ Customer::Subscription.get(subscription_id, options)
140
168
  end
141
169
  end
142
170
  end
@@ -20,7 +20,6 @@ module Mollie
20
20
 
21
21
  attr_accessor :id,
22
22
  :description,
23
- :warning,
24
23
  :granted
25
24
  end
26
25
  end
@@ -27,9 +27,10 @@ module Mollie
27
27
  :category_code,
28
28
  :status,
29
29
  :review,
30
- :created_datetime,
31
- :updated_datetime,
32
- :links
30
+ :created_at,
31
+ :_links
32
+
33
+ alias_method :links, :_links
33
34
 
34
35
  def unverified?
35
36
  status == STATUS_UNVERIFIED
@@ -55,24 +56,28 @@ module Mollie
55
56
  @review && @review.status == REVIEW_STATUS_REJECTED
56
57
  end
57
58
 
58
- def created_datetime=(created_datetime)
59
- @created_datetime = Time.parse(created_datetime.to_s) rescue nil
59
+ def created_at=(created_at)
60
+ @created_at = Time.parse(created_at.to_s) rescue nil
60
61
  end
61
62
 
62
- def updated_datetime=(updated_datetime)
63
- @updated_datetime = Time.parse(updated_datetime.to_s) rescue nil
63
+ def checkout_preview_url
64
+ Util.extract_url(links, 'checkout_preview_url')
64
65
  end
65
66
 
66
- def apikeys_url
67
- links && links['apikeys']
67
+ def chargebacks(options = {})
68
+ Chargeback.all(options.merge(profile_id: id))
68
69
  end
69
70
 
70
- def checkout_preview_url
71
- links && links['checkout_preview_url']
71
+ def methods(options = {})
72
+ Method.all(options.merge(profile_id: id))
73
+ end
74
+
75
+ def payments(options = {})
76
+ Payment.all(options.merge(profile_id: id))
72
77
  end
73
78
 
74
- def apikeys
75
- Relation.new(self, Profile::ApiKey)
79
+ def refunds(options = {})
80
+ Refund.all(options.merge(profile_id: id))
76
81
  end
77
82
  end
78
83
  end
data/lib/mollie/refund.rb CHANGED
@@ -4,12 +4,18 @@ module Mollie
4
4
  STATUS_PENDING = "pending"
5
5
  STATUS_PROCESSING = "processing"
6
6
  STATUS_REFUNDED = "refunded"
7
+ STATUS_FAILED = "failed"
7
8
 
8
9
  attr_accessor :id,
9
- :payment,
10
10
  :amount,
11
+ :settlement_amount,
11
12
  :status,
12
- :refunded_datetime
13
+ :payment_id,
14
+ :description,
15
+ :created_at,
16
+ :_links
17
+
18
+ alias_method :links, :_links
13
19
 
14
20
  def queued?
15
21
  status == STATUS_QUEUED
@@ -27,16 +33,30 @@ module Mollie
27
33
  status == STATUS_REFUNDED
28
34
  end
29
35
 
30
- def refunded_datetime=(refunded_datetime)
31
- @refunded_datetime = Time.parse(refunded_datetime) rescue nil
36
+ def failed?
37
+ status == STATUS_FAILED
32
38
  end
33
39
 
34
40
  def amount=(amount)
35
- @amount = BigDecimal.new(amount.to_s) if amount
41
+ @amount = Amount.new(amount)
42
+ end
43
+
44
+ def settlement_amount=(settlement_amount)
45
+ @settlement_amount = Amount.new(settlement_amount)
46
+ end
47
+
48
+ def created_at=(created_at)
49
+ @created_at = Time.parse(created_at) rescue nil
50
+ end
51
+
52
+ def payment(options = {})
53
+ Payment.get(payment_id, options)
36
54
  end
37
55
 
38
- def payment=(payment)
39
- @payment = Payment.new(payment)
56
+ def settlement(options = {})
57
+ settlement_id = Util.extract_id(links, "settlement")
58
+ return if settlement_id.nil?
59
+ Settlement.get(settlement_id, options)
40
60
  end
41
61
  end
42
62
  end