3. Add Invoices

Overview

This API documentation describes the addInvoice endpoint of the Paylink API, which allows merchants to generate invoices and receive payments online through the Paylink gateway. The merchant will send the payment URL to the customer through different channels or redirect them to the Paylink payment page.

Endpoint

POST /api/addInvoice

Request Headers

HeaderRequiredDescription
AuthorizationYesBearer token provided by Authentication Endpoint
Content-TypeYesIt must be set to application/JSON.
{
  "Authorization": "Bearer [id_token]",
  "accept": "application/json",
  "content-type": "application/json"
}

Request Body Parameters

Creating an invoice requires information on the new invoice, such as the amount, callback URL, and client email. The following table describes the body parameters.

ParameterTypeRequiredDescription
amountfloatYesThe total amount of the invoice. NOTE: Buyer will pay this amount regardless of the total amounts of the products' prices.
callBackUrlstringNoThe URL will be called when the payment is complete or canceled.
clientEmailstringNoThe email address of the client.
clientMobilestringYesThe mobile number of the client.
currencystringNoThe currency code of the invoice. The default value is SAR. (e.g., USD, EUR, GBP).
clientNamestringYesThe name of the client.
notestringNoA note for the invoice.
orderNumberstringYesA unique identifier for the invoice.
productsarrayYesAn array of product objects will be included in the invoice. See product object details below.
smsMessagestringNoThis option will enable the invoice to be sent to the client's mobile specified in clientMobile. The message of this SMS can have placeholder for dynamic content. The placeholders are:
- [CLIENT_NAME]: Name of the client.
- [TRANSACTION_NO]: Transaction number from Paylink of the invoice.
- [ORDER_NUMBER]: The order number of the invoice.
- [QR_URL]: The URL that display QR code of the invoice.
- [MOB_URL]: The URL of the simple invoice format for mobile devices.
- [SHORT_URL]: The short URL of the invoice.
- [AMOUNT]: The amount of the invoice.
- [WEB_URL]: The full URL of the invoice.

NOTE: The service requires additional aggrement with Paylink sales.
supportedCardBrandsArrayNoList of supported card brands. This list is optional. values are: [mada, visaMastercard, amex, tamara, stcpay, urpay]
displayPendingBooleanNoThis option will make this invoice displayed in my.paylink.sa

Product Object Details

ParameterTypeRequiredDescription
titlestringYesThe title of the product.
pricefloatYesThe price of the product.
qtyintYesThe quantity of the product.
descriptionstringNoA description of the product.
isDigitalboolNoSet to true if the product is digital.
imageSrcstringNoA URL to an image of the product.
specificVatfloatNoThe VAT rate for the product. This will override the default VAT rate for the invoice if set.
productCostfloatNoThe cost of the product. This will be used to calculate the profit margin for the merchant.

An example of the request is as follows:

{
  "amount": 100.0,
  "clientMobile": "0512345678",
  "clientName": "Mohammed Ali",
  "orderNumber": "123456789",
  "products": [
    {
      "title": "Book",
      "price": 50.0,
      "qty": 2,
      "description": null,
      "isDigital": false,
      "imageSrc": null,
      "specificVat": null,
      "productCost": null
    }
  ],
  "callBackUrl": "https://example.com",
  "cancelUrl": "https://example.com",
  "clientEmail": "[email protected]",
  "currency": "SAR",
  "note": "Test invoice",
  "smsMessage": "URL: [SHORT_URL], Amount: [AMOUNT]",
  "supportedCardBrands": ["mada", "visaMastercard", "amex", "tabby", "tamara", "stcpay", "urpay"],
  "displayPending": true
}

Success Response

If the add invoice request success. The response details are as follows:

ParameterTypeDescription
gatewayOrderRequestObjectThe invoice details were sent to the gateway. See details below.
amountFloatThe total amount of the invoice.
transactionNoStringThe gateway assigns the transaction number.
orderStatusStringThe status of the invoice.
paymentErrorsStringAny payment errors that occurred.
urlStringThe URL to the payment page.
qrUrlStringThe URL to the QR code image for the payment
checkUrlStringThe URL of the API can be used to check the status of the price. NOTE: Calling this URL must have a token in the header.
mobileUrlStringTHE URL for mobile devices.
successBooleanThis field indicates whether this endpoint operation is successful or not. NOTE: This is not the payment or order status. It is the endpoint for getting invoice details.
digitalOrderBooleanThis field indicates whether the order contains digital products or not.
foreignCurrencyRateFloatThis is about the foreign currency rate used in the transaction, if applicable. In addition, it includes the exchange rate related to the SAR currency.

Example of the response:

{
    "gatewayOrderRequest": {
        "amount": 5.0,
        "orderNumber": "MERCHANT-ANY-UNIQUE-ORDER-NUMBER-123123123",
        "callBackUrl": "https://www.example.com",
        "clientEmail": "[email protected]",
        "clientName": "Zaid Matooq",
        "clientMobile": "0509200900",
        "note": "This invoice is for VIP client.",
        "cancelUrl": null,
        "products": [
            {
                "title": "Hand bag",
                "price": 150.0,
                "qty": 1,
                "description": "Brown Hand bag leather for ladies",
                "isDigital": true,
                "imageSrc": "http://merchantwebsite.com/img/img1.jpg",
                "specificVat": null,
                "productCost": null
            }
        ],
        "supportedCardBrands": null,
        "currency": null,
        "smsMessage": null,
        "displayPending": null,
        "receivers": null,
        "partnerPortion": null,
        "metadata": null
    },
    "amount": 5.0,
    "transactionNo": "1707943132122",
    "orderStatus": "CREATED",
    "paymentErrors": null,
    "url": "https://paymentpilot.paylink.sa/pay/info/1707943132122",
    "qrUrl": "https://restpilot.paylink.sa/openApi/loadOrderQRCode/1707943132122",
    "mobileUrl": "https://paymentpilot.paylink.sa/pay/frame/1707943132122?n=Zaid%20Matooq&m=0509200900",
    "checkUrl": "https://restpilot.paylink.sa/api/getInvoice/1707943132122",
    "success": true,
    "digitalOrder": true,
    "foreignCurrencyRate": null,
    "paymentReceipt": null,
    "metadata": null
}

Failure Response:

If any failure occurred, the response details are as follows

ParameterTypeDescription
detailstringA detailed error message explaining the reason for the failure.
titlestringA short title for the error that summarizes the reason for the failure.
typestringA URL that identifies the type of error.
statusstringThe HTTP status code for the response.

Important Note

📘

Invoice minimum amount

The minimum invoice amount in the Paylink system is SAR 5.00.

🚧

Important use of GetInvoice in server side

Merchant's application must perform this endpoint on the server-side. Then send the resulting response to the client-side. If this endpoint is used in the client-side, then its result must be verified and confirmed using GetInvoice endpoint from the server-side to check the orderStatus equal to piad and the amount paid.

Try the endpoint

For more detail about the endpoint and to try it out, please click here.