Skip to main content

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

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

Sample Code

Deliver Order Example
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; }
}

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.

info

Payment Plan Orders are delivered fully.

Payload parameters

ParameterDescriptionType

OrderRowIds

required
ID of the order rows to be deliveredList of Long
InvoiceDistributionType

Valid only for invoice paymentmethod.
Invoice distribution types:

  • Default = 0
  • Post = 2
  • Email = 3
  • EInvoiceB2B = 4
Long
RowDeliveryOptionsAn object containing details of partial delivery of order rows.RowDeliveryOptions
CancelRemaining

Default value is FALSE.
If this parameter is set TRUE, then rest of the order will be cancelled after delivery.


Is applicable for invoice Account Credit orders.

Boolean

Row Delivery Options

ParameterDescriptionType
OrderRowId

Order row ID from Order Rows.
ID should be present in the [OrderRowIds] collection in request.

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

CodeHttpStatusCodeDescription
202AcceptedDeliver request Accepted for processing.
400BadRequest
Reason:
  • Missing request details.
  • Missing CanDeliverOrder or CanDeliverPartially action.

  • Order row already delivered.
  • Order rowId is not valid.
  • Order rowId is missing CanDeliverRow action.
  • Order not found.
  • No order rows to deliver.
  • Invalid distribution type.
  • Order expired/closed.
  • Any other internal error.
403ForbiddenMerchant is not authorized to retrieve information.
401UnauthorizedMerchant is not authorized to retrieve information.

Deliver order with lower amount

info

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

Method: POST
/api/v1/orders/{CheckoutOrderId}/deliveries/DeliverAndLowerAmount

Sample Code

Deliver Order Example
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);

Prerequisite

The order must have the actions CanDeliverOrder and CanCancelAmount.

Payload parameters

ParameterDescriptionType

DeliveredAmount required

Amount to be Delivered.Long

Response Code

CodeHttpStatusCodeDescription
202AcceptedDeliver request Accepted for processing.
400BadRequest
Reason:
  • Missing request details.
  • Missing CanDeliverOrder or CanCancelAmount action.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant is not authorized to retrieve information.
401UnauthorizedMerchant is not authorized to retrieve information.