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("http://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
202AcceptedCancel request Accepted for processing.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanCancelOrder action.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant is not authorized to retrieve information.
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 should not 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("http://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 is not authorized to retrieve information.
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("http://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 is not authorized to retrieve information.
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("http://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

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 is not authorized to retrieve information.
401UnauthorizedMerchant is not authorized to retrieve information.