orderItemsCancel method
- String id,
- String idempotencyKey, {
- OrderItemCancelRequest? orderItemCancelRequest,
- Future<
void> ? abortTrigger,
Cancel an item
Cancels an order item and refunds what was paid for it, less any cancellation penalty. Available when the item's actions.cancellation is available; while a refund is running it shows inProgress, and manualReview means support must handle it. An item still being delivered cannot be cancelled, and the fulfillmentFailed reason is accepted only for a rejected item; a cancellation that is not valid for the item returns 400 with code 10001. A kind of item that can never be cancelled returns 422 with code 18000 (CANCELLATION_NOT_SUPPORTED). Otherwise a cancellation that is not allowed now returns 409 with code 18001 (CANCELLATION_NOT_AVAILABLE), and details[0].reason repeats actions.cancellation.availability (IN_PROGRESS, MANUAL_REVIEW or NOT_AVAILABLE). The amount is recalculated at this point, so it can differ from an earlier cancellation preview. A refund started by OpenRoam support returns 409. An item of another partner, or an unknown id, returns 404 with code 10004. Returns the orderItemId, the refund amount, the method it is returned to and its status. A balance payment is refunded to the wallet that paid it. Refund progress is also reported by the order-item.refunded webhook. Requires an Idempotency-Key header (a UUID). Repeating a completed request with the same key returns 409 with code 12000 (IDEMPOTENCY_KEY_ALREADY_USED); one still running returns 409 with code 12002 (IDEMPOTENCY_KEY_IN_PROGRESS), and a different body with the same key 409 with code 12001. A request that ended in an error can be sent again with the same key and body.
Parameters:
-
String id (required): Order item id (
items[].idfrom the order response). -
String idempotencyKey (required): UUID idempotency key for safe retries of this operation.
-
OrderItemCancelRequest orderItemCancelRequest: The cancellation reason.
Implementation
Future<OrderItemCancelResult?> orderItemsCancel(String id, String idempotencyKey, { OrderItemCancelRequest? orderItemCancelRequest, Future<void>? abortTrigger, }) async {
final response = await orderItemsCancelWithHttpInfo(id, idempotencyKey, orderItemCancelRequest: orderItemCancelRequest, 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), 'OrderItemCancelResult',) as OrderItemCancelResult;
}
return null;
}