Cancelling orders
Cancel order
Description
Call this endpoint to cancel an order.
Endpoint
/api/v1/orders/{CheckoutOrderId}
Sample Code
- C#
- Request
- Response
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);
{
"IsCancelled": true
}
Prerequisite
The order must have the action CanCancelOrder.
Request parameters
Parameter | Description | Type |
---|---|---|
CheckoutOrderId required | Checkout order ID of the specified order. | Long |
IsCancelled required | Set to true to cancel order. | Boolean |
Response Code
Code | HttpStatusCode | Description |
---|---|---|
202 | Accepted | Cancel request Accepted for processing. |
400 | BadRequest | Reason:
|
403 | Forbidden | Merchant is not authorized to retrieve information. |
401 | Unauthorized | Merchant 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
/api/v1/orders/{CheckoutOrderId}
Sample Code
- C#
- Request
- Response
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);
}
}
}
{
"CancelledAmount": 0
}
Prerequisite
The order must have the action CanCancelAmount.
Request parameters
Parameter | Description | Type |
---|---|---|
CheckoutOrderId required | Checkout order ID of the specified order. | Long |
CancelledAmount required | Amount to cancel. | Long |
Response Code
Code | HttpStatusCode | Description |
---|---|---|
202 | Accepted | Cancel request Accepted for processing. |
400 | BadRequest | Reason:
|
403 | Forbidden | Merchant is not authorized to retrieve information. |
401 | Unauthorized | Merchant is not authorized to retrieve information. |
Cancel order row
Description
Call this endpoint to change the status of an order row to cancelled.
Endpoint
/api/v1/orders/{CheckoutOrderId}/rows/{OrderRowId}/
Sample Code
- C#
- Request
- Response
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);
{
"IsCancelled": true
}
Prerequisite
The order must have the action CanCancelOrderRow.
The order row must have the action CanCancelRow.
Request parameters
Parameter | Description | Type |
---|---|---|
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
Code | HttpStatusCode | Description |
---|---|---|
204 | No Content | Cancel request Accepted for processing. |
400 | BadRequest | Reason:
|
403 | Forbidden | Merchant is not authorized to retrieve information. |
401 | Unauthorized | Merchant is not authorized to retrieve information. |
Cancel order rows
Description
Call this endpoint to change the status of the order rows to Cancelled.
Endpoint
/api/v1/orders/{CheckoutOrderId}/rows/cancelOrderRows/
Sample Code
- C#
- Request
- Response
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);
{
"OrderRowIds": [
0
]
}
Prerequisite
The order must have the action CanCancelOrderRow.
The order rows must have the action CanCancelRow.
Request parameters
Parameter | Description | Type |
---|---|---|
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
Code | HttpStatusCode | Description |
---|---|---|
204 | No Content | Cancel request Accepted for processing. |
400 | BadRequest | Reason:
|
403 | Forbidden | Merchant is not authorized to retrieve information. |
401 | Unauthorized | Merchant is not authorized to retrieve information. |