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
@@ -0,0 +1,95 @@
1
+ module Mollie
2
+ class Order
3
+ class Line < Base
4
+ attr_accessor :id,
5
+ :order_id,
6
+ :type,
7
+ :name,
8
+ :status,
9
+ :is_cancelable,
10
+ :quantity,
11
+ :quantity_shipped,
12
+ :amount_shipped,
13
+ :quantity_refunded,
14
+ :amount_refunded,
15
+ :quantity_canceled,
16
+ :amount_canceled,
17
+ :shippable_quantity,
18
+ :refundable_quantity,
19
+ :cancelable_quantity,
20
+ :unit_price,
21
+ :discount_amount,
22
+ :total_amount,
23
+ :vat_rate,
24
+ :vat_amount,
25
+ :sku,
26
+ :created_at,
27
+ :_links
28
+
29
+ alias links _links
30
+
31
+ def cancelable?
32
+ is_cancelable == true
33
+ end
34
+
35
+ def discounted?
36
+ !@discount_amount.nil?
37
+ end
38
+
39
+ def shippable?
40
+ shippable_quantity.to_i > 0
41
+ end
42
+
43
+ def refundable?
44
+ refundable_quantity.to_i > 0
45
+ end
46
+
47
+ def product_url
48
+ Util.extract_url(links, 'product_url')
49
+ end
50
+
51
+ def image_url
52
+ Util.extract_url(links, 'image_url')
53
+ end
54
+
55
+ def amount_shipped=(amount)
56
+ @amount_shipped = Mollie::Amount.new(amount)
57
+ end
58
+
59
+ def amount_refunded=(amount)
60
+ @amount_refunded = Mollie::Amount.new(amount)
61
+ end
62
+
63
+ def amount_canceled=(amount)
64
+ @amount_canceled = Mollie::Amount.new(amount)
65
+ end
66
+
67
+ def unit_price=(amount)
68
+ @unit_price = Mollie::Amount.new(amount)
69
+ end
70
+
71
+ def discount_amount=(amount)
72
+ @discount_amount = Mollie::Amount.new(amount)
73
+ end
74
+
75
+ def total_amount=(amount)
76
+ @total_amount = Mollie::Amount.new(amount)
77
+ end
78
+
79
+ def vat_amount=(amount)
80
+ @vat_amount = Mollie::Amount.new(amount)
81
+ end
82
+
83
+ def created_at=(created_at)
84
+ @created_at = Time.parse(created_at.to_s)
85
+ end
86
+
87
+ def cancel(options = {})
88
+ qty = options.delete(:quantity) || quantity
89
+ options[:lines] = [{ id: id, quantity: qty }]
90
+ options[:order_id] = order_id
91
+ Mollie::Order::Line.delete(nil, options)
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,6 @@
1
+ module Mollie
2
+ class Order
3
+ class Refund < ::Mollie::Refund
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,34 @@
1
+ module Mollie
2
+ class Order
3
+ class Shipment < Base
4
+ attr_accessor :id,
5
+ :order_id,
6
+ :created_at,
7
+ :tracking,
8
+ :lines,
9
+ :_links
10
+
11
+ alias links _links
12
+
13
+ def tracking
14
+ @tracking || OpenStruct.new
15
+ end
16
+
17
+ def tracking=(tracking)
18
+ @tracking = OpenStruct.new(tracking) if tracking.is_a?(Hash)
19
+ end
20
+
21
+ def lines=(lines)
22
+ @lines = lines.map { |line| Order::Line.new(line) }
23
+ end
24
+
25
+ def created_at=(created_at)
26
+ @created_at = Time.parse(created_at.to_s)
27
+ end
28
+
29
+ def order(options = {})
30
+ Order.get(order_id, options)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,11 +1,12 @@
1
1
  module Mollie
2
2
  class Payment < Base
3
- STATUS_OPEN = 'open'.freeze
4
- STATUS_CANCELED = 'canceled'.freeze
5
- STATUS_PENDING = 'pending'.freeze
6
- STATUS_EXPIRED = 'expired'.freeze
7
- STATUS_FAILED = 'failed'.freeze
8
- STATUS_PAID = 'paid'.freeze
3
+ STATUS_OPEN = 'open'.freeze
4
+ STATUS_CANCELED = 'canceled'.freeze
5
+ STATUS_PENDING = 'pending'.freeze
6
+ STATUS_EXPIRED = 'expired'.freeze
7
+ STATUS_FAILED = 'failed'.freeze
8
+ STATUS_PAID = 'paid'.freeze
9
+ STATUS_AUTHORIZED = 'authorized'.freeze
9
10
 
10
11
  RECURRINGTYPE_NONE = nil
11
12
  RECURRINGTYPE_FIRST = 'first'.freeze
@@ -36,6 +37,7 @@ module Mollie
36
37
  :sequence_type,
37
38
  :mandate_id,
38
39
  :subscription_id,
40
+ :order_id,
39
41
  :application_fee,
40
42
  :_links,
41
43
  :details,
@@ -68,6 +70,10 @@ module Mollie
68
70
  status == STATUS_PAID
69
71
  end
70
72
 
73
+ def authorized?
74
+ status == STATUS_AUTHORIZED
75
+ end
76
+
71
77
  def application_fee=(application_fee)
72
78
  amount = Amount.new(application_fee['amount'])
73
79
  description = application_fee['description']
@@ -186,5 +192,10 @@ module Mollie
186
192
  options = options.merge(customer_id: customer_id)
187
193
  Customer::Subscription.get(subscription_id, options)
188
194
  end
195
+
196
+ def order(options = {})
197
+ return if order_id.nil?
198
+ Order.get(order_id, options)
199
+ end
189
200
  end
190
201
  end
@@ -0,0 +1,43 @@
1
+ module Mollie
2
+ class Payment
3
+ class Capture < Base
4
+ attr_accessor :id,
5
+ :mode,
6
+ :amount,
7
+ :settlement_amount,
8
+ :payment_id,
9
+ :shipment_id,
10
+ :settlement_id,
11
+ :created_at,
12
+ :_links
13
+
14
+ alias links _links
15
+
16
+ def amount=(amount)
17
+ @amount = Mollie::Amount.new(amount)
18
+ end
19
+
20
+ def settlement_amount=(amount)
21
+ @settlement_amount = Mollie::Amount.new(amount)
22
+ end
23
+
24
+ def created_at=(created_at)
25
+ @created_at = Time.parse(created_at.to_s)
26
+ end
27
+
28
+ def payment(options = {})
29
+ Payment.get(payment_id, options)
30
+ end
31
+
32
+ def shipment(options = {})
33
+ return if shipment_id.nil?
34
+ Order::Shipment.get(shipment_id, options)
35
+ end
36
+
37
+ def settlement(options = {})
38
+ return if settlement_id.nil?
39
+ Settlement.get(settlement_id, options)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -10,7 +10,9 @@ module Mollie
10
10
  :amount,
11
11
  :settlement_amount,
12
12
  :status,
13
+ :lines,
13
14
  :payment_id,
15
+ :order_id,
14
16
  :description,
15
17
  :created_at,
16
18
  :_links
@@ -45,6 +47,10 @@ module Mollie
45
47
  @settlement_amount = Amount.new(settlement_amount)
46
48
  end
47
49
 
50
+ def lines=(lines)
51
+ @lines = lines.map { |line| Order::Line.new(line) }
52
+ end
53
+
48
54
  def created_at=(created_at)
49
55
  @created_at = begin
50
56
  Time.parse(created_at)
@@ -62,5 +68,10 @@ module Mollie
62
68
  return if settlement_id.nil?
63
69
  Settlement.get(settlement_id, options)
64
70
  end
71
+
72
+ def order(options = {})
73
+ return if order_id.nil?
74
+ Order.get(order_id, options)
75
+ end
65
76
  end
66
77
  end
@@ -1,3 +1,3 @@
1
1
  module Mollie
2
- VERSION = '4.0.1'.freeze
2
+ VERSION = '4.1.0'.freeze
3
3
  end
@@ -0,0 +1,39 @@
1
+ {
2
+ "resource": "capture",
3
+ "id": "cpt_4qqhO89gsT",
4
+ "mode": "live",
5
+ "amount": {
6
+ "value": "1027.99",
7
+ "currency": "EUR"
8
+ },
9
+ "settlementAmount": {
10
+ "value": "399.00",
11
+ "currency": "EUR"
12
+ },
13
+ "paymentId": "tr_WDqYK6vllg",
14
+ "shipmentId": "shp_3wmsgCJN4U",
15
+ "settlementId": "stl_jDk30akdN",
16
+ "createdAt": "2018-08-02T09:29:56+00:00",
17
+ "_links": {
18
+ "self": {
19
+ "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT",
20
+ "type": "application/hal+json"
21
+ },
22
+ "payment": {
23
+ "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg",
24
+ "type": "application/hal+json"
25
+ },
26
+ "shipment": {
27
+ "href": "https://api.mollie.com/v2/orders/ord_8wmqcHMN4U/shipments/shp_3wmsgCJN4U",
28
+ "type": "application/hal+json"
29
+ },
30
+ "settlement": {
31
+ "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN",
32
+ "type": "application/hal+json"
33
+ },
34
+ "documentation": {
35
+ "href": "https://docs.mollie.com/reference/v2/captures-api/get-capture",
36
+ "type": "text/html"
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "_embedded": {
3
+ "captures": [
4
+ {
5
+ "resource": "capture",
6
+ "id": "cpt_4qqhO89gsT",
7
+ "mode": "live",
8
+ "amount": {
9
+ "value": "1027.99",
10
+ "currency": "EUR"
11
+ },
12
+ "settlementAmount": {
13
+ "value": "399.00",
14
+ "currency": "EUR"
15
+ },
16
+ "paymentId": "tr_WDqYK6vllg",
17
+ "shipmentId": "shp_3wmsgCJN4U",
18
+ "settlementId": "stl_jDk30akdN",
19
+ "createdAt": "2018-08-02T09:29:56+00:00",
20
+ "_links": {
21
+ "self": {
22
+ "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT",
23
+ "type": "application/hal+json"
24
+ },
25
+ "payment": {
26
+ "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg",
27
+ "type": "application/hal+json"
28
+ },
29
+ "shipment": {
30
+ "href": "https://api.mollie.com/v2/orders/ord_8wmqcHMN4U/shipments/shp_3wmsgCJN4U",
31
+ "type": "application/hal+json"
32
+ },
33
+ "settlement": {
34
+ "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN",
35
+ "type": "application/hal+json"
36
+ },
37
+ "documentation": {
38
+ "href": "https://docs.mollie.com/reference/v2/captures-api/get-capture",
39
+ "type": "text/html"
40
+ }
41
+ }
42
+ }
43
+ ]
44
+ },
45
+ "count": 1,
46
+ "_links": {
47
+ "documentation": {
48
+ "href": "https://docs.mollie.com/reference/v2/captures-api/list-captures",
49
+ "type": "text/html"
50
+ },
51
+ "self": {
52
+ "href": "https://api.mollie.dev/v2/payments/tr_WDqYK6vllg/captures?limit=50",
53
+ "type": "application/hal+json"
54
+ },
55
+ "previous": null,
56
+ "next": null
57
+ }
58
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "lines": [
3
+ {
4
+ "id": "odl_dgtxyl",
5
+ "quantity": 2
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "lines": [
3
+ {
4
+ "id": "odl_dgtxyl",
5
+ "quantity": 1
6
+ }
7
+ ]
8
+ }
@@ -0,0 +1,88 @@
1
+ {
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
+ }