Delivering orders
Deliver order
Description
Call this endpoint to deliver an order.
The request body must contain a list of all order row IDs to be delivered.
To make a complete delivery, include all order rows IDs or set the row IDs array empty.
If the delivery doesn't contain any order rows, it will still count as complete.
To make a partial delivery, only include the order rows that are to be delivered.
Endpoint
/api/v1/orders/{CheckoutOrderId}/deliveries
Sample Code
- C#
- Request
- Response
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;
internal static class DeliverOrder
{
internal static async Task DeliverOrderAsync(long checkoutOrderId)
{
var services = new ServiceCollection();
services.AddHttpClient("MyApiClient", client =>
{
client.BaseAddress = new Uri("https://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}/deliveries", checkoutOrderId);
var orderRowIds = new int[] { 4 }; //Deliver Order with RowId - 4
var rowDeliveryOptions = new List<RowDeliveryOptions>
{
new RowDeliveryOptions{OrderRowId = 4, Quantity = 100} `//Deliver Order with RowId - 4, Quantity - 1 (100 in minor units)`
};
var deliveryRequest = new DeliveryRequest(orderRowIds, rowDeliveryOptions, 1, false);
var jsonString = JsonSerializer.Serialize(deliveryRequest);
var deliveryRequestJson = 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, deliveryRequestJson);
// 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 DeliveryRequest(int[] OrderRowIds, IList<RowDeliveryOptions> RowDeliveryOptions, int InvoiceDistributionType, bool CancelRemaining);
internal class RowDeliveryOptions
{
public int OrderRowId { get; set; }
public int Quantity { get; set; }
}
{
"OrderRowIds": [
0
],
"RowDeliveryOptions": [
{
"OrderRowId": 0,
"Quantity": 0
}
],
"InvoiceDistributionType": 0,
"CancelRemaining": false
}
{
"DeliveryId": 194281000040
}
InvoiceDistributionType
| Value | Name | Description |
|---|---|---|
| 0 | Unknown | Not specified |
| 2 | Post | Invoice sent by post |
| 3 | Invoice sent by email | |
| 4 | EInvoiceB2B | Electronic invoice for B2B |
| 6 | Omni | Omni channel distribution |
Prerequisite
The order must have action CanDeliverOrder or CanDeliverPartially to deliver the order.
To make a partial delivery, the order must have the action CanDeliverPartially and each order row must have the action CanDeliverRow.
Payment Plan Orders are delivered fully.
Payload parameters
| Parameter | Description | Type |
|---|---|---|
OrderRowIDs required | ID of the order rows to be delivered | List of Long |
| InvoiceDistributionType | Valid only for invoice payment method.
| Long |
| RowDeliveryOptions | An object containing details of partial delivery of order rows. | RowDeliveryOptions |
| CancelRemaining | Default value is FALSE.
Is applicable for orders with payment type: InvoiceAccount CreditCard VippsMobilepayApplepayGooglepay. | Boolean |
Row Delivery Options
| Parameter | Description | Type |
|---|---|---|
| OrderRowID | Order row ID for order rows. | Long |
| Quantity | Number of items to be delivered for specified row. Quantity cannot be less than 0, or more than the quantity of the row. | Long |
Response Code
| Code | HttpStatusCode | Description |
|---|---|---|
| 202 | Accepted | Deliver request Accepted for processing. |
| 400 | BadRequest | Reason:
|
| 403 | Forbidden | Merchant does not have permission to access this resource. |
| 401 | Unauthorized | Merchant is not authorized to retrieve information. |
Deliver order with lower amount
Available for orders with payment type: Card Vipps Mobilepay Applepay Googlepay
Description
Call this endpoint to deliver part of the order amount and cancel the remaining amount.
Order status will be changed to Delivered , and no further action can be done on the order rows.
Delivered amount can be cancelled/credited depending on the action available.
Endpoint
/api/v1/orders/{CheckoutOrderId}/deliveries/DeliverAndLowerAmount
Sample Code
- C#
- Request
- Response
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;
internal static class DeliverOrderAmount
{
internal static async Task DeliverOrderAmountAsync(long checkoutOrderId)
{
var services = new ServiceCollection();
services.AddHttpClient("MyApiClient", client =>
{
client.BaseAddress = new Uri("https://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}/deliveries/DeliverAndLowerAmount", checkoutOrderId);
var deliveryRequest = new DeliveryAmountRequest(100);
var jsonString = JsonSerializer.Serialize(deliveryRequest);
var deliveryRequestJson = 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, deliveryRequestJson);
// 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 DeliveryAmountRequest(long DeliveredAmount);
{
"DeliveredAmount": 15000
}
{
"DeliveryId": 194281000040
}
Prerequisite
The order must have the actions CanDeliverOrder and CanCancelAmount.
Payload parameters
| Parameter | Description | Type |
|---|---|---|
DeliveredAmount | Amount to be Delivered. | Long |
Response Code
| Code | HttpStatusCode | Description |
|---|---|---|
| 202 | Accepted | Deliver request Accepted for processing. |
| 400 | BadRequest | Reason:
|
| 403 | Forbidden | Merchant does not have permission to access this resource. |
| 401 | Unauthorized | Merchant is not authorized to retrieve information. |
Deliver and Lower Amount
Description
Call this endpoint to lower the order amount and deliver in a single operation. Useful when you want to deliver an order for less than its full amount (e.g. the customer returned part of an order before delivery).
Endpoint
Method: POST
/api/v1/orders/{CheckoutOrderId}/deliveries/DeliverAndLowerAmount
Prerequisite
The order must have BOTH actions:
- CanCancelAmount (to lower the amount)
- CanDeliverOrder (to deliver)
Request parameters
| Parameter | Description | Type |
|---|---|---|
| CheckoutOrderId (required) | Checkout order ID of the specified order. | Long |
| DeliveredAmount (required) | The amount to deliver (in minor units). | Decimal |
| CancelRemaining | When set to true, undelivered order rows will be automatically cancelled after delivery. Only applicable for Invoice, PaymentPlan, and AccountCredit orders. Default: false. | Boolean |
Response
| Parameter | Description | Type |
|---|---|---|
| DeliveryId | ID of the created delivery. | Long |
Response Code
| Code | HttpStatusCode | Description |
|---|---|---|
| 202 | Accepted | Deliver and lower amount request accepted for processing. |
| 400 | BadRequest | Invalid request details, missing actions, or order not found. |
| 403 | Forbidden | Merchant not permitted. |
| 401 | Unauthorized | Merchant not authorized. |