mollie-api-ruby 4.0.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +6 -0
  3. data/examples/captures/get-payment.rb +2 -0
  4. data/examples/captures/get-settlement.rb +2 -0
  5. data/examples/captures/get-shipment.rb +2 -0
  6. data/examples/captures/get.rb +4 -0
  7. data/examples/captures/list.rb +1 -0
  8. data/examples/orders/cancel-lines.rb +2 -0
  9. data/examples/orders/cancel.rb +5 -0
  10. data/examples/orders/create-refund.rb +15 -0
  11. data/examples/orders/create.rb +88 -0
  12. data/examples/orders/get.rb +1 -0
  13. data/examples/orders/list-refunds.rb +1 -0
  14. data/examples/orders/list.rb +1 -0
  15. data/examples/orders/update.rb +15 -0
  16. data/examples/payments/get-order.rb +2 -0
  17. data/examples/refunds/get-order.rb +2 -0
  18. data/examples/shipments/create.rb +17 -0
  19. data/examples/shipments/get-order.rb +2 -0
  20. data/examples/shipments/get.rb +4 -0
  21. data/examples/shipments/list.rb +1 -0
  22. data/examples/shipments/update.rb +9 -0
  23. data/lib/mollie.rb +5 -0
  24. data/lib/mollie/base.rb +2 -0
  25. data/lib/mollie/exception.rb +1 -1
  26. data/lib/mollie/list.rb +8 -0
  27. data/lib/mollie/order.rb +142 -0
  28. data/lib/mollie/order/line.rb +95 -0
  29. data/lib/mollie/order/refund.rb +6 -0
  30. data/lib/mollie/order/shipment.rb +34 -0
  31. data/lib/mollie/payment.rb +17 -6
  32. data/lib/mollie/payment/capture.rb +43 -0
  33. data/lib/mollie/refund.rb +11 -0
  34. data/lib/mollie/version.rb +1 -1
  35. data/test/fixtures/captures/get.json +39 -0
  36. data/test/fixtures/captures/list.json +58 -0
  37. data/test/fixtures/orders/cancel_line.json +8 -0
  38. data/test/fixtures/orders/cancel_line_qty.json +8 -0
  39. data/test/fixtures/orders/create.json +88 -0
  40. data/test/fixtures/orders/create_refund.json +9 -0
  41. data/test/fixtures/orders/get.json +218 -0
  42. data/test/fixtures/orders/list.json +34 -0
  43. data/test/fixtures/orders/list_refunds.json +85 -0
  44. data/test/fixtures/orders/refund.json +63 -0
  45. data/test/fixtures/orders/refund_all.json +3 -0
  46. data/test/fixtures/orders/update.json +14 -0
  47. data/test/fixtures/refunds/get.json +111 -0
  48. data/test/fixtures/shipments/create.json +16 -0
  49. data/test/fixtures/shipments/get.json +101 -0
  50. data/test/fixtures/shipments/list.json +74 -0
  51. data/test/fixtures/shipments/update.json +7 -0
  52. data/test/helper.rb +4 -0
  53. data/test/mollie/list_test.rb +3 -0
  54. data/test/mollie/order/line_test.rb +45 -0
  55. data/test/mollie/order/shipment_test.rb +143 -0
  56. data/test/mollie/order_test.rb +289 -0
  57. data/test/mollie/payment/capture_test.rb +77 -0
  58. data/test/mollie/payment_test.rb +33 -0
  59. data/test/mollie/refund_test.rb +64 -0
  60. metadata +101 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc0a692631f366a82801cfacbddd3a374feb23c4246cad015f5d5d28442bbe6f
4
- data.tar.gz: 13bab05f6eee4826daaf8147e696fc1c5b8fd828a35e3dd56697ef756e97ac77
3
+ metadata.gz: f94d074aceda8fa4e7e541274aa0310d6dd414e80764f57bae3a2eaa604cc3dc
4
+ data.tar.gz: 74c99d214bd5f014134fc667e4aeff19cfec559b3d748dc64bfa7fac1b375fd4
5
5
  SHA512:
6
- metadata.gz: 0eca2506d8f26e6de42661531956513f04292d59f87711ac8b26e584b9fd61d8c905bfaa68da20c96a7b2d08eedf8edfc955f7b9cc4658cbe3e663611f66bfde
7
- data.tar.gz: 2d9c0f92e0349014398dae906afe85cc32ecf32d8a8c2fe739bbbae2d0ad85f8563bdc0b56f357e1f238cf1f0f4424f0d95c5110555d67f3d0b20e3b816b945d
6
+ metadata.gz: 1fc8639da1239db004daa99c723193cf0f56e8c82790267698d61d5597d49d8ec03a7bd338033be98644459d27cb8512810f47eac83ec205d000a34266bc7cbe
7
+ data.tar.gz: 4c13bc4d8756cd9a4c2701b4a04a037865fca7a8458865897f177af16a57ea97a4e883ca9c1096867646b501dbfbb9ecc83052431b7a53535f1dc38111aefee1
@@ -23,6 +23,10 @@ Lint/DuplicateMethods:
23
23
  - 'lib/mollie/customer/mandate.rb'
24
24
  - 'lib/mollie/customer/subscription.rb'
25
25
  - 'lib/mollie/invoice.rb'
26
+ - 'lib/mollie/order.rb'
27
+ - 'lib/mollie/order/line.rb'
28
+ - 'lib/mollie/order/shipment.rb'
29
+ - 'lib/mollie/payment/capture.rb'
26
30
  - 'lib/mollie/organization.rb'
27
31
  - 'lib/mollie/payment.rb'
28
32
  - 'lib/mollie/profile.rb'
@@ -37,6 +41,8 @@ Metrics/AbcSize:
37
41
  # Configuration parameters: CountComments.
38
42
  Metrics/ClassLength:
39
43
  Max: 295
44
+ Exclude:
45
+ - 'test/**/*'
40
46
 
41
47
  # Offense count: 1
42
48
  Metrics/CyclomaticComplexity:
@@ -0,0 +1,2 @@
1
+ capture = Mollie::Payment::Capture.get('cpt_4qqhO89gsT', payment_id: 'tr_WDqYK6vllg')
2
+ payment = capture.payment
@@ -0,0 +1,2 @@
1
+ capture = Mollie::Payment::Capture.get('cpt_4qqhO89gsT', payment_id: 'tr_WDqYK6vllg')
2
+ settlement = capture.settlement
@@ -0,0 +1,2 @@
1
+ capture = Mollie::Payment::Capture.get('cpt_4qqhO89gsT', payment_id: 'tr_WDqYK6vllg')
2
+ shipment = capture.shipment
@@ -0,0 +1,4 @@
1
+ capture = Mollie::Payment::Capture.get(
2
+ 'cpt_4qqhO89gsT',
3
+ payment_id: 'tr_WDqYK6vllg'
4
+ )
@@ -0,0 +1 @@
1
+ capture = Mollie::Payment::Capture.all(payment_id: 'tr_WDqYK6vllg')
@@ -0,0 +1,2 @@
1
+ order = Mollie::Order.get('ord_kEn1PlbGa')
2
+ order.lines[0].cancel
@@ -0,0 +1,5 @@
1
+ Mollie::Order.cancel('ord_kEn1PlbGa')
2
+
3
+ # Cancel an order instance
4
+ order = Mollie::Order.get('ord_kEn1PlbGa')
5
+ order.cancel
@@ -0,0 +1,15 @@
1
+ # Refund all order lines
2
+ order = Mollie::Order.get('ord_kEn1PlbGa')
3
+ refund = order.refund!
4
+
5
+ # Refund a specific order line
6
+ order = Mollie::Order.get('ord_kEn1PlbGa')
7
+ refund = order.refund!(
8
+ lines: [
9
+ {
10
+ id: 'odl_dgtxyl',
11
+ quantity: 1
12
+ }
13
+ ],
14
+ description: 'Required quantity not in stock, refunding one photo book.'
15
+ )
@@ -0,0 +1,88 @@
1
+ order = Mollie::Order.create(
2
+ amount: {
3
+ value: '1027.99',
4
+ currency: 'EUR'
5
+ },
6
+ billingAddress: {
7
+ streetAndNumber: 'Keizersgracht 313',
8
+ city: 'Amsterdam',
9
+ region: 'Noord-Holland',
10
+ postalCode: '1234AB',
11
+ country: 'NL',
12
+ title: 'Dhr',
13
+ givenName: 'Piet',
14
+ familyName: 'Mondriaan',
15
+ email: 'piet@mondriaan.com',
16
+ phone: '+31208202070'
17
+ },
18
+ shippingAddress: {
19
+ streetAndNumber: 'Prinsengracht 313',
20
+ streetAdditional: '4th floor',
21
+ city: 'Haarlem',
22
+ region: 'Noord-Holland',
23
+ postalCode: '5678AB',
24
+ country: 'NL',
25
+ title: 'Mr',
26
+ givenName: 'Chuck',
27
+ familyName: 'Norris',
28
+ email: 'norris@chucknorrisfacts.net'
29
+ },
30
+ metadata: {
31
+ order_id: '1337',
32
+ description: 'Lego cars'
33
+ },
34
+ consumerDateOfBirth: '1958-01-31',
35
+ locale: 'nl_NL',
36
+ orderNumber: '1337',
37
+ redirectUrl: 'https://example.org/redirect',
38
+ webhookUrl: 'https://example.org/webhook',
39
+ method: 'klarnapaylater',
40
+ lines: [
41
+ {
42
+ type: 'physical',
43
+ sku: '5702016116977',
44
+ name: 'LEGO 42083 Bugatti Chiron',
45
+ productUrl: 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083',
46
+ imageUrl: 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$',
47
+ quantity: 2,
48
+ vatRate: '21.00',
49
+ unitPrice: {
50
+ "currency": 'EUR',
51
+ "value": '399.00'
52
+ },
53
+ totalAmount: {
54
+ "currency": 'EUR',
55
+ "value": '698.00'
56
+ },
57
+ discountAmount: {
58
+ "currency": 'EUR',
59
+ "value": '100.00'
60
+ },
61
+ vatAmount: {
62
+ "currency": 'EUR',
63
+ "value": '121.14'
64
+ }
65
+ },
66
+ {
67
+ type: 'physical',
68
+ sku: '5702015594028',
69
+ name: 'LEGO 42056 Porsche 911 GT3 RS',
70
+ productUrl: 'https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056',
71
+ imageUrl: 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$',
72
+ quantity: 1,
73
+ vatRate: '21.00',
74
+ unitPrice: {
75
+ currency: 'EUR',
76
+ value: '329.99'
77
+ },
78
+ totalAmount: {
79
+ currency: 'EUR',
80
+ value: '329.99'
81
+ },
82
+ vatAmount: {
83
+ currency: 'EUR',
84
+ value: '57.27'
85
+ }
86
+ }
87
+ ]
88
+ )
@@ -0,0 +1 @@
1
+ order = Mollie::Order.get('ord_kEn1PlbGa')
@@ -0,0 +1 @@
1
+ refunds = Order::Refund.all(order_id: 'ord_kEn1PlbGa')
@@ -0,0 +1 @@
1
+ orders = Mollie::Order.all
@@ -0,0 +1,15 @@
1
+ order = Mollie::Order.update(
2
+ 'ord_kEn1PlbGa',
3
+ billingAddress: {
4
+ city: 'Amsterdam',
5
+ country: 'NL',
6
+ email: 'piet@mondriaan.com',
7
+ familyName: 'Mondriaan',
8
+ givenName: 'Piet',
9
+ phone: '+31208202070',
10
+ postalCode: '1234AB',
11
+ region: 'Noord-Holland',
12
+ streetAndNumber: 'Keizersgracht 313',
13
+ title: 'Dhr'
14
+ }
15
+ )
@@ -0,0 +1,2 @@
1
+ payment = Mollie::Payment.get('tr_7UhSN1zuXS')
2
+ order = payment.order
@@ -0,0 +1,2 @@
1
+ refund = Mollie::Payment::Refund.get('re_4qqhO89gsT', payment_id: 'tr_WDqYK6vllg')
2
+ order = refund.order
@@ -0,0 +1,17 @@
1
+ shipment = Mollie::Order::Shipment.create(
2
+ order_id: 'ord_kEn1PlbGa',
3
+ lines: [
4
+ {
5
+ id: 'odl_dgtxyl',
6
+ quantity: 1
7
+ },
8
+ {
9
+ id: 'odl_jp31jz'
10
+ }
11
+ ],
12
+ tracking: {
13
+ carrier: 'PostNL',
14
+ code: '3SKABA000000000',
15
+ url: 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C'
16
+ }
17
+ )
@@ -0,0 +1,2 @@
1
+ shipment = Mollie::Order::Shipment.get('shp_3wmsgCJN4U', order_id: 'ord_kEn1PlbGa')
2
+ order = shipment.order
@@ -0,0 +1,4 @@
1
+ shipment = Mollie::Order::Shipment.get(
2
+ 'shp_3wmsgCJN4U',
3
+ order_id: 'ord_kEn1PlbGa'
4
+ )
@@ -0,0 +1 @@
1
+ shipments = Mollie::Order::Shipment.all(order_id: 'ord_kEn1PlbGa')
@@ -0,0 +1,9 @@
1
+ shipment = Mollie::Order::Shipment.update(
2
+ 'shp_3wmsgCJN4U',
3
+ order_id: 'ord_kEn1PlbGa',
4
+ tracking: {
5
+ carrier: 'PostNL',
6
+ code: '3SKABA000000000',
7
+ url: 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C'
8
+ }
9
+ )
@@ -21,6 +21,7 @@ require 'mollie/customer/subscription'
21
21
  require 'mollie/invoice'
22
22
  require 'mollie/list'
23
23
  require 'mollie/method'
24
+ require 'mollie/order'
24
25
  require 'mollie/organization'
25
26
  require 'mollie/payment'
26
27
  require 'mollie/permission'
@@ -29,6 +30,10 @@ require 'mollie/refund'
29
30
  require 'mollie/settlement'
30
31
 
31
32
  require 'mollie/customer/payment'
33
+ require 'mollie/order/line'
34
+ require 'mollie/order/refund'
35
+ require 'mollie/order/shipment'
36
+ require 'mollie/payment/capture'
32
37
  require 'mollie/payment/chargeback'
33
38
  require 'mollie/payment/refund'
34
39
  require 'mollie/settlement/chargeback'
@@ -44,6 +44,7 @@ module Mollie
44
44
  def delete(id, options = {})
45
45
  request('DELETE', id, options)
46
46
  end
47
+ alias cancel delete
47
48
 
48
49
  def request(method, id = 0, data = {}, options = {})
49
50
  parent_id = options.delete(self.parent_id) || data.delete(self.parent_id)
@@ -88,5 +89,6 @@ module Mollie
88
89
  end
89
90
  self.class.delete(id, options)
90
91
  end
92
+ alias cancel delete
91
93
  end
92
94
  end
@@ -2,7 +2,7 @@ module Mollie
2
2
  class Exception < StandardError
3
3
  end
4
4
 
5
- class RequestError < RuntimeError
5
+ class RequestError < Mollie::Exception
6
6
  attr_accessor :status, :title, :detail, :field, :links
7
7
 
8
8
  def initialize(error)
@@ -20,6 +20,14 @@ module Mollie
20
20
  end
21
21
  end
22
22
 
23
+ def [](index)
24
+ @items[index]
25
+ end
26
+
27
+ def size
28
+ @items.size
29
+ end
30
+
23
31
  def each(&block)
24
32
  @items.each(&block)
25
33
  end
@@ -0,0 +1,142 @@
1
+ module Mollie
2
+ class Order < Base
3
+ STATUS_PENDING = 'pending'.freeze
4
+ STATUS_AUTHORIZED = 'authorized'.freeze
5
+ STATUS_PAID = 'paid'.freeze
6
+ STATUS_SHIPPING = 'shipping'.freeze
7
+ STATUS_EXPIRED = 'expired'.freeze
8
+ STATUS_CANCELED = 'canceled'.freeze
9
+ STATUS_COMPLETED = 'completed'.freeze
10
+
11
+ attr_accessor :id,
12
+ :profile_id,
13
+ :method,
14
+ :mode,
15
+ :amount,
16
+ :amount_captured,
17
+ :amount_refunded,
18
+ :status,
19
+ :is_cancelable,
20
+ :billing_address,
21
+ :consumer_date_of_birth,
22
+ :order_number,
23
+ :shipping_address,
24
+ :locale,
25
+ :metadata,
26
+ :redirect_url,
27
+ :webhook_url,
28
+ :created_at,
29
+ :expires_at,
30
+ :expired_at,
31
+ :paid_at,
32
+ :authorized_at,
33
+ :canceled_at,
34
+ :completed_at,
35
+ :lines,
36
+ :_links
37
+
38
+ alias links _links
39
+
40
+ def pending?
41
+ status == STATUS_PENDING
42
+ end
43
+
44
+ def authorized?
45
+ status == STATUS_AUTHORIZED
46
+ end
47
+
48
+ def paid?
49
+ status == STATUS_PAID
50
+ end
51
+
52
+ def shipping?
53
+ status == STATUS_SHIPPING
54
+ end
55
+
56
+ def expired?
57
+ status == STATUS_EXPIRED
58
+ end
59
+
60
+ def canceled?
61
+ status == STATUS_CANCELED
62
+ end
63
+
64
+ def completed?
65
+ status == STATUS_COMPLETED
66
+ end
67
+
68
+ def cancelable?
69
+ is_cancelable
70
+ end
71
+
72
+ def checkout_url
73
+ Util.extract_url(links, 'checkout')
74
+ end
75
+
76
+ def lines=(lines)
77
+ @lines = lines.map { |line| Order::Line.new(line) }
78
+ end
79
+
80
+ def amount=(amount)
81
+ @amount = Mollie::Amount.new(amount)
82
+ end
83
+
84
+ def amount_captured=(amount)
85
+ @amount_captured = Mollie::Amount.new(amount)
86
+ end
87
+
88
+ def amount_refunded=(amount)
89
+ @amount_refunded = Mollie::Amount.new(amount)
90
+ end
91
+
92
+ def billing_address=(address)
93
+ @billing_address = OpenStruct.new(address) if address.is_a?(Hash)
94
+ end
95
+
96
+ def shipping_address=(address)
97
+ @shipping_address = OpenStruct.new(address) if address.is_a?(Hash)
98
+ end
99
+
100
+ def metadata=(metadata)
101
+ @metadata = OpenStruct.new(metadata) if metadata.is_a?(Hash)
102
+ end
103
+
104
+ def created_at=(created_at)
105
+ @created_at = Time.parse(created_at.to_s)
106
+ end
107
+
108
+ def expires_at=(expires_at)
109
+ @expires_at = Time.parse(expires_at.to_s)
110
+ end
111
+
112
+ def expired_at=(expired_at)
113
+ @expired_at = Time.parse(expired_at.to_s)
114
+ end
115
+
116
+ def paid_at=(paid_at)
117
+ @paid_at = Time.parse(paid_at.to_s)
118
+ end
119
+
120
+ def authorized_at=(authorized_at)
121
+ @authorized_at = Time.parse(authorized_at.to_s)
122
+ end
123
+
124
+ def canceled_at=(canceled_at)
125
+ @canceled_at = Time.parse(canceled_at.to_s)
126
+ end
127
+
128
+ def completed_at=(completed_at)
129
+ @completed_at = Time.parse(completed_at.to_s)
130
+ end
131
+
132
+ def refunds(options = {})
133
+ Order::Refund.all(options.merge(order_id: id))
134
+ end
135
+
136
+ def refund!(options = {})
137
+ options[:order_id] = id
138
+ options[:lines] ||= []
139
+ Order::Refund.create(options)
140
+ end
141
+ end
142
+ end