3. Invoice-service

Integrate to PayEx Invoice service API 

Introduction

This API is used to create new invoices on existing customers

1615196225210-926.png

Each resource in the API corresponds to its own route. All routes are structured according to a specific standard, explained below

The below route is an example of a route towards resource1Id
lf-api.payex.com/ledger/{Subdomain}/v1/{LedgerNumber}/resource1/{resource1Id}

Route segmentDescription
SubdomainIn this part of the API it will be invoice-service
LedgerNumberThe ledger identifier/number at PayEx
InvoiceNoIdentifier of resource invoice

Routes that occurs in examples of this documentation will use the following identifiers

ResourceIdentifier
LedgerNumberXXX
InvoicesNNN

Invoices

This resource is used to create new invoices, both debit invoices and credit invoices

Batches of multiple invoices should be processed sequentially towards the API. Each API call is intended for the creation of a single invoice

Example of a new debit invoice

Request
POST /ledger/invoice-service/v1/XXX/invoices HTTP/1.1
Host: -
Authorization: Bearer <Token>
Content-Type: application/json

{
  "customerNo": "2992682",
  "invoiceNo": "0000003",
  "invoiceDate": "2021-05-15",
  "preferredDueDate": "2021-06-15",
  "externalInvoiceId": "900003",
  "currency": "NOK",
  "invoiceAddress": {
     "addressee": "Annie Testsson",
     "streetAddress": "Teststreet 1",
     "zipCode": "50000",
     "city": "Testcity",
     "coAddress": "CO Bengtsson",
     "countryCode": "SE"
   },
  "distribution": null,
  "invoiceReason": {
     "invoiceReasonCode": "CAS",
     "invoiceReasonDescription": "Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet"
   },
  "legalMonetaryTotal": {
     "payableAmount": 97.99,
     "vatInclusiveAmount": 98.01,
     "vatExclusiveAmount": 98.01
   },
  "referenceInfo": {
     "invoicePeriod": {
        "startDate": "2021-04-07",
        "endDate": "2021-04-25"
      },
     "deliveryInfo": {
        "deliveryDate": "2021-04-27",
        "deliveryAddress": {
           "addressee": "Namn på mottagre",
           "streetAddress": "Testgatan 789",
           "zipCode": "11111",
           "city": "Sthlm",
           "coAddress": "C/O Andersson",
           "countryCode": "SE"
         }
      },
     "purchaseOrderReference": "Lorem ipsum dolor sit amet",
     "salesOrderReference": "Lorem ipsum dolor sit amet",
     "buyerReference": "Lorem ipsum dolor sit amet",
     "invoicedObjectIdentifier": "Lorem ipsum do",
     "contractReference": "Lorem ipsum dolor sit amet",
     "despatchReference": "Lorem ipsum dolor sit amet",
     "receiptReference": "Lorem ipsum dolor sit amet",
     "tenderReference": "Lorem ipsum dolor sit amet",
     "projectReference": "Lorem ipsum dolor sit amet"
   },
  "InvoiceNote": "InvoiceNote-Text e Lorem ipsum dolor sit amet,  Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, ",
  "invoiceSpecification": {
     "inclVat": true,
     "roundingAmount": -0.01,
     "invoiceLines": [
         {
           "itemDescription": "Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet",
           "amount": 98.0,
           "datePeriod": {
              "StartDate": "2021-04-21",
              "EndDate": "2021-04-25"
            },
           "gTIN": "156789123",
           "itemObjectIdentifier": "itemObjectIdentifier",
           "quantity": 1,
           "unit": "ANN",
           "unitPrice": 98.0,
           "vatCategoryCode": "AE",
           "vatRate": 10
         },
         {
           "itemDescription": "Lorem ipsum dolor sit amet",
           "amount": 0.01
         }
      ],
     "invoiceVatSpecification": {
        "vatSubTotal": [
            {
              "taxableAmount": 98.01,
              "vatAmount": 0.0,
              "vatRate": 1,
              "vatCategoryCode": "Z"
            }
         ]
      },
     "taxCurrencyVatSpecification": {
        "vatSubTotal": [
            {
              "taxableAmount": 50.0,
              "vatAmount": 5.5,
              "vatRate": 1.0,
              "vatCategoryCode": "O"
            }
         ],
        "taxCurrencyCode": "GBP",
        "exchangeRate": 1.55
      },
     "taxReduction": {
        "taxReductionDescription": "Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet",
        "taxReductionAmount": 0.01
      }
   }
}

Example of a new credit invoice

Request
POST /ledger/invoice-service/v1/XXX/invoices HTTP/1.1
Host: -
Authorization: Bearer <Token>
Content-Type: application/json

{
  "customerNo": "2992682",
  "invoiceNo": "000004",
  "invoiceDate": "2021-05-17",
  "externalInvoiceId": "900004",
  "currency": "SEK",
  "invoiceAddress": {
     "addressee": "Annie Testsson",
     "streetAddress": "Teststreet 1",
     "zipCode": "50000",
     "city": "Testcity",
     "coAddress": "CO Bengtsson",
     "countryCode": "SE"
   },
  "distribution": null,
  "invoiceReason": {
     "invoiceReasonCode": "CAS",
     "invoiceReasonDescription": "Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet"
   },
  "legalMonetaryTotal": {
     "payableAmount": -88.0,
     "vatInclusiveAmount": -88.01,
     "vatExclusiveAmount": -88.01
   },
  "referenceInfo": {
     "invoicePeriod": {
        "startDate": "2021-04-07",
        "endDate": "2021-04-25"
      },
     "deliveryInfo": {
        "deliveryDate": "2021-04-27",
        "deliveryAddress": {
           "addressee": "Name of recipient",
           "streetAddress": "Teststreet 789",
           "zipCode": "11111",
           "city": "Testcity",
           "coAddress": "C/O Andersson",
           "countryCode": "SE"
         }
      },
     "purchaseOrderReference": "Lorem ipsum dolor sit amet",
     "salesOrderReference": "Lorem ipsum dolor sit amet",
     "buyerReference": "Lorem ipsum dolor sit amet",
     "invoicedObjectIdentifier": "Lorem ipsum do",
     "contractReference": "Lorem ipsum dolor sit amet",
     "despatchReference": "Lorem ipsum dolor sit amet",
     "receiptReference": "Lorem ipsum dolor sit amet",
     "tenderReference": "Lorem ipsum dolor sit amet",
     "projectReference": "Lorem ipsum dolor sit amet",
     "debitInvoiceReferences": [
         {
           "debitInvoiceReference": "InvoiceNo xxxx"
         }
      ]
   },
  "InvoiceNote": "Lorem ipsum dolor sit amet,  Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet",
  "invoiceSpecification": {
     "inclVat": true,
     "roundingAmount": 0.01,
     "invoiceLines": [
         {
           "itemDescription": "Description of item 1",
           "amount": -88.01
         }
      ],
     "invoiceVatSpecification": {
        "vatSubTotal": [
            {
              "taxableAmount": -88.01,
              "vatAmount": 0.0,
              "vatRate": 1,
              "vatCategoryCode": "Z"
            }
         ]
      },
     "taxCurrencyVatSpecification": {
        "vatSubTotal": [
            {
              "taxableAmount": 50.0,
              "vatAmount": 5.5,
              "vatRate": 1.0,
              "vatCategoryCode": "O"
            }
         ],
        "taxCurrencyCode": "GBP",
        "exchangeRate": 1.55
      }
   }
}
Response
HTTP/1.1 201 Created
Content-Type: application/json

{
   "invoice" : "..ledger/invoice/v1/XXX/invoices/NNN",
}

Get single "create-invoice" request

Request
GET /ledger/invoice-service/v1/XXX/invoices/NNN HTTP/1.1
Host: -
Authorization: Bearer <Token>
Content-Type: application/json
Response
POST /ledger/invoice-service/v1/XXX/invoices HTTP/1.1
Host: -
Authorization: Bearer <Token>
Content-Type: application/json

{
   "customerNo" : "900",
   "invoiceNo" : "0000001",
   "invoiceDate": "2021-05-15",
   "preferredDueDate": "2021-06-15",
   "externalInvoiceId": "900001",
   "currency": "SEK",
   "invoiceAddress": {
       "addressee": "Annie Testsson",
       "streetAddress": "Teststreet 1",
       "zipCode": "50000",
       "city": "Testcity",
       "coAddress": "CO Bengtsson",
       "countryCode": "SE"
    },
   "distribution": null,
   "invoiceReason": {
       "invoiceReasonCode": "CAS",
       "invoiceReasonDescription": "Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet"
    },
   "legalMonetaryTotal": {
       "payableAmount": 88.00,
       "vatInclusiveAmount": 98.01,
       "vatExclusiveAmount": 98.01
    },
   "referenceInfo": {
   "invoicePeriod": {
       "startDate": "2021-04-07",
       "endDate": "2021-04-25"
    },
   "deliveryInfo": {
       "deliveryDate": "2021-04-27",
       "deliveryAddress": {
           "addressee": "Namn på mottagre",
           "streetAddress": "Testgatan 789",
           "zipCode": "11111",
           "city": "Sthlm",
           "coAddress": "C/O Andersson",
           "countryCode": "SE"
      }
    },
   "purchaseOrderReference": "Lorem ipsum dolor sit amet",
   "salesOrderReference": "Lorem ipsum dolor sit amet",
   "buyerReference": "Lorem ipsum dolor sit amet",
   "invoicedObjectIdentifier": "Lorem ipsum do",
   "contractReference": "Lorem ipsum dolor sit amet",
   "despatchReference": "Lorem ipsum dolor sit amet",
   "receiptReference": "Lorem ipsum dolor sit amet",
   "tenderReference": "Lorem ipsum dolor sit amet",
   "projectReference": "Lorem ipsum dolor sit amet"
    },
   "InvoiceNote": "InvoiceNote-Text e Lorem ipsum dolor sit amet,  Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, ",
   "invoiceSpecification": {
       "inclVat": true,
       "roundingAmount": -0.01,
       "invoiceLines": [
            {
               "itemDescription": "Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet",
               "amount": 98.00,
               "datePeriod": {
                   "StartDate": "2021-04-21",
                   "EndDate": "2021-04-25"
                },
               "gTIN": "156789123",
               "itemObjectIdentifier": "itemObjectIdentifier",
               "quantity": 8,
               "unit": "ANN",
               "unitPrice": 10.00,
               "vatCategoryCode": "AE",
               "vatRate": 10
            },
            {
               "itemDescription": "Lorem ipsum dolor sit amet",
               "amount": 0.01
            }
        ],
       "invoiceVatSpecification": {
           "vatSubTotal": [
                {
                   "taxableAmount": 98.01,
                   "vatAmount": 0.00,
                   "vatRate": 1,
                   "vatCategoryCode": "Z"
                }
            ]
        },
       "taxCurrencyVatSpecification": {
           "vatSubTotal": [
                {
                   "taxableAmount": 50.00,
                   "vatAmount": 5.50,
                   "vatRate": 1.00,
                   "vatCategoryCode": "O"
                }
            ],
           "taxCurrencyCode": "GBP",
           "exchangeRate": 1.55
        },
        "taxReduction": {
           "taxReductionDescription": "Lorem ipsum dolor sit amet, Lorem ipsum dolor sit amet",
           "taxReductionAmount": 10
        }

    }
}

Invoice resource properties

For basic string properties, all characters included in "Basic Latin" and "Latin-1 Supplement" are generally supported unless otherwise stated in below table

PropertyData typeFormatRequiredDescription
customerNostringMinLength: 1
MaxLength: 15*
numeric, 1-9 
YesThe unique identifier of the customer
MaxLength may differ depending on configuration
KID (Norway)

invoiceNo

stringMaxlength: 15
Regex pattern:

[A-Za-z0-9\-]+

YesYour unique identifier/invoice number of the invoice
invoiceDatedateISO 8601Yes 
invoiceAddressobject No

Optional invoice address. Only used if different from customer name and legal address

    addresseestringMaxlength: 72YesFull name of addressee
    streetAddressstringMaxlength: 72NoStreet address
    zipCodestringMaxlength: 9YesZipcode conforming to country standard
    citystringMaxlength: 27YesCity
    coAddressstringMaxlength: 72NoCare of address
    countryCodestringISO 3166-1 alpha-2YesCountry code according to ISO 3166
preferredDueDatedateISO 8601No

Used if a specific duedate is preferred. Number of days between distributiondate, wich it set by PayEx based on invoicedate and processingdate, and preferred due date must exceed minimum payment terms for the specific country. Else minimum paymentterms for the country will be used. Number of days between distributiondate, which is set by PayEx based on invoicedate and processingdate, and preferred due date, can not exceed maximum paymentterms (default 60 days), if true an ERROR is created and the customer and its invoices will be rejected.

externalInvoiceIdstringMaxLength: 50
Regex pattern:
^[a-zA-Z0-9äåöÄÅÖ/_ -.]*$
NoAdditional external unique invoice identfier in accountsreceivable
distributionstring No
  • Postal
  • Email
  • EInvoiceB2B (some optional fields will be required if this is set*)
  • ArchiveOnly (available 2023-04-19)

If no distribution is set, default distribution priority order will apply.

currencystring YesValid currency supported in Your accountsreceivable

invoiceReason

object Yes 
  invoiceReasonCodestringUNCL7161NoInvoice reason code according to format UNCL7161
  invoiceReasonDescriptionstringMaxlength: 200YesDescription of the reason for the invoice

legalMonetaryTotal

object Yes

Contains total amount and currency of the invoice. Positive amount is used for debit invoice. Negative amount is used for credit invoice

   PayableAmountdecimalFraction digits: 2
Max size: 100000000
Min size: -100000000
YesTotal amount to by payed. LegalMonetary.VatInclusiveAmount + Invoicespecification.Roundingamount - InvoiceSpecification.TaxReductionAmount
   VatInclusiveAmountdecimalFraction digits: 2
Max size: 100000000
Min size: -100000000
YesTotal amount inclusive of Vat.  Equals sum of InvoiceSpecification.InvoiceVatSpecification.VatSubTotal.TaxableAmount + VatAmount
   VatExclusiveAmountdecimalFraction digits: 2
Max size: 100000000
Min size: -100000000
YesTotal amount exclusive of Vat. Equals sum of InvoiceSpecification.InvoiceVatSpecification.VatSubTotal.TaxableAmount

referenceInfo

object NoContaining invoice reference information
invoicePeriodobject NoOptional invoiceperiod. Used in EDI
      startDatedateISO 8601Yes 
      endDatedateISO 8601Yes 
deliveryInfoobject NoOptional deliveryinformation of product/service invoiced. Also used in EDI
      deliveryDatedateISO 8601No 
deliveryAddressobject Yes 
         addresseestringMaxlength: 72Yes 
         streetAddressstringMaxlength: 72No 
         zipCodestringMaxlength: 9Yes 
         citystringMaxlength: 27Yes 
         coAddressstringMaxlength: 72No 
        countryCodestringISO 3166-1 alpha-2Yes 
   purchaseOrderReferencestringMaxlength: 50NoOptional unique purchase order reference issued by the Buyer. Used in EDI
   salesOrderReferencestringMaxlength: 50NoOptional sales order reference issued by Seller. Used in EDI
   buyerReferencestringMaxlength: 50NoOptional reference of who ordered the products/services. Example being the name of the person ordering, employee number or a code identifying this person or department/group. Your ref is often used for internal routing at recipient, and hence it is important to fill this element with the correct values according to the need of the recipient. Used in EDI
   invoicedObjectIdentifierstringMaxlength: 50NoOptional identifier for an object on which the invoice is based, given by the Seller. Examples may be a subscription number, telephone number, meter point, vehicle, person etc., as applicable. Used in EDI
   contractReferencestringMaxlength: 50NoOptional reference to a purchase contract. Used in EDI
   despatchReferencestringMaxlength: 50NoOptional reference to a despatch advice. Used in EDI
   receiptReferencestringMaxlength: 50NoOptional reference to a receipt advice. Used in EDI
   tenderReferencestringMaxlength: 50NoOptional reference to the tenderer or lot, in most cases the Procurement Procedure Identifier. Used in EDI
   projectReferencestringMaxlength: 50NoOptional reference to a project. Used in EDI
   debitInvoiceReferenceslist NoIf creditinvoice, optional reference to debit invoice. Used in EDI
     debitInvoiceReferencestringMaxlength: 50YesReference to debit invoice
invoiceNotestringMaxlength: 250NoA textual note that gives unstructured information that is relevant to the Invoice as a whole

invoiceSpecification

object Yes

Contains the specification of the invoice

    inclVatbool YesIf True, invoiceLine.amount must include Vat. If False, invoiceLine.amount must exclude Vat. EDI-distribution requires an excl vat InvoiceSpecification
    roundingAmountdecimalFraction digits: 2
Max size: 0.99
Min size: -0.99
NoRoundingamount  +- 0.99
not affected by VAT

invoiceLines

list Yes 
        itemDescriptionstringMaxlength: 250YesMandatory description of the invoiced item/service
        amountdecimal YesMandatory amount rounded to two decimals. inclusive or exclusive of vat dependends of setting of the boolean attribute Invoicespecification.InclVat
Sum of the amounts of all invoiceLines must equal to legalMonetaryTotal.VatInclusiveAmount or VatExclusiveAmount, depending on Invoicespecification.InclVat true/false.
datePeriodobject NoOptional date/period
            startDatedateISO 8601Yes 
            endDatedateISO 8601No 
        gtinstringMaxlength: 15NoOptional global trade item identifier (GS1 GTIN)
        itemObjectIdentifierstringMaxlength: 50NoOptional identifier for an object on which the invoiceitem is based, given by the Seller. Examples may be a subscription number, telephone number, meter point, vehicle, person etc., as applicable. Used in EDI
        quantitydecimalFraction digits: 5
Max size: 100000000
Min size: -100000000
No**This field is required if distribution is set to EInvoiceB2B
Optional quantity with up to 5 decimals
        unitstringUNECERec20 No*

*This field is required if distribution is set to EInvoiceB2B
Optional unit of quantity according to UNECERec20 code list:

  • C62 - Used for unit-less count (pcs)
  • KGM - Kilogram
  • GRM - Gram
  • AD - Byte
  • 2P - Kilobyte
  • 4L - Megabyte
  • E34 - Gigabyte
  • E35 - Terabyte
  • SEC - Seconds
  • MIN - Minutes
  • DAY - Day
  • WEE - Week
  • MON - Month
  • ANN - Year
        unitPricedecimalFraction digits: 5
Max size: 100000000
Min size: 0
No**This field is required if distribution is set to EInvoiceB2B
Optional unitprice with up to 5 decimals.  Inclusive or exclusive of vat dependent of setting of the boolean attribute Invoicespecification.InclVat
        vatCategoryCodestring NoOptional VatCategoryCode according to UN/CEFACT code list 5305, D.16B
  • AE - VAT Reverse Charge: Code specifying that the standard VAT rate is levied from the invoicee
  • - Exempt from tax: Code specifying that taxes are not applicable
  • - Standard rate: Code specifying the standard rate
  • Z - Zero rated goods: Code specifying that the goods are at a zero rate
  • G - Free export item, tax not charged: Code specifying that the item is free export and taxes are not charged
  • O - Services outside scope of tax: Code specifying that taxes are not applicable to the services
  • K - VAT exempt for EEA intra-community supply of goods and services. A tax category code indicating the item is VAT exempt due to an intra-community supply in the European Economic Area
        vatRatedecimalFraction digits: 2
Max size: 100.00
Min size: 0.00
NoOptional valid VatRate

invoiceVatSpecifications

object YesIs specified once per distinct combination of VatCategoryCode and VatRate. Each combination must match sum of corresponding InvoiceLines
    vatSubTotallist YesVatSubTotal is specified once per combination of VatCategoryCode and VatRate
       taxableAmountdecimalFraction digits: 2
Min size: -100000000
Max size: 100000000
Yes 
       vatAmountdecimalFraction digits: 2
Min size: -100000000
Max size: 100000000
Yes 
       vatRatedecimalpercentage
min: 0.00
max: 100.00
YesvatRate in percentage
       vatCategoryCodestring Yes

Valid values:

  • AE - VAT Reverse Charge: Code specifying that the standard VAT rate is levied from the invoicee
  • - Exempt from tax: Code specifying that taxes are not applicable
  • - Standard rate: Code specifying the standard rate
  • Z - Zero rated goods: Code specifying that the goods are at a zero rate
  • G - Free export item, tax not charged: Code specifying that the item is free export and taxes are not charged
  • O - Services outside scope of tax: Code specifying that taxes are not applicable to the services
  • K - VAT exempt for EEA intra-community supply of goods and services. A tax category code indicating the item is VAT exempt due to an intra-community supply in the European Economic Area

taxCurrencyVatSpecification

object NoUsed if seller tax currency is other than invoice currency
vatSubTotallistrequired 1-10 itemsYesVatSubTotal is specified once per combination of VatCategoryCode and VatRate
            taxableAmountdecimalamountYes 
            vatAmountdecimalamountYes 
            vatRatedecimalpercentage
min: 0.00
max: 100.00
YesvatRate in percentage
            vatCategoryCodestring Yes

Valid values:

  • AE - VAT Reverse Charge: Code specifying that the standard VAT rate is levied from the invoicee
  • - Exempt from tax: Code specifying that taxes are not applicable
  • - Standard rate: Code specifying the standard rate
  • Z - Zero rated goods: Code specifying that the goods are at a zero rate
  • G - Free export item, tax not charged: Code specifying that the item is free export and taxes are not charged
  • O - Services outside scope of tax: Code specifying that taxes are not applicable to the services
  • K - VAT exempt for EEA intra-community supply of goods and services. A tax category code indicating the item is VAT exempt due to an intra-community supply in the European Economic Area
    taxCurrencyCodestring YesThe tax currency code of the seller
    exchangeRatedecimalFraction digits: 5
Min size: 0.00001
YesExchangeRate used to calculate vat in seller tax currency
taxReductionobject NoTaxreduction used for Reversed Tax and ROT/RUT
    taxReductionDescriptionstringMaxlength: 250Yes 
    taxReductionAmountdecimalFraction digits: 2
Min size: 0,01
Max size: 100000000
Yes 

Problems

All errors from the api are returned in the form of "problems" (response body), except for the http status code itself.
The problem object contain more detailed info on what the error is. The "type" property can be used to programmatically interpret the error as it contains a code definition of the problem.
Other properties can be useful for logging and subsequent troubleshooting. Some problems are extended with additional parameters so it may be a good idea to log response body as raw data to include these.

Problems of type validation does contain an additional list ("Problems") that describes exactly which parameter that failed the validation

Example

Response
HTTP/1.1 400 Error
Content-Type: application/problem+json

{
  "Type" : "ledger/invoice-service/v1/problems/validation",
  "Title" : "A validation error occurred",
  "Status" : 400,
  "Instance" : "215d4206-ca35-4f43-85ad-169c8f6d4ec1",
  "Detail" : "A validation error occurred. Please fix the problems mentioned in the 'problems' property below.",
  "Problems" : [
      {
        "amount" : "Expected value between [0,01]-[79228162514264337593543950335] actual [0]"
      }
   ]
}

Problem types

Note, each problem typecode is preceded by "ledger.invoice-service." in this API, e.g. the error "validation" in the table below will appear as typecode "ledger.invoice-service.validation".

Problem type (code)HttpstatusDescription
validation400occurs if any of the inputvalidation fails, it is described in the problem which parameter that failed the validation
invoice-not-found404 
Created by Fredrik Nilsson on 2021/06/29 16:24