Return an Instore Order
If the customer already paid for the order, the customer will be credited the same way as they paid.
To return an order partially, call the endpoint with an array of order rows to return. These order rows do not have to match any of the rows of the original order. If the array is empty, the entire order will be credited.
Method: POST
/api/v1/orders/{merchantOrderNumber}/return
Request
- Request Model
- Request Samples
- Code Snippets
Name | Description | Type | Additional Information | Examples |
---|---|---|---|---|
Name | Article name. | String | Max length: 40 | |
Quantity | Quantity of the product. | Int64 | 1-7 digits Minor Units. | |
UnitPrice | Price of the product including VAT. | Int64 | 1-13 digits Can be negative. Minor Units. | |
ArticleNumber | Article number | String | Max length: 256 | |
DiscountPercent | The discount percent of the order row. Cannot be used together with DiscountAmount | Int64 | Min: 0 Max: 10000 No fractions Minor Units. | |
DiscountAmount | The total discount amount for this order row. Cannot be used together with DiscountPercent | Int64 | Min: 0 Max: Order row total Minor Units. | |
VatPercent | The VAT percentage of the current product. Valid vat percentage for that country. | Int64 | Minor Units. | |
Unit | The unit type, e.g., “st”, “pc”, “kg” etc. | String | Max length: 4 | |
RowNumber | The row number the row will have in the Webpay system | Int32 |
application/json
{
"returnedItems": [
{
"articleNumber": "abc1234",
"name": "Headphones4",
"quantity": 100,
"unitPrice": 100,
"discountPercent": 0,
"discountAmount": 0,
"vatPercent": 0,
"unit": "st",
"rowNumber": 3,
"merchantData": "Size: M"
}
]
}
- C#
ReturnOrderSample.cs
namespace Instore
{
using APIPortal_CodeSamples;
using Microsoft.Extensions.DependencyInjection;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Text;
public class ReturnInstoreOrder
{
public static async Task ReturnInstoreOrderAsync(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");
InstoreReturnOrderRequestModel returnRequest = InstoreReturnOrderRequest.CreateReturnRequest();
var jsonString = JsonSerializer.Serialize(returnRequest);
var returnOrderRequestJson = new StringContent(
jsonString,
Encoding.UTF8,
"application/json");
// 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}/return", merchantOrderNumber);
try
{
HttpResponseMessage response = await httpClient.PostAsync(apiUrl, returnOrderRequestJson);
// 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);
}
}
}
public class InstoreReturnOrderRequestModel
{
public List<OrderRow> ReturnedItems { get; set; } = new List<OrderRow>();
}
public class InstoreReturnOrderRequest
{
public static InstoreReturnOrderRequestModel CreateReturnRequest() => new()
{
ReturnedItems = new List<OrderRow>() {
new OrderRow {
ArticleNumber = "123-456-789",
Name="Article1",
Quantity=500,
UnitPrice=100,
Unit="st",
RowNumber = 1
}
}
};
}
}
Response Code
Code | HttpStatusCode | Description |
---|---|---|
200 | OK | Order cancelled. |
403 | Forbidden | Error in cancelling order. |