Skip to main content

Crediting orders

Credit order rows

Description

Call this endpoint to create a new credit on a delivery.
The Credit order rows call needs to contain a list of all the order row IDs that are to be credited.

Endpoint

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

Sample Code

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

internal static class CreditOrder
{
internal static async Task CreditOrderRowsAsync(long checkoutOrderId, long deliveryId)
{
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/{1}/credits/", checkoutOrderId, deliveryId);
var orderRowIds = new int[] { 2 }; //Credit Order with RowId - 1
var rowCreditingOptions = new List<RowCreditingOptions>
{
new RowCreditingOptions{OrderRowId = 2, Quantity = 100} //Credit Order with RowId - 1 , Quanity - 1
};

var creditRequest = new CreditRowsRequest(orderRowIds, rowCreditingOptions);
var jsonString = JsonSerializer.Serialize(creditRequest);
var creditRowRequestJson = 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, creditRowRequestJson);

// 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 CreditRowsRequest(int[] OrderRowIds, IList<RowCreditingOptions> RowCreditingOptions);
internal class RowCreditingOptions
{
public int OrderRowId { get; set; }
public int Quantity { get; set; }
}
info

Available for Orders with Paymenttype InvoicePaymentplan Account Credit

Prerequisite

The delivery must have the action CanCreditOrderRows.
The order rows must have the action CanCreditRow.

Request parameters

ParameterDescriptionType

CheckoutOrderId required

Checkout order ID of the specified order.Long

DeliveryId required

ID of the specified delivery.Long

OrderRowIds required

ID(s) of the delivered order row(s) to be credited.
Pass Empty array( [] ) - if all the rows needs to be credited.
List of Long
RowCreditingOptions
  • An object containing details of partial crediting of order rows.

  • This parameter can be used only to partially credit Invoice orders.

RowCreditingOptions

Row Crediting Options

ParameterDescriptionType
OrderRowId

Order row ID.
ID should be present in the OrderRowIds collection in request.

Long
Quantity
  • Number of items to be credited for specified row.
  • Quantity should be not be less than 0 or more than the quantity of the row.

Long

Response

ParameterDescriptionType
CreditIdID to identify each creditString
ResultCodeNameIf the credit is success or pendingString

Response Code

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

Credit new order row

Description

Call this endpoint to credit an order by adding a new order row with a credit amount.

Endpoint

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

Sample Code

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

internal static class CreditOrderNewRow
{
internal static async Task CreditOrderNewRowAsync(long checkoutOrderId, long deliveryId)
{
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/{1}/credits/", checkoutOrderId, deliveryId);
var creditNewRow = new NewCreditOrderRow("art-2", "Article - 2", 100, 100, 0, 0, 0, "st");
var creditNewRowRequest = new NewCreditOrderRowRequest
{
NewCreditOrderRows = new List<NewCreditOrderRow> { creditNewRow }
};

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

// 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 class NewCreditOrderRowRequest
{
public NewCreditOrderRow NewCreditOrderRow { get; set; }
public IList<NewCreditOrderRow> NewCreditOrderRows { get; set; }
}
internal record NewCreditOrderRow(string ArticleNumber, string Name, long Quantity, long UnitPrice, long DiscountPercent,
long DiscountAmount, long VatPercent, string Unit);
info

Available for Orders with Paymenttype InvoicePaymentplan Account Credit

Prerequisite

The delivery must have the action CanCreditNewRow.

Request parameters

ParameterDescriptionType

CheckoutOrderId required

Checkout order ID of the specified order.Long

DeliveryId required

ID of the specified delivery.Long
NewCreditOrderRowThe new credit row.CreditOrderRow
NewCreditOrderRowsUse this if crediting multiple new rowsList of CreditOrderRow

Response

ParameterDescriptionType
CreditIdID to identify each creditString
ResultCodeNameIf the credit is success or pendingString

Response Code

CodeHttpStatusCodeDescription
202AcceptedCredit request Accepted for processing.
400BadRequest
Reason:
  • Invalid request details.
  • Missing CanCreditNewRow action.
  • Credit amount exceeds remaining debt.
  • Order not found.
  • Any other internal error.
403ForbiddenMerchant is not authorized to retrieve information.
401UnauthorizedMerchant is not authorized to retrieve information.

Credit Order Row

ParameterDescriptionType
ArticleNumberArticle NumberString

Name required

Credit Article name.String

UnitPrice required

Article amount including VAT.Long
VatPercent

The VAT percentage of the credit amount.
Allowed valid VAT percentage for different countries.

Long
DiscountPercent

The discount percent of the product.
API doesn't accept decimal value for DiscountPercent.

Long
DiscountAmount

The discount amount of the product.
API doesn't accept decimal value for DiscountAmount.

Long

Credit order row with fee

Description

This endpoint could be called to create a new credit with fee on a delivery with specified order rows.
It is also possible to partially credit an order row with fee using the RowCreditingOptions.

Adding a fee to the credit is optional.

Endpoint

Method: POST
/api/v1/orders/{CheckoutOrderId}/deliveries/{DeliveryId}/credits/CreditWithFee

Sample Code

Credit Order Rows with Fee Example
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class CreditOrderNewRowFee
{
internal static async Task CreditOrderNewRowFeeAsync(long checkoutOrderId, long deliveryId)
{
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/{1}/credits/CreditWithFee", checkoutOrderId, deliveryId);
var orderRowIds = new int[] { 2 }; //Credit Order with RowId - 1
var rowCreditingOptions = new List<RowCreditingOptions>
{
new RowCreditingOptions{OrderRowId = 2, Quantity = 100} //Credit Order with RowId - 2 , Quanity - 1
};

var fee = new CreditFee("art-1", "Article-1", 100, 0);

var creditRequest = new CreditNewRowFeeRequest(orderRowIds, fee, rowCreditingOptions);

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

// 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 CreditFee(string ArticleNumber, string Name, long UnitPrice, long VatPercent);
internal record CreditNewRowFeeRequest(int[] OrderRowIds, CreditFee Fee, IList<RowCreditingOptions> RowCreditingOptions);
internal class RowCreditingOptions
{
public int OrderRowId { get; set; }
public int Quantity { get; set; }
}
info

Available for Orders with Paymenttype Invoice

Prerequisite

The delivery must have the action CanCreditOrderRows.
The order rows must have the action CanCreditRow.

Request parameters

ParameterDescriptionType

CheckoutOrderId required

Checkout order ID of the specified order.Long

DeliveryId required

ID of the specified delivery.Long

OrderRowIds required

ID(s) of the delivered order row(s) to be credited.List of Long
FeeAn object containing the fee details of the credit..CreditRowFee
RowCreditingOptions
  • An object containing details of partial crediting of order rows.

  • This parameter can only be used to partially credit Invoice orders.

RowCreditingOptions

Response

ParameterDescriptionType
CreditIdID to identify each creditString

Response Code

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

Credit Row Fee

ParameterDescriptionType
ArticleNumberArticle number as a string.String

Name required

Article name.String

UnitPrice required

Price of the product including VAT.Long
VatPercent

The VAT percentage of the credit amount.
Allowed valid VAT percentage for different countries.

Long

Credit amount

Description

Call this endpoint to create a new credit with a specific amount. This endpoint can be called several times on the same order to credit different amounts.

The credit amount should not be larger than the delivered amount. The total credited amount should not be higher than the actual delivered amount.

Endpoint

Method: PATCH
/api/v1/orders/{CheckoutOrderId}/deliveries/{DeliveryId}/

Sample Code

Credit Order by Amount Example
using Microsoft.Extensions.DependencyInjection;
using System.Text.Json;
using System.Text;

internal static class CreditOrderAmount
{
internal static async Task CreditOrderAmountAsync(long checkoutOrderId, long deliveryId)
{
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/{1}", checkoutOrderId, deliveryId);


var creditRequest = new CreditAmountRequest(100);
var jsonString = JsonSerializer.Serialize(creditRequest);
var creditRequestJson = 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, creditRequestJson);

// 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 CreditAmountRequest(long CreditedAmount);
info

Available for Orders with Paymenttype Direct bank Card Vipps MobilePay Swish

Prerequisite

The delivery must have the action CanCreditAmount.

Request parameters

ParameterDescriptionType

CheckoutOrderId required

Checkout order ID of the specified order.Long

DeliveryId required

ID of the specified delivery.Long

CreditedAmount required

Amount to be credited.Long

Response

ParameterDescriptionType
CreditIdID to identify each creditString
ResultCodeNameIf the credit is success or pendingString

Response Code

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