-
Notifications
You must be signed in to change notification settings - Fork 18
/
orders_api.html.md.erb
305 lines (210 loc) · 10 KB
/
orders_api.html.md.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
---
parent: smart_cart
title: orders_api
---
<%= partial 'partials/page_locales' %>
# Orders API <%= edit_link %>
> <i class="fa fa-exclamation-triangle"></i>
> **Important update:** From 5/7/2021 onwards, more order state updates will be sent via Webhook requests. [Read more](/smart_cart/webhook#webhook-events)
Orders API allows Skroutz Merchants to perform actions on their Smart Cart orders,
such as accepting or rejecting an order.
You may find a high level overview of the service and descriptive guides for its activation in the
[merchant support guidelines](https://<%= settings.merchants_domain %>/merchants/support/guidelines/skroutz_marketplace_integration).
<%= partial 'partials/toc' %>
## Setup
### Obtaining an API token
In order to be able to use the API, you need to generate an **API token** from within Smart Cart settings
page in merchant's panel (Merchants > Services > [Skroutz Marketplace](https://<%= settings.merchants_domain %>/merchants/account/shop/ecommerce_details)).
> <i class="fa fa-exclamation-triangle"></i>
> There can only be one active **API key** per shop at a certain time.
> Creating a new API key will expire any previous one.
### Authorization
Pass in a valid **API token** in the `Authorization` header, prefixed with `Bearer `
as in the following curl example.
A specific `Accept` header is also required.
<pre class="terminal">
curl -X GET https://<%= settings.api_domain %>/merchants/ecommerce/orders/191128-1234567 \
-H 'Accept: application/vnd.<%= settings.site_name %>+json; version=3.0' \
-H 'Authorization: Bearer your_access_token_here'
</pre>
## Endpoints
All endpoints require the order `code` as a URL parameter. This is available in all incoming order
[Webhook](/smart_cart/webhook) events, as well as the merchants' panel.
### Retrieve a single order
When an order is in a state that can be accepted or rejected, `accept_options` and `reject_options`
attributes are included in the response, providing all the available options for
issuing "accept" or "reject" requests for the order, respectively.
<pre class="terminal">
GET /merchants/ecommerce/orders/:code
</pre>
<%= render_recording :merchants_ecommerce_orders_show %>
### Accept a single order
To accept an order you need to provide the `pickup_location` and the `pickup_window` which are required. You can also specify `number_of_parcels` which is optional with a default value of `1` if missing.
> <i class="fa fa-exclamation-triangle"></i>
> Express orders cannot be accepted via the API. An automated mechanism will handle the order acceptance.
The available param values used are provided in `accept_options` when retrieving a single order.
<pre class="terminal">
POST /merchants/ecommerce/orders/:code/accept
</pre>
<%= render_recording :merchants_ecommerce_orders_accept %>
#### Example
<pre class="terminal">
curl -X POST https://<%= settings.api_domain %>/merchants/ecommerce/orders/191128-1234567/accept \
-H 'Accept: application/vnd.<%= settings.site_name %>+json; version=3.0' \
-H 'Content-Type: application/json; charset=utf-8' \
-H 'Authorization: Bearer your_access_token_here' \
-d '{ "pickup_location": "YlpD0KROym", "pickup_window": 2, "number_of_parcels": 1 }'
</pre>
### Reject a single order
#### Reject specific line items with reasons
To reject specific line items you need to provide a `line_items` params which would hold an
array of line items. Each line items should have the line item `id` and the rejection
`reason_id`. In case the rejection reason `requires_available_quantity`,
an `available_quantity` attribute is also required.
The available rejection reason IDs are provided in `reject_options` when retrieving a single order.
<pre class="terminal">
POST /merchants/ecommerce/orders/:code/reject
</pre>
<%= render_recording :merchants_ecommerce_orders_reject %>
#### Example
<pre class="terminal">
curl -X POST https://<%= settings.api_domain %>/merchants/ecommerce/orders/191128-1234567/reject \
-H 'Accept: application/vnd.<%= settings.site_name %>+json; version=3.0' \
-H 'Content-Type: application/json; charset=utf-8' \
-H 'Authorization: Bearer your_access_token_here' \
-d '{ "line_items": [ { "id": "jn231kb12u", "reason_id": 2 }, { "id": "opaoe8M3pZ", "reason_id": 4, "available_quantity": 1 } ] }'
</pre>
#### Reject whole order with "other" reason
<pre class="terminal">
POST /merchants/ecommerce/orders/:code/reject
</pre>
<%= render_recording :merchants_ecommerce_orders_reject_other %>
#### Example
<pre class="terminal">
curl -X POST https://<%= settings.api_domain %>/merchants/ecommerce/orders/191128-1234567/reject \
-H 'Accept: application/vnd.<%= settings.site_name %>+json; version=3.0' \
-H 'Content-Type: application/json; charset=utf-8' \
-H 'Authorization: Bearer your_access_token_here' \
-d '{ "rejection_reason_other": "Our store is closed for personal reasons" }'
</pre>
### Upload receipt/invoice
To upload the receipt/invoice of the order, you need to set the `invoice_file` param with the contents of the document.
<pre class="terminal">
POST /merchants/ecommerce/orders/:code/invoices
</pre>
#### Example
<pre class="terminal">
curl -X POST https://<%= settings.api_domain %>/merchants/ecommerce/orders/191128-1234567/invoices \
-H 'Accept: application/vnd.<%= settings.site_name %>+json; version=3.0' \
-H 'Content-Type: multipart/form-data' \
-H 'Authorization: Bearer your_access_token_here' \
-F 'invoice_file=@/path/to/invoice.pdf'
</pre>
Only one file is allowed per order. If the file is already uploaded, it will by replaced by the new file in a subsequent submission.
<blockquote>
<p>
Allowed file types are: pdf/png/jpg. The maximum file size is 7MB.
</p>
</blockquote>
### Update tracking details (FBM only)
To allow shipment tracking, you need to provide the `courier` and `tracking_code` for each order shipment.
> <i class="fa fa-exclamation-triangle"></i>
> This endpoint is available only for FBM (Fulfilled By Merchant) orders
>
> <i class="fa fa-exclamation-triangle"></i>
>The existing API endpoint is limited to updating tracking details only for orders shipped to customers and does not currently support return orders.
>These should be still handled through merchants panel for the time being.
<pre class="terminal">
POST /merchants/ecommerce/orders/:code/tracking_details
</pre>
<%= render_recording :merchants_ecommerce_orders_tracking_details %>
<pre class="terminal">
curl -X POST https://api.skroutz.gr/merchants/ecommerce/orders/191128-1234567/tracking_details \
-H 'Accept: application/vnd.skroutz+json; version=3.0' \
-H 'Content-Type: application/json; charset=utf-8' \
-H 'Authorization: Bearer your_access_token_here' \
-d '{ "tracking_details": [ { "courier":"acs", "tracking_code":"224085551" } ] }'
</pre>
## Error handling
In case of errors, the response will have a representative HTTP status code
in the `4xx` or `5xx` range. The body would contain an array of `errors`.
For example, if you try to accept an order that is already accepted, you will
get a `422` HTTP status code (Unprocessable Entity), with the following body:
<%= render_code '{
"errors": [
{
"code": "order_status",
"messages": [
"Order already accepted."
]
}
]
}', 'javascript' %>
And if you try to reject an order that is already rejected, you will
also get a `422` HTTP status code (Unprocessable Entity), with the following body:
<%= render_code '{
"errors": [
{
"code": "order_status",
"messages": [
"Order already rejected."
]
}
]
}', 'javascript' %>
## Test requests (sandbox)
The following demo order codes are available on production for testing reasons and represent different order states.
> It is safe to issue "accept" and "reject" API calls for the following demo order codes multiple times for testing,
> since no actions on them would persist any data.
#### DEMO-OPEN
A new order that is not accepted yet, and has no courier voucher.
<pre class="terminal">
GET /merchants/ecommerce/orders/DEMO-OPEN
</pre>
<%= render_recording :merchants_ecommerce_orders_demo_open %>
#### DEMO-ACCEPTED
An already-accepted order that also has a courier voucher. Trying to accept it would return an error.
<pre class="terminal">
GET /merchants/ecommerce/orders/DEMO-ACCEPTED
</pre>
<%= render_recording :merchants_ecommerce_orders_demo_accepted %>
#### DEMO-REJECTED
An already-rejected order. Trying to reject it would return an error.
<pre class="terminal">
GET /merchants/ecommerce/orders/DEMO-REJECTED
</pre>
<%= render_recording :merchants_ecommerce_orders_demo_rejected %>
#### DEMO-INVOICE
A new order, requesting an invoice.
<pre class="terminal">
GET /merchants/ecommerce/orders/DEMO-INVOICE
</pre>
<%= render_recording :merchants_ecommerce_orders_demo_invoice %>
#### DEMO-INVOICE39A
A new order including an item with VAT exclusion based on “Άρθρο 39α”.
<pre class="terminal">
GET /merchants/ecommerce/orders/DEMO-INVOICE39A
</pre>
<%= render_recording :merchants_ecommerce_orders_demo_invoice39a %>
#### DEMO-FBS
An already-accepted order without a courier voucher that will be fulfilled by Skroutz. Trying to accept it would return an error.
<pre class="terminal">
GET /merchants/ecommerce/orders/DEMO-FBS
</pre>
<%= render_recording :merchants_ecommerce_orders_demo_fbs %>
#### DEMO-FBS-DISPATCHED
A dispatched order without a courier voucher that will be fulfilled by Skroutz. Delivery note included.
<pre class="terminal">
GET /merchants/ecommerce/orders/DEMO-FBS-DISPATCHED
</pre>
<%= render_recording :merchants_ecommerce_orders_demo_fbs_dispatched %>
#### DEMO-STORE-PICKUP
An open order without a courier or courier voucher that will be picked up by the user at the store.
<pre class="terminal">
GET /merchants/ecommerce/orders/DEMO-STORE-PICKUP
</pre>
<%= render_recording :merchants_ecommerce_orders_demo_store_pickup %>
## Order object attributes appendix
> The order object returned retrieving a single order via the API is the same as
> in [webhook events](/smart_cart/webhook) about a new/updated order.
<%= partial 'localizable/smart_cart/order_object' %>