Delivering orders
Deliver order
Description
Call this endpoint to deliver a checkout order.
The Deliver call needs to contain a list of all the 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("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}/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 , Quanity - 1
};
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
}
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 paymentmethod.
| Long |
RowDeliveryOptions | An object containing details of partial delivery of order rows. | RowDeliveryOptions |
CancelRemaining | Default value is FALSE.
Is applicable for invoice Account Credit orders. | Boolean |
Row Delivery Options
Parameter | Description | Type |
---|---|---|
OrderRowId | Order row ID from Order Rows. | Long |
Quantity | Number of items to be delivered for specified row. Quantity should be not 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 is not authorized to retrieve information. |
401 | Unauthorized | Merchant is not authorized to retrieve information. |
Deliver order with lower amount
Available for Orders with Paymenttype cardBank Swish Vipps Mobilepay
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("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}/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 is not authorized to retrieve information. |
401 | Unauthorized | Merchant is not authorized to retrieve information. |