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
/api/v1/orders/{CheckoutOrderId}/deliveries/{DeliveryId}/credits/
Sample Code
- C#
- Request
- Response
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; }
}
{
"OrderRowIds": [
1
],
"RowCreditingOptions": [
{
"OrderRowId": 1,
"Quantity": 100
}
]
}
{
"CreditId": 194281000040
}
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
Parameter | Description | Type |
---|---|---|
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 |
| RowCreditingOptions |
Row Crediting Options
Parameter | Description | Type |
---|---|---|
OrderRowId | Order row ID. | Long |
Quantity |
| Long |
Response
Parameter | Description | Type |
---|---|---|
CreditId | ID to identify each credit | String |
ResultCodeName | If the credit is success or pending | String |
Response Code
Code | HttpStatusCode | Description |
---|---|---|
202 | Accepted | Credit 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. |
Credit new order row
Description
Call this endpoint to credit an order by adding a new order row with a credit amount.
Endpoint
/api/v1/orders/{CheckoutOrderId}/deliveries/{DeliveryId}/credits/
Sample Code
- C#
- Request
- Response
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);
{
"NewCreditOrderRow": {
"OrderRowId": 0,
"ArticleNumber": "string",
"Name": "string",
"Quantity": 0,
"UnitPrice": 0,
"DiscountPercent": 0,
"DiscountAmount": 0,
"VatPercent": 0,
"Unit": "string",
"IsCancelled": true,
"Actions": [
"string"
]
},
"NewCreditOrderRows": [
{
"OrderRowId": 0,
"ArticleNumber": "string",
"Name": "string",
"Quantity": 0,
"UnitPrice": 0,
"DiscountPercent": 0,
"DiscountAmount": 0,
"VatPercent": 0,
"Unit": "string",
"IsCancelled": true,
"Actions": [
"string"
]
}
]
}
{
"CreditId": 194281000040
}
Available for Orders with Paymenttype InvoicePaymentplan Account Credit
Prerequisite
The delivery must have the action CanCreditNewRow.
Request parameters
Parameter | Description | Type |
---|---|---|
CheckoutOrderId required | Checkout order ID of the specified order. | Long |
DeliveryId required | ID of the specified delivery. | Long |
NewCreditOrderRow | The new credit row. | CreditOrderRow |
NewCreditOrderRows | Use this if crediting multiple new rows | List of CreditOrderRow |
Response
Parameter | Description | Type |
---|---|---|
CreditId | ID to identify each credit | String |
ResultCodeName | If the credit is success or pending | String |
Response Code
Code | HttpStatusCode | Description |
---|---|---|
202 | Accepted | Credit 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. |
Credit Order Row
Parameter | Description | Type |
---|---|---|
ArticleNumber | Article Number | String |
Name required | Credit Article name. | String |
UnitPrice required | Article amount including VAT. | Long |
VatPercent | The VAT percentage of the credit amount. | Long |
DiscountPercent | The discount percent of the product. | Long |
DiscountAmount | The discount amount of the product. | 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
/api/v1/orders/{CheckoutOrderId}/deliveries/{DeliveryId}/credits/CreditWithFee
Sample Code
- C#
- Request
- Response
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; }
}
{
"OrderRowIds": [
0
],
"Fee": {
"ArticleNumber": "string",
"Name": "string",
"UnitPrice": 0,
"VatPercent": 0
},
"RowCreditingOptions": [
{
"OrderRowId": 0,
"Quantity": 0
}
]
}
{
"CreditId": 194281000040
}
Available for Orders with Paymenttype Invoice
Prerequisite
The delivery must have the action CanCreditOrderRows.
The order rows must have the action CanCreditRow.
Request parameters
Parameter | Description | Type |
---|---|---|
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 |
Fee | An object containing the fee details of the credit.. | CreditRowFee |
RowCreditingOptions |
| RowCreditingOptions |
Response
Parameter | Description | Type |
---|---|---|
CreditId | ID to identify each credit | String |
Response Code
Code | HttpStatusCode | Description |
---|---|---|
202 | Accepted | Credit 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. |
Credit Row Fee
Parameter | Description | Type |
---|---|---|
ArticleNumber | Article 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. | 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
/api/v1/orders/{CheckoutOrderId}/deliveries/{DeliveryId}/
Sample Code
- C#
- Request
- Response
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);
{
"CreditedAmount": 0
}
{
"CreditId": 194281000040
}
Available for Orders with Paymenttype Direct bank Card Vipps MobilePay Swish
Prerequisite
The delivery must have the action CanCreditAmount.
Request parameters
Parameter | Description | Type |
---|---|---|
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
Parameter | Description | Type |
---|---|---|
CreditId | ID to identify each credit | String |
ResultCodeName | If the credit is success or pending | String |
Response Code
Code | HttpStatusCode | Description |
---|---|---|
202 | Accepted | Credit 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. |