ordersGetCancellationPreview method
Preview an order cancellation
Previews cancelling every item of an order now, with the totals. Requires the read order permission. Returns { orderId, currency, items, totals }, every amount in the order currency. Each item has orderItemId, productType and status. previewable items carry preview, the same payload as GET order-items/{id}/cancellation-preview (isRefundable: false included); notCancellable items carry a reason: notFulfilled (not delivered), refunded, refundInProgress (a refund was started and has not finished), amendmentInProgress, manualReview (contact support) or notAllowed (the product's rules do not allow cancelling it now). totals sums penaltyAmount, cancellationFee and refundAmount over the previewable items; totals.isComplete is true only when every item is previewable. The preview cancels nothing, changes no state and locks no amount: cancelling an item prices its cancellation again. Only an item the item preview refuses is notAllowed: a booking system that cannot answer right now fails this whole call, with 503 when it is unavailable, as it fails the item preview. Retry later. An order of another partner, or an unknown id, returns 404 with code 10004.
Parameters:
- String id (required):
Order id (
idfrom the order response).
Implementation
Future<OrderCancellationPreview?> ordersGetCancellationPreview(String id, { Future<void>? abortTrigger, }) async {
final response = await ordersGetCancellationPreviewWithHttpInfo(id, abortTrigger: abortTrigger,);
if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
}
// When a remote server returns no body with a status of 204, we shall not decode it.
// At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
// FormatException when trying to decode an empty string.
if (response.body.isNotEmpty && response.statusCode != HttpStatus.noContent) {
return await apiClient.deserializeAsync(await _decodeBodyBytes(response), 'OrderCancellationPreview',) as OrderCancellationPreview;
}
return null;
}