Skip to main content

Cancelling orders

Cancel order​

Description

Call this endpoint to cancel an order.

Endpoint​

Method: PATCH
/api/v1/orders/{CheckoutOrderId}

Sample Code​

Cancel Order Example
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class CancelOrder
{
internal static async Task CancelOrderAsync(long checkoutOrderId)
{
var services = new ServiceCollection();
services.AddHttpClient("MyApiClient", client =>
{
client.BaseAddress = new Uri("https://paymentadminapistage.svea.com/api/");
});

var serviceProvider = services.BuildServiceProvider();
var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient("MyApiClient");

var apiUrl = string.Format("v1/orders/{0}", checkoutOrderId);
var cancelRequest = new CancelRequest(true);

var jsonString = JsonSerializer.Serialize(cancelRequest);
var cancelRequestJson = new StringContent(
jsonString,
Encoding.UTF8,
"application/json");

// Add authorization header
Authentication.CreateAuthenticationToken(out string token, out string timestamp, jsonString);
httpClient.DefaultRequestHeaders.Add("Authorization", token);
httpClient.DefaultRequestHeaders.Add("Timestamp", timestamp);

try
{
HttpResponseMessage response = await httpClient.PatchAsync(apiUrl, cancelRequestJson);

// Check if the request was successful
if (response.IsSuccessStatusCode)
{
string responseData = await response.Content.ReadAsStringAsync();
Console.WriteLine("Response: " + responseData);
}
else
{
Console.WriteLine("Failed to retrieve data. Status code: " + response.StatusCode);
}
}
catch (HttpRequestException ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
internal record CancelRequest(bool IsCancelled);

Prerequisite​

The order must have the action CanCancelOrder.

Request parameters​

ParameterDescriptionType

CheckoutOrderID required

Checkout order ID of the specified order.Long

IsCancelled required

Set to true to cancel order.Boolean

Response Code​

CodeHttpStatusCodeDescription
204No ContentCancel request processed successfully.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanCancelOrder action.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant does not have permission to access this resource.
401UnauthorizedMerchant is not authorized to retrieve information.

Cancel order amount​

Description

Call this endpoint to cancel an amount on an order.
It can be called several times on the same order.
Every time the endpoint is called, the new cancelled amount will replace the current cancelled amount.
The requested cancelled amount cannot be higher than the initial order amount. When requesting a new cancelled amount, always provide the total cancelled amount.

Endpoint​

Method: PATCH
/api/v1/orders/{CheckoutOrderId}

Sample Code​

Cancel Order Amount Example
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class CancelOrderAmount
{
internal static async Task CancelOrderAmountAsync(long checkoutOrderId, long cancelAmount)
{
var services = new ServiceCollection();
services.AddHttpClient("MyApiClient", client =>
{
client.BaseAddress = new Uri("https://paymentadminapistage.svea.com/api/");
});

var serviceProvider = services.BuildServiceProvider();
var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient("MyApiClient");

var apiUrl = string.Format("v1/orders/{0}", checkoutOrderId);
var cancelAmountRequest = new CancelAmountRequest(1000);

var jsonString = JsonSerializer.Serialize(cancelAmountRequest);
var cancelAmountRequestJson = new StringContent(
jsonString,
Encoding.UTF8,
"application/json");

// Add authorization header
Authentication.CreateAuthenticationToken(out string token, out string timestamp, jsonString);
httpClient.DefaultRequestHeaders.Add("Authorization", token);
httpClient.DefaultRequestHeaders.Add("Timestamp", timestamp);

try
{
HttpResponseMessage response = await httpClient.PatchAsync(apiUrl, cancelAmountRequestJson);

// Check if the request was successful
if (response.IsSuccessStatusCode)
{
string responseData = await response.Content.ReadAsStringAsync();
Console.WriteLine("Response: " + responseData);
}
else
{
Console.WriteLine("Failed to retrieve data. Status code: " + response.StatusCode);
}
}
catch (HttpRequestException ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}

Prerequisite​

The order must have the action CanCancelAmount.

Request parameters​

ParameterDescriptionType

CheckoutOrderID required

Checkout order ID of the specified order.Long

CancelledAmount required

Amount to cancel.Long

Response Code​

CodeHttpStatusCodeDescription
202AcceptedCancel request accepted for processing.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanCancelAmount action.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant does not have permission to access this resource.
401UnauthorizedMerchant is not authorized to retrieve information.

Cancel order row​

Description

Call this endpoint to change the status of an order row to cancelled.

Endpoint​

Method: PATCH
/api/v1/orders/{CheckoutOrderId}/rows/{OrderRowId}/

Sample Code​

Cancel Order Row Example
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class CancelOrderRow
{
internal static async Task CancelOrderRowAsync(long checkoutOrderId, long rowId)
{
var services = new ServiceCollection();
services.AddHttpClient("MyApiClient", client =>
{
client.BaseAddress = new Uri("https://paymentadminapistage.svea.com/api/");
});

var serviceProvider = services.BuildServiceProvider();
var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient("MyApiClient");

var apiUrl = string.Format("v1/orders/{0}/rows/{1}/", checkoutOrderId, rowId);
var orderRowIds = new int[] { 2 };

var cancelRequest = new CancelRequest(true);
var jsonString = JsonSerializer.Serialize(cancelRequest);
var cancelRequestJson = new StringContent(
jsonString,
Encoding.UTF8,
"application/json");

// Add authorization header
Authentication.CreateAuthenticationToken(out string token, out string timestamp, jsonString);
httpClient.DefaultRequestHeaders.Add("Authorization", token);
httpClient.DefaultRequestHeaders.Add("Timestamp", timestamp);

try
{
HttpResponseMessage response = await httpClient.PatchAsync(apiUrl, cancelRequestJson);

// Check if the request was successful
if (response.IsSuccessStatusCode)
{
string responseData = await response.Content.ReadAsStringAsync();
Console.WriteLine("Response: " + responseData);
}
else
{
Console.WriteLine("Failed to retrieve data. Status code: " + response.StatusCode);
}
}
catch (HttpRequestException ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}

internal record CancelRequest(bool IsCancelled);

Prerequisite​

The order must have the action CanCancelOrderRow.
The order row must have the action CanCancelRow.

Request parameters​

ParameterDescriptionType

CheckoutOrderID required

Checkout order ID of the specified order.Long

OrderRowID required

Order row ID to be cancelled. This can be retrieved from GET Order Response

Long

IsCancelled required

Set to true to cancel order row.Boolean

Response Code​

CodeHttpStatusCodeDescription
204No ContentCancel request accepted for processing.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanCancelOrderRow or CanCancelRow action.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant does not have permission to access this resource.
401UnauthorizedMerchant is not authorized to retrieve information.

Cancel order rows​

Description

Call this endpoint to change the status of the order rows to cancelled.

Endpoint​

Method: PATCH
/api/v1/orders/{CheckoutOrderId}/rows/cancelOrderRows/

Sample Code​

Cancel Order Rows Example

using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class CancelOrderRows
{
internal static async Task CancelOrderRowsAsync(long checkoutOrderId)
{
var services = new ServiceCollection();
services.AddHttpClient("MyApiClient", client =>
{
client.BaseAddress = new Uri("https://paymentadminapistage.svea.com/api/");
});

var serviceProvider = services.BuildServiceProvider();
var httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();
var httpClient = httpClientFactory.CreateClient("MyApiClient");

var apiUrl = string.Format("v1/orders/{0}/rows/cancelOrderRows/", checkoutOrderId);
var orderRowIds = new int[] { 2, 3 };

var cancelRequest = new CancelOrderRowsRequest(orderRowIds);
var jsonString = JsonSerializer.Serialize(cancelRequest);
var cancelRequestJson = new StringContent(
jsonString,
Encoding.UTF8,
"application/json");

// Add authorization header
Authentication.CreateAuthenticationToken(out string token, out string timestamp, jsonString);
httpClient.DefaultRequestHeaders.Add("Authorization", token);
httpClient.DefaultRequestHeaders.Add("Timestamp", timestamp);

try
{
HttpResponseMessage response = await httpClient.PatchAsync(apiUrl, cancelRequestJson);

// Check if the request was successful
if (response.IsSuccessStatusCode)
{
string responseData = await response.Content.ReadAsStringAsync();
Console.WriteLine("Response: " + responseData);
}
else
{
Console.WriteLine("Failed to retrieve data. Status code: " + response.StatusCode);
}
}
catch (HttpRequestException ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
}
internal record CancelOrderRowsRequest(int[] OrderRowIds);

Prerequisite​

The order must have the action CanCancelOrderRow.
The order rows must have the action CanCancelRow.

Request parameters​

ParameterDescriptionType

CheckoutOrderID required

Checkout order ID of the specified order.Long

OrderRowIDs required

ID of the rows that will be cancelled. This can be retrieved from GET Order response

List of Long
RowCancellationOptions

An object containing details of partial cancellation of order rows.

RowCancellationOptions

Row Cancellation Options​

ParameterDescriptionType
OrderRowID

Order row ID.
ID should be present in the OrderRowIDs collection in request.

Long
Quantity

Number of items to be cancelled for specified row.
Quantity should not be less than 0 or more than the quantity of the row.

Long

Response Code​

CodeHttpStatusCodeDescription
204No ContentCancel request accepted for processing.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanCancelOrderRow or CanCancelRow action.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant does not have permission to access this resource.
401UnauthorizedMerchant is not authorized to retrieve information.