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.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +6 -0
- data/examples/captures/get-payment.rb +2 -0
- data/examples/captures/get-settlement.rb +2 -0
- data/examples/captures/get-shipment.rb +2 -0
- data/examples/captures/get.rb +4 -0
- data/examples/captures/list.rb +1 -0
- data/examples/orders/cancel-lines.rb +2 -0
- data/examples/orders/cancel.rb +5 -0
- data/examples/orders/create-refund.rb +15 -0
- data/examples/orders/create.rb +88 -0
- data/examples/orders/get.rb +1 -0
- data/examples/orders/list-refunds.rb +1 -0
- data/examples/orders/list.rb +1 -0
- data/examples/orders/update.rb +15 -0
- data/examples/payments/get-order.rb +2 -0
- data/examples/refunds/get-order.rb +2 -0
- data/examples/shipments/create.rb +17 -0
- data/examples/shipments/get-order.rb +2 -0
- data/examples/shipments/get.rb +4 -0
- data/examples/shipments/list.rb +1 -0
- data/examples/shipments/update.rb +9 -0
- data/lib/mollie.rb +5 -0
- data/lib/mollie/base.rb +2 -0
- data/lib/mollie/exception.rb +1 -1
- data/lib/mollie/list.rb +8 -0
- data/lib/mollie/order.rb +142 -0
- data/lib/mollie/order/line.rb +95 -0
- data/lib/mollie/order/refund.rb +6 -0
- data/lib/mollie/order/shipment.rb +34 -0
- data/lib/mollie/payment.rb +17 -6
- data/lib/mollie/payment/capture.rb +43 -0
- data/lib/mollie/refund.rb +11 -0
- data/lib/mollie/version.rb +1 -1
- data/test/fixtures/captures/get.json +39 -0
- data/test/fixtures/captures/list.json +58 -0
- data/test/fixtures/orders/cancel_line.json +8 -0
- data/test/fixtures/orders/cancel_line_qty.json +8 -0
- data/test/fixtures/orders/create.json +88 -0
- data/test/fixtures/orders/create_refund.json +9 -0
- data/test/fixtures/orders/get.json +218 -0
- data/test/fixtures/orders/list.json +34 -0
- data/test/fixtures/orders/list_refunds.json +85 -0
- data/test/fixtures/orders/refund.json +63 -0
- data/test/fixtures/orders/refund_all.json +3 -0
- data/test/fixtures/orders/update.json +14 -0
- data/test/fixtures/refunds/get.json +111 -0
- data/test/fixtures/shipments/create.json +16 -0
- data/test/fixtures/shipments/get.json +101 -0
- data/test/fixtures/shipments/list.json +74 -0
- data/test/fixtures/shipments/update.json +7 -0
- data/test/helper.rb +4 -0
- data/test/mollie/list_test.rb +3 -0
- data/test/mollie/order/line_test.rb +45 -0
- data/test/mollie/order/shipment_test.rb +143 -0
- data/test/mollie/order_test.rb +289 -0
- data/test/mollie/payment/capture_test.rb +77 -0
- data/test/mollie/payment_test.rb +33 -0
- data/test/mollie/refund_test.rb +64 -0
- metadata +101 -34
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"lines": [
|
3
|
+
{
|
4
|
+
"id": "odl_dgtxyl",
|
5
|
+
"quantity": 1
|
6
|
+
},
|
7
|
+
{
|
8
|
+
"id": "odl_jp31jz"
|
9
|
+
}
|
10
|
+
],
|
11
|
+
"tracking": {
|
12
|
+
"carrier": "PostNL",
|
13
|
+
"code": "3SKABA000000000",
|
14
|
+
"url": "http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C"
|
15
|
+
}
|
16
|
+
}
|
@@ -0,0 +1,101 @@
|
|
1
|
+
{
|
2
|
+
"resource": "shipment",
|
3
|
+
"id": "shp_3wmsgCJN4U",
|
4
|
+
"orderId": "ord_kEn1PlbGa",
|
5
|
+
"createdAt": "2018-08-09T14:33:54+00:00",
|
6
|
+
"tracking": {
|
7
|
+
"carrier": "PostNL",
|
8
|
+
"code": "3SKABA000000000",
|
9
|
+
"url": "http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C"
|
10
|
+
},
|
11
|
+
"lines": [
|
12
|
+
{
|
13
|
+
"resource": "orderline",
|
14
|
+
"id": "odl_dgtxyl",
|
15
|
+
"orderId": "ord_kEn1PlbGa",
|
16
|
+
"name": "LEGO 42083 Bugatti Chiron",
|
17
|
+
"sku": "5702016116977",
|
18
|
+
"type": "physical",
|
19
|
+
"status": "shipping",
|
20
|
+
"isCancelable": true,
|
21
|
+
"quantity": 2,
|
22
|
+
"unitPrice": {
|
23
|
+
"value": "399.00",
|
24
|
+
"currency": "EUR"
|
25
|
+
},
|
26
|
+
"vatRate": "21.00",
|
27
|
+
"vatAmount": {
|
28
|
+
"value": "121.14",
|
29
|
+
"currency": "EUR"
|
30
|
+
},
|
31
|
+
"totalAmount": {
|
32
|
+
"value": "698.00",
|
33
|
+
"currency": "EUR"
|
34
|
+
},
|
35
|
+
"createdAt": "2018-09-23T17:23:13+00:00",
|
36
|
+
"discountAmount": {
|
37
|
+
"value": "100.00",
|
38
|
+
"currency": "EUR"
|
39
|
+
},
|
40
|
+
"_links": {
|
41
|
+
"productUrl": {
|
42
|
+
"href": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083",
|
43
|
+
"type": "text/html"
|
44
|
+
},
|
45
|
+
"imageUrl": {
|
46
|
+
"href": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$",
|
47
|
+
"type": "text/html"
|
48
|
+
}
|
49
|
+
}
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"resource": "orderline",
|
53
|
+
"id": "odl_j3eusr",
|
54
|
+
"orderId": "ord_kEn1PlbGa",
|
55
|
+
"name": "LEGO 42056 Porsche 911 GT3 RS",
|
56
|
+
"sku": "5702015594028",
|
57
|
+
"type": "physical",
|
58
|
+
"status": "shipping",
|
59
|
+
"isCancelable": true,
|
60
|
+
"quantity": 1,
|
61
|
+
"unitPrice": {
|
62
|
+
"value": "329.99",
|
63
|
+
"currency": "EUR"
|
64
|
+
},
|
65
|
+
"vatRate": "21.00",
|
66
|
+
"vatAmount": {
|
67
|
+
"value": "57.27",
|
68
|
+
"currency": "EUR"
|
69
|
+
},
|
70
|
+
"totalAmount": {
|
71
|
+
"value": "329.99",
|
72
|
+
"currency": "EUR"
|
73
|
+
},
|
74
|
+
"createdAt": "2018-09-23T17:23:13+00:00",
|
75
|
+
"_links": {
|
76
|
+
"productUrl": {
|
77
|
+
"href": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056",
|
78
|
+
"type": "text/html"
|
79
|
+
},
|
80
|
+
"imageUrl": {
|
81
|
+
"href": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$",
|
82
|
+
"type": "text/html"
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
],
|
87
|
+
"_links": {
|
88
|
+
"self": {
|
89
|
+
"href": "https://api.mollie.com/v2/shipments/shp_bjylrn",
|
90
|
+
"type": "application/hal+json"
|
91
|
+
},
|
92
|
+
"order": {
|
93
|
+
"href": "https://api.mollie.com/v2/orders/ord_kEn1PlbGa",
|
94
|
+
"type": "application/hal+json"
|
95
|
+
},
|
96
|
+
"documentation": {
|
97
|
+
"href": "https://docs.mollie.com/reference/v2/shipments-api/get-shipment",
|
98
|
+
"type": "text/html"
|
99
|
+
}
|
100
|
+
}
|
101
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
{
|
2
|
+
"count": 1,
|
3
|
+
"_embedded": {
|
4
|
+
"shipments": [
|
5
|
+
{
|
6
|
+
"resource": "shipment",
|
7
|
+
"id": "shp_3wmsgCJN4U",
|
8
|
+
"orderId": "ord_kEn1PlbGa",
|
9
|
+
"createdAt": "2018-08-09T14:33:54+00:00",
|
10
|
+
"tracking": {
|
11
|
+
"carrier": "PostNL",
|
12
|
+
"code": "3SKABA000000000",
|
13
|
+
"url": "http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C"
|
14
|
+
},
|
15
|
+
"lines": [
|
16
|
+
{
|
17
|
+
"resource": "orderline",
|
18
|
+
"id": "odl_dgtxyl",
|
19
|
+
"orderId": "ord_pbjz8x",
|
20
|
+
"name": "LEGO 42083 Bugatti Chiron",
|
21
|
+
"productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083",
|
22
|
+
"imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$",
|
23
|
+
"sku": "5702016116977",
|
24
|
+
"type": "physical",
|
25
|
+
"status": "shipping",
|
26
|
+
"quantity": 2,
|
27
|
+
"unitPrice": {
|
28
|
+
"value": "399.00",
|
29
|
+
"currency": "EUR"
|
30
|
+
},
|
31
|
+
"vatRate": "21.00",
|
32
|
+
"vatAmount": {
|
33
|
+
"value": "121.14",
|
34
|
+
"currency": "EUR"
|
35
|
+
},
|
36
|
+
"discountAmount": {
|
37
|
+
"value": "100.00",
|
38
|
+
"currency": "EUR"
|
39
|
+
},
|
40
|
+
"totalAmount": {
|
41
|
+
"value": "698.00",
|
42
|
+
"currency": "EUR"
|
43
|
+
},
|
44
|
+
"createdAt": "2018-08-02T09:29:56+00:00"
|
45
|
+
}
|
46
|
+
],
|
47
|
+
"_links": {
|
48
|
+
"self": {
|
49
|
+
"href": "https://api.mollie.com/v2/order/ord_kEn1PlbGa/shipments/shp_3wmsgCJN4U",
|
50
|
+
"type": "application/hal+json"
|
51
|
+
},
|
52
|
+
"order": {
|
53
|
+
"href": "https://api.mollie.com/v2/orders/ord_kEn1PlbGa",
|
54
|
+
"type": "application/hal+json"
|
55
|
+
},
|
56
|
+
"documentation": {
|
57
|
+
"href": "https://docs.mollie.com/reference/v2/shipments-api/get-shipment",
|
58
|
+
"type": "text/html"
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
]
|
63
|
+
},
|
64
|
+
"_links": {
|
65
|
+
"self": {
|
66
|
+
"href": "https://api.mollie.com/v2/order/ord_kEn1PlbGa/shipments",
|
67
|
+
"type": "application/hal+json"
|
68
|
+
},
|
69
|
+
"documentation": {
|
70
|
+
"href": "https://docs.mollie.com/reference/v2/shipments-api/list-shipments",
|
71
|
+
"type": "text/html"
|
72
|
+
}
|
73
|
+
}
|
74
|
+
}
|
data/test/helper.rb
CHANGED
data/test/mollie/list_test.rb
CHANGED
@@ -32,11 +32,14 @@ module Mollie
|
|
32
32
|
list = Mollie::List.new(attributes, Payment)
|
33
33
|
|
34
34
|
assert_equal 2, list.count
|
35
|
+
assert_equal 2, list.size
|
35
36
|
assert_kind_of Payment, list.to_a[0]
|
36
37
|
assert_equal 'tr_1', list.to_a[0].id
|
38
|
+
assert_equal 'tr_1', list[0].id
|
37
39
|
|
38
40
|
assert_kind_of Payment, list.to_a[1]
|
39
41
|
assert_equal 'tr_2', list.to_a[1].id
|
42
|
+
assert_equal 'tr_2', list[1].id
|
40
43
|
end
|
41
44
|
|
42
45
|
def test_next_page
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
class Order
|
5
|
+
class LineTest < Test::Unit::TestCase
|
6
|
+
GET_ORDER = read_fixture('orders/get.json')
|
7
|
+
CANCEL_LINE = read_fixture('orders/cancel_line.json')
|
8
|
+
CANCEL_QTY = read_fixture('orders/cancel_line_qty.json')
|
9
|
+
|
10
|
+
def test_discounted
|
11
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
12
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
13
|
+
|
14
|
+
order = Order.get('ord_kEn1PlbGa')
|
15
|
+
assert order.lines[0].discounted?
|
16
|
+
assert order.lines[1].discounted? == false
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_cancel_order_line
|
20
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
21
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
22
|
+
|
23
|
+
stub_request(:delete, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/lines')
|
24
|
+
.with(body: JSON.parse(CANCEL_LINE).to_json)
|
25
|
+
.to_return(status: 204, body: GET_ORDER, headers: {})
|
26
|
+
|
27
|
+
order = Order.get('ord_kEn1PlbGa')
|
28
|
+
assert_nil order.lines.first.cancel
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_cancel_order_line_with_quantity
|
32
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
33
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
34
|
+
|
35
|
+
stub_request(:delete, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/lines')
|
36
|
+
.with(body: JSON.parse(CANCEL_QTY).to_json)
|
37
|
+
.to_return(status: 204, body: GET_ORDER, headers: {})
|
38
|
+
|
39
|
+
order = Order.get('ord_kEn1PlbGa')
|
40
|
+
assert_nil order.lines.first.cancel(quantity: 1)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
class Order
|
5
|
+
class ShipmentTest < Test::Unit::TestCase
|
6
|
+
GET_ORDER = read_fixture('orders/get.json')
|
7
|
+
GET_SHIPMENT = read_fixture('shipments/get.json')
|
8
|
+
CREATE_SHIPMENT = read_fixture('shipments/create.json')
|
9
|
+
LIST_SHIPMENTS = read_fixture('shipments/list.json')
|
10
|
+
UPDATE_SHIPMENT = read_fixture('shipments/update.json')
|
11
|
+
|
12
|
+
def test_get_shipment
|
13
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/shipments/shp_3wmsgCJN4U')
|
14
|
+
.to_return(status: 200, body: GET_SHIPMENT, headers: {})
|
15
|
+
|
16
|
+
shipment = Order::Shipment.get('shp_3wmsgCJN4U', order_id: 'ord_kEn1PlbGa')
|
17
|
+
assert_equal 'shp_3wmsgCJN4U', shipment.id
|
18
|
+
assert_equal 'ord_kEn1PlbGa', shipment.order_id
|
19
|
+
assert_equal Time.parse('2018-08-09T14:33:54+00:00'), shipment.created_at
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_tracking_details
|
23
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/shipments/shp_3wmsgCJN4U')
|
24
|
+
.to_return(status: 200, body: GET_SHIPMENT, headers: {})
|
25
|
+
|
26
|
+
shipment = Order::Shipment.get('shp_3wmsgCJN4U', order_id: 'ord_kEn1PlbGa')
|
27
|
+
assert_equal 'shp_3wmsgCJN4U', shipment.id
|
28
|
+
assert_equal 'PostNL', shipment.tracking.carrier
|
29
|
+
assert_equal '3SKABA000000000', shipment.tracking.code
|
30
|
+
assert_equal 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C', shipment.tracking.url
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_nil_tracking_details
|
34
|
+
body = %({ "resource": "shipment", "id": "shp_3wmsgCJN4U" })
|
35
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/shipments/shp_3wmsgCJN4U')
|
36
|
+
.to_return(status: 200, body: body, headers: {})
|
37
|
+
|
38
|
+
shipment = Order::Shipment.get('shp_3wmsgCJN4U', order_id: 'ord_kEn1PlbGa')
|
39
|
+
assert_equal 'shp_3wmsgCJN4U', shipment.id
|
40
|
+
assert_nil shipment.tracking.carrier
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_order_lines
|
44
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/shipments/shp_3wmsgCJN4U')
|
45
|
+
.to_return(status: 200, body: GET_SHIPMENT, headers: {})
|
46
|
+
|
47
|
+
shipment = Order::Shipment.get('shp_3wmsgCJN4U', order_id: 'ord_kEn1PlbGa')
|
48
|
+
assert shipment.lines.size == 2
|
49
|
+
|
50
|
+
line = shipment.lines.first
|
51
|
+
assert_equal 'odl_dgtxyl', line.id
|
52
|
+
assert_equal 'ord_kEn1PlbGa', line.order_id
|
53
|
+
assert_equal 'LEGO 42083 Bugatti Chiron', line.name
|
54
|
+
assert_equal 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', line.product_url
|
55
|
+
assert_equal 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', line.image_url
|
56
|
+
assert_equal '5702016116977', line.sku
|
57
|
+
assert_equal 'physical', line.type
|
58
|
+
assert_equal 'shipping', line.status
|
59
|
+
assert_equal true, line.is_cancelable
|
60
|
+
assert_equal true, line.cancelable?
|
61
|
+
assert_equal 2, line.quantity
|
62
|
+
assert_equal BigDecimal('399.00'), line.unit_price.value
|
63
|
+
assert_equal 'EUR', line.unit_price.currency
|
64
|
+
assert_equal '21.00', line.vat_rate
|
65
|
+
assert_equal BigDecimal('121.14'), line.vat_amount.value
|
66
|
+
assert_equal 'EUR', line.vat_amount.currency
|
67
|
+
assert_equal BigDecimal('100.00'), line.discount_amount.value
|
68
|
+
assert_equal 'EUR', line.discount_amount.currency
|
69
|
+
assert_equal BigDecimal('698.00'), line.total_amount.value
|
70
|
+
assert_equal 'EUR', line.total_amount.currency
|
71
|
+
assert_equal Time.parse('2018-09-23T17:23:13+00:00'), line.created_at
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_create_shipment
|
75
|
+
stub_request(:post, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/shipments')
|
76
|
+
.with(body: CREATE_SHIPMENT.delete("\n "))
|
77
|
+
.to_return(status: 201, body: GET_SHIPMENT, headers: {})
|
78
|
+
|
79
|
+
shipment = Order::Shipment.create(
|
80
|
+
order_id: 'ord_kEn1PlbGa',
|
81
|
+
lines: [
|
82
|
+
{
|
83
|
+
id: 'odl_dgtxyl',
|
84
|
+
quantity: 1
|
85
|
+
},
|
86
|
+
{
|
87
|
+
id: 'odl_jp31jz'
|
88
|
+
}
|
89
|
+
],
|
90
|
+
tracking: {
|
91
|
+
carrier: 'PostNL',
|
92
|
+
code: '3SKABA000000000',
|
93
|
+
url: 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C'
|
94
|
+
}
|
95
|
+
)
|
96
|
+
|
97
|
+
assert_kind_of Order::Shipment, shipment
|
98
|
+
assert_equal 'shp_3wmsgCJN4U', shipment.id
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_list_shipments
|
102
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/shipments')
|
103
|
+
.to_return(status: 200, body: LIST_SHIPMENTS, headers: {})
|
104
|
+
|
105
|
+
shipments = Order::Shipment.all(order_id: 'ord_kEn1PlbGa')
|
106
|
+
assert_equal 1, shipments.size
|
107
|
+
assert_equal 'shp_3wmsgCJN4U', shipments.first.id
|
108
|
+
assert_equal 'ord_kEn1PlbGa', shipments.first.order_id
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_update_shipment
|
112
|
+
stub_request(:patch, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/shipments/shp_3wmsgCJN4U')
|
113
|
+
.with(body: UPDATE_SHIPMENT.delete("\n "))
|
114
|
+
.to_return(status: 200, body: GET_SHIPMENT, headers: {})
|
115
|
+
|
116
|
+
shipment = Order::Shipment.update(
|
117
|
+
'shp_3wmsgCJN4U',
|
118
|
+
order_id: 'ord_kEn1PlbGa',
|
119
|
+
tracking: {
|
120
|
+
carrier: 'PostNL',
|
121
|
+
code: '3SKABA000000000',
|
122
|
+
url: 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C'
|
123
|
+
}
|
124
|
+
)
|
125
|
+
|
126
|
+
assert_kind_of Order::Shipment, shipment
|
127
|
+
assert_equal 'shp_3wmsgCJN4U', shipment.id
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_get_order
|
131
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/shipments/shp_3wmsgCJN4U')
|
132
|
+
.to_return(status: 200, body: GET_SHIPMENT, headers: {})
|
133
|
+
|
134
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
135
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
136
|
+
|
137
|
+
shipment = Order::Shipment.get('shp_3wmsgCJN4U', order_id: 'ord_kEn1PlbGa')
|
138
|
+
order = shipment.order
|
139
|
+
assert_equal 'ord_kEn1PlbGa', order.id
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,289 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
class OrderTest < Test::Unit::TestCase
|
5
|
+
CREATE_ORDER = read_fixture('orders/create.json')
|
6
|
+
GET_ORDER = read_fixture('orders/get.json')
|
7
|
+
UPDATE_ORDER = read_fixture('orders/update.json')
|
8
|
+
LIST_ORDER = read_fixture('orders/list.json')
|
9
|
+
|
10
|
+
# Refunds
|
11
|
+
CREATE_ORDER_REFUND = read_fixture('orders/create_refund.json')
|
12
|
+
REFUND_ALL_LINES = read_fixture('orders/refund_all.json')
|
13
|
+
LIST_ORDER_REFUNDS = read_fixture('orders/list_refunds.json')
|
14
|
+
GET_ORDER_REFUND = read_fixture('orders/refund.json')
|
15
|
+
|
16
|
+
def test_status_pending
|
17
|
+
assert Order.new(status: Order::STATUS_PENDING).pending?
|
18
|
+
assert !Order.new(status: 'not-pending').pending?
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_status_authorized
|
22
|
+
assert Order.new(status: Order::STATUS_AUTHORIZED).authorized?
|
23
|
+
assert !Order.new(status: 'not-authorized').authorized?
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_status_paid
|
27
|
+
assert Order.new(status: Order::STATUS_PAID).paid?
|
28
|
+
assert !Order.new(status: 'not-paid').paid?
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_status_shipping
|
32
|
+
assert Order.new(status: Order::STATUS_SHIPPING).shipping?
|
33
|
+
assert !Order.new(status: 'not-shipping').shipping?
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_status_expired
|
37
|
+
assert Order.new(status: Order::STATUS_EXPIRED).expired?
|
38
|
+
assert !Order.new(status: 'not-expired').expired?
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_status_canceled
|
42
|
+
assert Order.new(status: Order::STATUS_CANCELED).canceled?
|
43
|
+
assert !Order.new(status: 'not-canceled').canceled?
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_status_completed
|
47
|
+
assert Order.new(status: Order::STATUS_COMPLETED).completed?
|
48
|
+
assert !Order.new(status: 'not-completed').completed?
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_get_order
|
52
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
53
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
54
|
+
|
55
|
+
order = Order.get('ord_kEn1PlbGa')
|
56
|
+
assert_equal 'ord_kEn1PlbGa', order.id
|
57
|
+
assert_equal 'pfl_URR55HPMGx', order.profile_id
|
58
|
+
assert_equal 'ideal', order.method
|
59
|
+
assert_equal 'live', order.mode
|
60
|
+
assert_equal BigDecimal('1027.99'), order.amount.value
|
61
|
+
assert_equal 'EUR', order.amount.currency
|
62
|
+
assert_equal BigDecimal('1002.99'), order.amount_captured.value
|
63
|
+
assert_equal 'EUR', order.amount_captured.currency
|
64
|
+
assert_equal BigDecimal('25.0'), order.amount_refunded.value
|
65
|
+
assert_equal 'EUR', order.amount_refunded.currency
|
66
|
+
assert_equal 'created', order.status
|
67
|
+
assert_equal true, order.is_cancelable
|
68
|
+
assert_equal '18475', order.order_number
|
69
|
+
assert_equal 'nl_NL', order.locale
|
70
|
+
assert_equal '1337', order.metadata.order_id
|
71
|
+
assert_equal 'Lego cars', order.metadata.description
|
72
|
+
assert_equal 'https://example.org/redirect', order.redirect_url
|
73
|
+
assert_equal 'https://example.org/webhook', order.webhook_url
|
74
|
+
assert_equal Time.parse('2018-08-02T09:29:56+00:00'), order.created_at
|
75
|
+
assert_equal Time.parse('2018-08-30T09:29:56+00:00'), order.expires_at
|
76
|
+
assert_equal Time.parse('2018-08-30T09:29:56+00:02'), order.expired_at
|
77
|
+
assert_equal Time.parse('2018-08-26T09:29:56+00:00'), order.paid_at
|
78
|
+
assert_equal Time.parse('2018-08-25T09:29:56+00:00'), order.authorized_at
|
79
|
+
assert_equal Time.parse('2018-08-27T09:29:56+00:00'), order.canceled_at
|
80
|
+
assert_equal Time.parse('2018-08-28T09:29:56+00:00'), order.completed_at
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_cancelable?
|
84
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
85
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
86
|
+
|
87
|
+
order = Order.get('ord_kEn1PlbGa')
|
88
|
+
assert_equal true, order.is_cancelable
|
89
|
+
assert_equal true, order.cancelable?
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_checkout_url
|
93
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
94
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
95
|
+
|
96
|
+
order = Order.get('ord_kEn1PlbGa')
|
97
|
+
assert_equal 'https://www.mollie.com/payscreen/order/checkout/kEn1PlbGa', order.checkout_url
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_billing_address
|
101
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
102
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
103
|
+
|
104
|
+
order = Order.get('ord_kEn1PlbGa')
|
105
|
+
assert_equal 'Keizersgracht 313', order.billing_address.street_and_number
|
106
|
+
assert_equal '1016 EE', order.billing_address.postal_code
|
107
|
+
assert_equal 'Amsterdam', order.billing_address.city
|
108
|
+
assert_equal 'nl', order.billing_address.country
|
109
|
+
assert_equal 'Luke', order.billing_address.given_name
|
110
|
+
assert_equal 'Skywalker', order.billing_address.family_name
|
111
|
+
assert_equal 'luke@skywalker.com', order.billing_address.email
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_shipping_address
|
115
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
116
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
117
|
+
|
118
|
+
order = Order.get('ord_kEn1PlbGa')
|
119
|
+
assert_equal 'Keizersgracht 313', order.shipping_address.street_and_number
|
120
|
+
assert_equal '1016 EE', order.shipping_address.postal_code
|
121
|
+
assert_equal 'Amsterdam', order.shipping_address.city
|
122
|
+
assert_equal 'nl', order.shipping_address.country
|
123
|
+
assert_equal 'Luke', order.shipping_address.given_name
|
124
|
+
assert_equal 'Skywalker', order.shipping_address.family_name
|
125
|
+
assert_equal 'luke@skywalker.com', order.shipping_address.email
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_order_lines
|
129
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
130
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
131
|
+
|
132
|
+
order = Order.get('ord_kEn1PlbGa')
|
133
|
+
line = order.lines.first
|
134
|
+
assert order.lines.size == 2
|
135
|
+
|
136
|
+
assert_equal 'odl_dgtxyl', line.id
|
137
|
+
assert_equal 'ord_kEn1PlbGa', line.order_id
|
138
|
+
assert_equal 'LEGO 42083 Bugatti Chiron', line.name
|
139
|
+
assert_equal 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', line.product_url
|
140
|
+
assert_equal 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', line.image_url
|
141
|
+
assert_equal '5702016116977', line.sku
|
142
|
+
assert_equal 'physical', line.type
|
143
|
+
assert_equal 'created', line.status
|
144
|
+
assert_equal true, line.is_cancelable
|
145
|
+
assert_equal true, line.cancelable?
|
146
|
+
assert_equal 2, line.quantity
|
147
|
+
assert_equal 0, line.quantity_shipped
|
148
|
+
assert_equal 0, line.quantity_refunded
|
149
|
+
assert_equal 0, line.quantity_canceled
|
150
|
+
assert_equal '21.00', line.vat_rate
|
151
|
+
|
152
|
+
assert_equal BigDecimal('0'), line.amount_shipped.value
|
153
|
+
assert_equal 'EUR', line.amount_shipped.currency
|
154
|
+
|
155
|
+
assert_equal BigDecimal('0'), line.amount_refunded.value
|
156
|
+
assert_equal 'EUR', line.amount_refunded.currency
|
157
|
+
|
158
|
+
assert_equal BigDecimal('0'), line.amount_canceled.value
|
159
|
+
assert_equal 'EUR', line.amount_canceled.currency
|
160
|
+
|
161
|
+
assert_equal BigDecimal('399.0'), line.unit_price.value
|
162
|
+
assert_equal 'EUR', line.unit_price.currency
|
163
|
+
|
164
|
+
assert_equal 0, line.shippable_quantity
|
165
|
+
assert_equal 0, line.refundable_quantity
|
166
|
+
assert_equal 2, line.cancelable_quantity
|
167
|
+
assert_equal false, line.shippable?
|
168
|
+
assert_equal false, line.refundable?
|
169
|
+
assert_equal true, line.cancelable?
|
170
|
+
|
171
|
+
assert_equal BigDecimal('100.0'), line.discount_amount.value
|
172
|
+
assert_equal 'EUR', line.discount_amount.currency
|
173
|
+
|
174
|
+
assert_equal BigDecimal('698.0'), line.total_amount.value
|
175
|
+
assert_equal 'EUR', line.total_amount.currency
|
176
|
+
|
177
|
+
assert_equal BigDecimal('121.14'), line.vat_amount.value
|
178
|
+
assert_equal 'EUR', line.vat_amount.currency
|
179
|
+
|
180
|
+
assert_equal Time.parse('2018-08-02T09:29:56+00:00'), line.created_at
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_create_order
|
184
|
+
minified_body = JSON.parse(CREATE_ORDER).to_json
|
185
|
+
stub_request(:post, 'https://api.mollie.com/v2/orders')
|
186
|
+
.with(body: minified_body)
|
187
|
+
.to_return(status: 201, body: GET_ORDER, headers: {})
|
188
|
+
|
189
|
+
order = Order.create(JSON.parse(CREATE_ORDER))
|
190
|
+
|
191
|
+
assert_kind_of Order, order
|
192
|
+
assert_equal 'ord_kEn1PlbGa', order.id
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_update_order
|
196
|
+
minified_body = JSON.parse(UPDATE_ORDER).to_json
|
197
|
+
stub_request(:patch, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
198
|
+
.with(body: minified_body)
|
199
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
200
|
+
|
201
|
+
order = Order.update('ord_kEn1PlbGa', JSON.parse(UPDATE_ORDER))
|
202
|
+
|
203
|
+
assert_kind_of Order, order
|
204
|
+
assert_equal 'ord_kEn1PlbGa', order.id
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_cancel_order
|
208
|
+
stub_request(:delete, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
209
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
210
|
+
|
211
|
+
order = Order.cancel('ord_kEn1PlbGa')
|
212
|
+
assert_nil order
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_cancel_order_instance
|
216
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
217
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
218
|
+
|
219
|
+
stub_request(:delete, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
220
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
221
|
+
|
222
|
+
order = Order.get('ord_kEn1PlbGa')
|
223
|
+
assert_nil order.cancel
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_list_orders
|
227
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders')
|
228
|
+
.to_return(status: 200, body: LIST_ORDER, headers: {})
|
229
|
+
|
230
|
+
orders = Order.all
|
231
|
+
assert_equal 3, orders.size
|
232
|
+
assert_equal 'ord_one', orders[0].id
|
233
|
+
assert_equal 'ord_two', orders[1].id
|
234
|
+
assert_equal 'ord_three', orders[2].id
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_create_order_refund
|
238
|
+
request_body = JSON.parse(CREATE_ORDER_REFUND, symbolize_names: true)
|
239
|
+
|
240
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
241
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
242
|
+
|
243
|
+
stub_request(:post, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/refunds')
|
244
|
+
.with(body: request_body.to_json)
|
245
|
+
.to_return(status: 201, body: GET_ORDER_REFUND, headers: {})
|
246
|
+
|
247
|
+
order = Order.get('ord_kEn1PlbGa')
|
248
|
+
refund = order.refund!(request_body)
|
249
|
+
|
250
|
+
assert_kind_of Order::Refund, refund
|
251
|
+
assert_equal 're_4qqhO89gsT', refund.id
|
252
|
+
assert_equal 'ord_kEn1PlbGa', refund.order_id
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_refund_all_lines
|
256
|
+
request_body = JSON.parse(REFUND_ALL_LINES, symbolize_names: true)
|
257
|
+
|
258
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
259
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
260
|
+
|
261
|
+
stub_request(:post, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/refunds')
|
262
|
+
.with(body: request_body.to_json)
|
263
|
+
.to_return(status: 201, body: GET_ORDER_REFUND, headers: {})
|
264
|
+
|
265
|
+
order = Order.get('ord_kEn1PlbGa')
|
266
|
+
refund = order.refund!
|
267
|
+
|
268
|
+
assert_kind_of Order::Refund, refund
|
269
|
+
assert_equal 're_4qqhO89gsT', refund.id
|
270
|
+
assert_equal 'ord_kEn1PlbGa', refund.order_id
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_list_order_refunds
|
274
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa')
|
275
|
+
.to_return(status: 200, body: GET_ORDER, headers: {})
|
276
|
+
|
277
|
+
stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/refunds')
|
278
|
+
.to_return(status: 200, body: LIST_ORDER_REFUNDS, headers: {})
|
279
|
+
|
280
|
+
order = Order.get('ord_kEn1PlbGa')
|
281
|
+
refunds = order.refunds
|
282
|
+
|
283
|
+
assert_equal 1, refunds.size
|
284
|
+
assert_kind_of Order::Refund, refunds.first
|
285
|
+
assert_equal 're_4qqhO89gsT', refunds.first.id
|
286
|
+
assert_equal 'ord_kEn1PlbGa', refunds.first.order_id
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|