Live verification. Verified live on a test company (2026-11-11) with this release: selling gift certificates (including automatic numbering, required barcodes and expiry), redeeming them with cash change, forfeit and a credit-note change, marking certificates used, activating the change credit note, the recovery commands, and the refusals before any write; every test invoice ended fully settled. Not exercised live: the reference lookup after a failed invoice create, because no create failed.
GiftCertificateInvoiceOptions.Sell sells (issues) gift certificates on a new invoice, as the dkERP desktop does. It uses
the same entry point as redemption, Sales.Invoice.CreateWithGiftCertificatesAsync, alone or together with Redeem.
The general rules (posted invoice, unique reference of at most 12 characters) are on
Concepts and prerequisites.
// invoice.Reference is required and unique for the sale, for example "SALE-1008".
// The invoice needs no line of its own: each sale adds one.
var result = await dkPlus.Sales.Invoice.CreateWithGiftCertificatesAsync(
invoice,
new GiftCertificateInvoiceOptions
{
Post = true,
Sell = [new GiftCertificateSale { ItemCode = "GB", Amount = 10000m, Number = "1007", Barcode = "5690000001007" }]
},
cancellationToken);
GiftCertificate sold = result.Issued[0]; // valid, active, linked to the invoice and its line
GiftCertificateSale has ItemCode (required), Amount (required, with tax), and Number and Barcode (see below).
Selling alone reads no payment modes and takes no GiftCertificatePaymentId, Change or ChangePaymentId; they are
rejected without Redeem.
Sell and of the invoice's own Lines isInvalidOperationException before any write.Lines hold no gift-certificate item, positive or negative, because DK Plus has no paper logic andCreateAsync sends such aCreateWithGiftCertificatesAsync refuses it.) Sell with Sell, redeem with Redeem.OriginalPrices is refused with Sell: with it DK prices every line from the item, not at the certificate's amount.Settings: storage (dkPos is refused), whether DK assigns numbers andReference.Number is required unless the company assigns numbers (AssignNumbers). Then a sale without a number gets the next freeBarcode is required when the company assigns barcodes (AssignBarcodes). It is sent as the line memo and stored on*, =, , or ;.Each sale is one invoice line, shaped as the desktop shapes it: the item, quantity 1, the amount as the price with tax,
the number as the line reference, the barcode as the line memo, and the item's description followed by nr. <number> as
the text (for example Gjafabréf nr. 1007). DK keeps 40 characters of the text, so a long description is shortened to
leave room for the number. The sold lines follow the invoice's own lines, and they count towards the total that redeemed
certificates pay when you sell and redeem together. In that case each sold Amount must be a whole number of cents and the
invoice's own lines need explicit prices (see Redeeming).
A created total that differs from the computed one holds every sold certificate as AmountMismatch.
After the invoice exists, the client creates each certificate valid and active, with the customer, the sales person (when the
invoice sets one), the barcode, a start date of today, an end date of today plus ValidForDays when certificates expire,
and links to the invoice and to the line.
A certificate is created only when DK invoiced its line at the sale's Amount, to the cent. DK may reprice a line itself, and a
certificate worth more or less than was paid would be wrong either way. A line DK invoiced at another amount leaves the sale
pending with reason AmountMismatch and creates nothing; a sale whose line cannot be matched is pending as LineNotFound.
In both cases check the invoice in dkERP.
If another writer takes the number between the check and the insert, the sale is pending with kind CreateGiftCertificate and
reason Conflict. The invoice line already shows the number, so the client does not renumber: check the sale in dkERP.
Selling follows the same outcomes as redemption (Failures and recovery):
before the invoice request the original exception (an allocated number may be burnt); NotCreated: nothing is pending for the
sales; Unknown: each sale is a CreateGiftCertificate step that was not attempted, with its number but no
CreateRequest; Created: every sale is still attempted and a failed one is pending with the CreateRequest that
completes it, using Sales.GiftCertificate.CreateAsync.
devop-dk sales invoice create -c C-100 --reference SALE-1008 \
--sell-gift-certificate "item-code=GB;amount=10000;number=1007;barcode=5690000001007" --post --yes
--sell-gift-certificate takes key=value pairs separated by ; (repeat the option for more certificates). The keys are
item-code, amount, number and barcode; a double-quoted value may hold ; or =. The sale needs --reference and
--post --yes, and no payment id.
New-Invoice -Customer C-100 -Reference SALE-1008 `
-SellGiftCertificate @{ ItemCode = 'GB'; Amount = 10000; Number = '1007'; Barcode = '5690000001007' }
Selling a gift certificate on account leaves the sale invoice as an open receivable on the customer. To settle it at once, put
the buyer's ordinary payment on the same invoice: the sold line and the payment go to DK Plus in one invoice request, and the
invoice is created paid. Verified live on a test company: a sale with the payment on the same invoice ended settled
("Greiddur reikningur").
// invoice.Reference is required and unique for the sale; payment type 1 is the company's cash payment.
var sale = new SalesInvoiceCreateRequest
{
Customer = new DkPlusSalesDocumentParty { Number = "C-100" },
Reference = "SALE-1009",
Payments = [SalesInvoicePayment.Create(1, 500m)]
};
var result = await dkPlus.Sales.Invoice.CreateWithGiftCertificatesAsync(
sale,
new GiftCertificateInvoiceOptions
{
Post = true,
Sell = [new GiftCertificateSale { ItemCode = "GB", Amount = 500m, Number = "1009" }]
},
cancellationToken);
devop-dk sales invoice create -c C-100 --reference SALE-1009 \
--sell-gift-certificate "item-code=GB;amount=500;number=1009" --payment 1=500 --post --yes
New-Invoice -Customer C-100 -Reference SALE-1009 `
-SellGiftCertificate @{ ItemCode = 'GB'; Amount = 500; Number = '1009' } -Payment @{ Id = 1; Amount = 500 }
devop-dk payment type list or Get-PaymentType. In1 is a cash payment.--payment is repeatable and -Payment takes a list, for example to split the amount between cash and card.--payment and -Payment need version 0.13.1 of the CLI and the PowerShell module. With 0.13.0, put the payment in thePayments of an invoice file (--file, or New-Invoice -Path), as below; the library has carried Payments since 0.13.0.{
"customer": { "number": "C-100" },
"reference": "SALE-1009",
"payments": [ { "id": 1, "amount": 500 } ]
}
devop-dk sales invoice create --file invoice.json \
--sell-gift-certificate "item-code=GB;amount=500;number=1009" --post --yes
Next: Failures and recovery and the
cookbook.