Skip to main content

Editing orders

Add order row

Description

Call this endpoint to add order row to an order. If the new order amount is higher than the current order amount, a credit check will be made.

Endpoint

Method: POST
/api/v1/orders/{CheckoutOrderId}/rows/

Sample Code

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

internal static class EditOrderAddRow
{
internal static async Task AddRowAsync(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/", checkoutOrderId);

//New Order Row
var addRowRequest = new AddRowRequest("A-1", "Article Name 1", 1000, 1000, 0, 0, 2500, "st");

var jsonString = JsonSerializer.Serialize(addRowRequest);
var addRowRequestJson = 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.PostAsync(apiUrl, addRowRequestJson);

// 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 CanAddOrderRow.

Request parameters

ParameterDescriptionType

CheckoutOrderId required

Checkout order ID of the specified order.Long

OrderRow required

Order RowOrder Row Object

Response

ParameterDescriptionType
OrderRowIdThe row ID of the newly created Order row.Long

Response Code

CodeHttpStatusCodeDescription
202AcceptedAdd Row request Accepted for processing.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanAddOrderRow action.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant is not authorized to retrieve information.
401UnauthorizedMerchant is not authorized to retrieve information.

Add order rows

Description

Call this endpoint to add several order rows to an order. If the new order amount is higher than the current order amount, a credit check will be made.

Endpoint

Method: POST
/api/v1/orders/{CheckoutOrderId}/rows/addOrderRows/

Sample Code

Add Order Rows Example
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class EditOrderAddRows
{
internal static async Task AddRowsAsync(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/addOrderRows", checkoutOrderId);

//New Order Rows
var addRowRequest = new List<AddRowRequest>
{
new AddRowRequest("A-1", "Article Name 1", 1000, 1000, 0, 0, 2500, "st"),
new AddRowRequest("A-2", "Article Name 2", 2000, 2000, 0, 0, 2500, "st"),
};

var addRowsRequest = new AddRowsRequest(addRowRequest);

var jsonString = JsonSerializer.Serialize(addRowsRequest);
var addRowRequestJson = 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.PostAsync(apiUrl, addRowRequestJson);

// 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 AddRowRequest(string ArticleNumber, string Name, long Quantity, long UnitPrice, long DiscountPercent, long DiscountAmount, long VatPercent, string Unit);

internal record AddRowsRequest(IList<AddRowRequest> OrderRows);

Prerequisite

The order must have the action CanAddOrderRow.

Request parameters

ParameterDescriptionType

CheckoutOrderId required

Checkout order ID of the specified order.Long

OrderRows required

List of Order Row ObjectList of Order Row

Order Row

ParameterDescriptionType
ArticleNumberArticle number as a string, can contain letters and numbers.String

Name required

Article name.String

Quantity required

Quantity of the product.Long

UnitPrice required

Price of the product including VAT.Long
DiscountPercentThe discount percent of the product.Long
DiscountAmountThe discount amount of the product.Long
VatPercentThe VAT percentage of the current product.Long
UnitThe unit type, e.g., “st”, “pc”, “kg” etc.String

Response

ParameterDescriptionType
OrderRowIdThe row IDs of the newly created OrderRows.List of Long

Response Code

CodeHttpStatusCodeDescription
202AcceptedAdd Row request Accepted for processing.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanAddOrderRow action.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant is not authorized to retrieve information.
401UnauthorizedMerchant is not authorized to retrieve information.

Update order row

Description

Call this endpoint to update an order row.
If the new order amount is higher than the current order amount, a credit check will be made.

Endpoint

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

Sample Code

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

internal static class EditOrderUpdateRow
{
internal static async Task EditOrderUpdateRowAsync(long checkoutOrderId, int 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 updateRowRequest = new UpdateRowRequest("A-1", 5000);

var jsonString = JsonSerializer.Serialize(updateRowRequest);
var updateRowRequestJson = 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, updateRowRequestJson);

// 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 UpdateRowRequest(string ArticleNumber, long Quantity, string? Name = "", long? UnitPrice = 0, long? DiscountPercent = 0, long? DiscountAmount = 0,
long? VatPercent = 0, string? Unit = "",
bool? IsCancelled = false);

Prerequisite

The order must have the action CanUpdateOrderRow.
The order row must have the action CanUpdateRow.

Request parameters

ParameterDescriptionType

CheckoutOrderId required

Checkout order ID of the specified order.Long

OrderRowId required

ID of the specified row to be updated.Long

OrderRow required

Order Row ObjectOrder Row

Response Code

CodeHttpStatusCodeDescription
204No ContentUpdate Row request Accepted for processing.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanUpdateOrderRow or CanUpdateRow action.
  • Order not found.
  • Order Row cannot be found.
  • Any other internal error.
403ForbiddenMerchant is not authorized to retrieve information.
401UnauthorizedMerchant is not authorized to retrieve information.

Update Order Row Request

ParameterDescriptionType
ArticleNumberArticle number as a string, can contain letters and numbers.String
NameArticle name.String

Quantity required

Quantity of the product.Long
UnitPricePrice of the product including VAT.Long
DiscountPercentThe discount percent of the product.Long
DiscountAmountThe discount amount of the product.Long
VatPercentThe VAT percentage of the current product.Long
UnitThe unit type, e.g., “st”, “pc”, “kg” etc.String
IsCancelledSet to true if the row needs to be cancelled.Boolean

Update order rows

Description

Call this endpoint to update several order rows.
If the new order amount is higher than the current order amount, a credit check will be made.

Endpoint

Method: POST
/api/v1/orders/{CheckoutOrderId}/rows/updateOrderRows/

Sample Code

Update Order Rows Example
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class EditOrderUpdateRows
{
internal static async Task EditOrderUpdateRowsAsync(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/updateOrderRows", checkoutOrderId);

var updateRowsRequest = new UpdateRowsRequest
{
OrderRows = new List<UpdateRowsObject>
{
new UpdateRowsObject(1, new UpdateRowRequest("A-1", 1000)),
new UpdateRowsObject(2, new UpdateRowRequest("A-2", 3000))
}
};


var jsonString = JsonSerializer.Serialize(updateRowsRequest);
var updateRowsRequestJson = 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.PostAsync(apiUrl, updateRowsRequestJson);

// 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 UpdateRowsObject(long RowId, UpdateRowRequest Row);
internal record UpdateRowRequest(string ArticleNumber, long Quantity, string? Name = "", long? UnitPrice = 0, long? DiscountPercent = 0, long? DiscountAmount = 0,
long? VatPercent = 0, string? Unit = "",
bool? IsCancelled = false);
internal class UpdateRowsRequest
{
public IList<UpdateRowsObject> OrderRows { get; set; }
}

Prerequisite

The order must have the action CanUpdateOrderRow.
The order row must have the action CanUpdateRow.

Request parameters

ParameterDescriptionType

CheckoutOrderId required

Checkout order ID of the specified order.Long

OrderRows required

To update several order rows with RowId specified.List of Order Row

Update Order Rows Request

ParameterDescriptionType

RowId required

Row Id of the Order Row.Long
ArticleNumberArticle number as a string, can contain letters and numbers.String
NameArticle name.String

Quantity required

Quantity of the product.Long
UnitPricePrice of the product including VAT.Long
DiscountPercentThe discount percent of the product.Long
DiscountAmountThe discount amount of the product.Long
VatPercentThe VAT percentage of the current product.Long
UnitThe unit type, e.g., “st”, “pc”, “kg” etc.String

Response Code

CodeHttpStatusCodeDescription
204No ContentUpdate Row request Accepted for processing.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanUpdateOrderRow or CanUpdateRow action.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant is not authorized to retrieve information.
401UnauthorizedMerchant is not authorized to retrieve information.

Replace order rows

Description

Call this endpoint to replace all existing order rows with new order rows.
The existing rows will be cancelled.
If the new order amount is higher than the current order amount, a credit check will be made.

Endpoint

Method: PUT
/api/v1/orders/{CheckoutOrderId}/rows/replaceOrderRows

Sample Code

Replace Order Rows Example
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class EditOrderReplaceRows
{
internal static async Task EditOrderReplaceRowsAsync(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/replaceOrderRows", checkoutOrderId);

//New Order Rows
var replaceRowRequest = new List<AddRowRequest>
{
new AddRowRequest("A-1", "Article Name 1", 1000, 1000, 0, 0, 2500, "st")
};

var addRowsRequest = new AddRowsRequest(replaceRowRequest);

var jsonString = JsonSerializer.Serialize(addRowsRequest);
var replaceRowRequestJson = 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.PutAsync(apiUrl, replaceRowRequestJson);

// 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 AddRowRequest(string ArticleNumber, string Name, long Quantity, long UnitPrice, long DiscountPercent, long DiscountAmount, long VatPercent, string Unit);

Prerequisite

The order must have the action CanUpdateOrderRow.

Request parameters

ParameterDescriptionType

CheckoutOrderId required

Checkout order ID of the specified order.Long

OrderRows required

To update several order rows with RowId specified.List of Order Row

Response Code

CodeHttpStatusCodeDescription
204No ContentUpdate Row request Accepted for processing.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanUpdateOrderRow or CanUpdateRow action.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant is not authorized to retrieve information.
401UnauthorizedMerchant is not authorized to retrieve information.

Extend order expiry date

Description

Call this endpoint to update expiry date of an order. The requested new expiry date of an order should not be in the past and greater then current date.

Endpoint

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

Sample Code

Extend Order Expiry Date Example
using Microsoft.Extensions.DependencyInjection;

internal static class EditOrderExtendExpiryDate
{
internal static async Task EditOrderExtendExpiryDateAsync(long checkoutOrderId, string expiryDate)
{
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}/extendOrder/{1}/", checkoutOrderId, expiryDate);

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

try
{
HttpResponseMessage response = await httpClient.PatchAsync(apiUrl, new StringContent(""));

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

Request parameters

ParameterDescriptionType

CheckoutOrderId required

Checkout order ID of the specified order.Long

ExpiryDate required

New expiry date of an order in ISO 8601 format. e.g. 2024-01-01

Date

Response Code

CodeHttpStatusCodeDescription
200SuccessExtend Date has been changed successfully.
400BadRequest
Reason:
  • Invalid request details.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant is not authorized to retrieve information.
401UnauthorizedMerchant is not authorized to retrieve information.