Downloading the invoice

Learn how to download the invoice PDF file for an order.

An invoice represents a document associated with a sale you provide to the shopper. The invoice itemizes the products or services rendered, including their cost, quantity, fees, duties, and taxes. It also establishes an obligation on the part of the shopper to pay you for those products and services.

Invoices can be especially useful when selling to other businesses. For business transactions, it's often customary to send customers an invoice, which they pay later, rather than immediately billing a credit card you have on file.

This topic explains how to download the invoice PDF file.

Invoice PDF download scenarios

You can download the invoice PDF programmatically or from a webhook notification.

Downloading the invoice PDF programmatically

To download the invoice PDF programmatically, follow these steps:

Step 1: Getting the download information for the order's invoice

To get the download information for the order's invoice, make a GET request to /v1/orders/{orderId}/invoices. Replace {orderId} with the actual order ID. This request retrieves all downloadable invoice URLs (invoiceURL) for the order. Each invoice can be individually downloaded using the provided receiptId.

Example request:

curl --location --request GET 'https://api.digitalriver.com/v1/orders/{orderId}/invoices' \
--header 'authorization: basic ***'

Example 200 OK response:

{
    "invoices": [
        {
            "type": "vat_invoice",
            "invoiceURL": "https://api.digitalriver.com/v1/orders/1075294270082/invoices/{receiptId}"
        }
    ]
}

Step 2: Getting the receipt for the invoice

To retrieve the receipt for an invoice, you make a GET request to /v1/orders/{orderId}/invoices/{receiptId} request to download the invoice by its unique invoice identifier (receiptId) for a specified order (orderId):

curl --location --request GET 'https://api.digitalriver.com/v1/orders/{orderId}/invoices/{receiptId}' \
--header 'authorization: basic ***'

Replace {orderId} with the order's identifier and {receiptId} with the invoice's identifier. Ensure your 'authorization' header contains the correct basic auth credentials. You will receive a 200 OK response that includes the PDF file of the invoice:

Downloading the invoice PDF via a webhook notification

You must enable the following events when creating a webhook in Global Commerce before you can perform this task:

  • order.invoice.created: The creation of an order invoice triggers this event.

To retrieve the invoice PDF file, follow these steps:

  1. Wait for the order.invoice.created event: This event is triggered when an invoice file is created.

  2. Obtain the fileId: In the notification you receive, locate the "fileId" value. Here's an example snippet:

    "data": {
      "object": {
        "fileId": "9e00869b-e2f5-4663-aacb-e33687466020",
        ...
      }
    }
  3. Retrieve the Invoice PDF: Use the fileId obtained to fetch the invoice PDF by making a GET /files/{fileId}/content request as shown below:

    curl --location --request GET 'https://api.digitalriver.com/files/{fileId}/content' \
    --header 'Authorization: Basic<YourAuthCredentials>'

Replace {fileId} with the actual fileId value and <YourAuthCredentials> with your appropriate authorization header value.

{
  "id": "9e00869b-e2f5-4663-aacb-e33687466020",
  "fileName": "File Name"
}

By performing these steps, you will be able to download the invoice PDF file associated with the generated fileId.

Last updated