Skip to main content

Cancel an Instore Order

An order can be canceled if the Order is in Open status.
If the customer already paid for the order, the customer should be credited using return the same way as they paid.

If the customer has not paid yet, the entire order will be canceled. A new order needs to be created to re-initiate the purchase.

Method: POST
/api/v1/orders/{merchantOrderNumber}/cancel
Cancel Order Example
namespace Instore
{
using APIPortal_CodeSamples;
using Microsoft.Extensions.DependencyInjection;
using System.Net.Http.Headers;

public class CancelInstoreOrder
{
public static async Task CancelInstoreOrderAsync(string merchantOrderNumber)
{
var services = new ServiceCollection();
services.AddHttpClient("MyApiClient", client =>
{
client.BaseAddress = new Uri("https://webpayinstoreapistage.svea.com");
});

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

// Add authorization header
Authentication.BasicAuthenticationToken(out byte[] token);
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(token));

var apiUrl = string.Format("/api/v1/orders/{0}/cancel", merchantOrderNumber);

try
{
HttpResponseMessage response = await httpClient.PostAsync(apiUrl, null);

// 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);
}
}
}
}

Response Code

CodeHttpStatusCodeDescription
200OKOrder cancelled.
403ForbiddenError in cancelling order.