# Accessing invoices and credit memos

For some transactions, Digital River automatically generates the [order invoice](#order-invoices) and [credit memo](#credit-memos) files that you can access and then share with your customers. To do this, you can implement nearly identical solutions.

To localize these files, set the [checkout's](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/checkouts) [`locale`](https://docs.digitalriver.com/digital-river-api/integration-options/checkouts/creating-checkouts/designating-a-locale).

For testing purposes, we also allow you to generate [mock order invoices and credit memos](#mock-order-invoices-and-credit-memos).

## Order invoices

In transactions assigned to one of the following [selling entities](https://docs.digitalriver.com/digital-river-api/integration-options/checkouts/creating-checkouts/selling-entities), Digital River generates an order invoice in PDF that you can share with customers:

* `Digital River, Inc.`
* `DR globalTech Inc.`
* `Digital River Ireland Ltd.`
* `Digital River UK`
* `DR Japan`

### How to access the invoice file

By [listening for the order invoice created event](#listening-for-the-order-invoice-created-event) or by [retrieving the order](#retrieving-the-invoice-file-identifier-from-the-order), you can get an invoice's file identifier and then use it to generate a shareable link.

You can also [download an invoice in Digital River Dashboard](https://docs.digitalriver.com/digital-river-api/administration/dashboard/order-management/orders/downloading-an-invoice).

{% hint style="info" %}
If an [order's ](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/orders)`totalAmount` is `0`, then Digital River doesn't generate a customer invoice.
{% endhint %}

#### Listening for the order invoice created event

You can be notified when the invoice is created by listening for the [event ](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/events)with a [`type`](https://docs.digitalriver.com/digital-river-api/events-and-webhooks-1/events-1#event-types) of [`order.invoice.created`](https://docs.digitalriver.com/digital-river-api/events-and-webhooks-1/events-1/event-types#order.invoice.created).

The event's [`data.object`](https://docs.digitalriver.com/digital-river-api/events-and-webhooks-1/events-1#event-data) contains an `id` and a `fileId`, both of which are identical and contain the invoice's [file ](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/files)identifier. You can use either to [create a publicly accessible link](#creating-a-publicly-accessible-link).

{% tabs %}
{% tab title="order.invoice.created" %}

```javascript
{
    "id": "c902f8aa-16fb-44ba-ba7b-f3c84061685a",
    "type": "order.invoice.created",
    "data": {
        "object": {
            "id": "6e5bf525-3907-40c5-86a9-f14ce4f33f35",
            "fileId": "6e5bf525-3907-40c5-86a9-f14ce4f33f35",
            "orderId": "188418250336",
            "customerId": "532736320336",
            "purpose": "customer_invoice",
            "invoiceURL": "https://api.digitalriver.com/files/6e5bf525-3907-40c5-86a9-f14ce4f33f35/content"
        }
    },
    "liveMode": false,
    "createdTime": "2021-04-28T02:04:13.591115Z",
    "versionIds": []
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
In the event's `data.object`, the `invoiceURL` can only be accessed with your [confidential (secret) API key](https://app.gitbook.com/s/ZrhMyLX5esFYS64lNWVW/digital-river-api-reference-guide/api-structure#confidential-keys). Since your customers won't be able to access the contents of this link, don't share it with them.
{% endhint %}

#### Retrieving the invoice file identifier from the order

To access the customer invoice file, you can also [retrieve the order](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/orders#orders-id-1).

Once invoices are generated, Digital River populates the [order's ](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/orders)`invoicePDFs[]`. If `invoicePDFs[]` doesn't exist, then the [file(s)](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/files) have yet to be created.

Each element of this array contains a [file's ](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/files)unique `id` and `url`.

You'll need to use `invoicePDFs[].id` to [create a publicly accessible link](#creating-a-publicly-accessible-link).

{% hint style="warning" %}
In the [order](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/orders), the `invoicePDFs[].url` can only be accessed with your [confidential (secret) API key](https://app.gitbook.com/s/ZrhMyLX5esFYS64lNWVW/digital-river-api-reference-guide/api-structure#confidential-keys). Since your customers won't be able to access the contents of this link, don't share it with them.
{% endhint %}

{% tabs %}
{% tab title="Order" %}

```javascript
{
    "id": "188418250336",
    ...
    "invoicePDFs": [
        {
            "id": "6e5bf525-3907-40c5-86a9-f14ce4f33f35",
            "url": "https://api.digitalriver.com/files/6e5bf525-3907-40c5-86a9-f14ce4f33f35/content",
            "liveMode": false
        }
    ],
    ...
}
```

{% endtab %}
{% endtabs %}

### Creating a publicly accessible link

To create a publicly accessible link to the invoice [file](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/files), assign its identifier to `fileId` and send it in the body of a [`POST /file-links`](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/file-links#file-links-1) request.

The response contains a `url` you can share with your customers by email, in their account management portals, or by another method of your choice.

## Credit memos

A credit memo is a document issued to customers notifying them of a reduced amount they owe.

### How to access the credit memo file

By [listening for the credit memo created event](#listening-for-the-credit-memo-created-event) or by [retrieving the order](#retrieving-the-credit-memo-file-identifier-from-the-order), you can get a credit memo's file identifier and then use it to generate a shareable link.

#### Listening for the credit memo created event

You can be notified when a credit memo is created by listening for the [event ](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/events)with a [`type`](https://docs.digitalriver.com/digital-river-api/events-and-webhooks-1/events-1#event-types) of [`order.credit_memo.created`](https://docs.digitalriver.com/digital-river-api/events-and-webhooks-1/events-1/event-types#order.credit_memo.created).

The event's [`data.object`](https://docs.digitalriver.com/digital-river-api/events-and-webhooks-1/events-1#event-data) contains an `id` and a `fileId`, both of which are identical and contain the credit memo's [file ](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/events)identifier. You can use either to [create a publicly accessible link](#creating-a-publicly-accessible-link-1).

{% tabs %}
{% tab title="order.credit\_memo.created" %}

```javascript
{
    "id": "d3786b5b-540b-4885-92a4-62f937d13f26",
    "type": "order.credit_memo.created",
    "data": {
        "object": {
            "id": "c233c10f-17e8-4799-a1ce-2469d042f29d",
            "fileId": "c233c10f-17e8-4799-a1ce-2469d042f29d",
            "orderId": "188466550336",
            "customerId": "532795950336",
            "purpose": "customer_credit_memo",
            "invoiceURL": "https://api.digitalriver.com/files/c233c10f-17e8-4799-a1ce-2469d042f29d/content"
        }
    },
    "liveMode": false,
    "createdTime": "2021-04-29T02:15:20.516626Z",
    "versionIds": []
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
In the event's `data.object`, the `invoiceURL` can only be accessed with your [confidential (secret) API key](https://app.gitbook.com/s/ZrhMyLX5esFYS64lNWVW/digital-river-api-reference-guide/api-structure#confidential-keys). Since your customers won't be able to access the contents of this link, don't share it with them.
{% endhint %}

#### Retrieving the credit memo file identifier from the order

To access a customer's credit memo file, you can also [retrieve the order](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/orders#orders-id).

Once credit memos are generated, Digital River populates the [order's ](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/orders)`creditMemoPDFs[]`. If `creditMemoPDFs[]` doesn't exist, then the [file(s)](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/files) have yet to be created.

Each element of this array contains a [file's ](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/files)unique `id` and `url`.

You'll need to use `creditMemoPDFs[].id` to [create a publicly accessible link](#creating-a-publicly-accessible-link-1).

{% hint style="warning" %}
In the [order](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/orders), the `creditMemoPDFs[].url` can only be accessed with your [confidential (secret) API key](https://app.gitbook.com/s/ZrhMyLX5esFYS64lNWVW/digital-river-api-reference-guide/api-structure#confidential-keys). Since your customers won't be able to access the contents of this link, don't share it with them.
{% endhint %}

{% tabs %}
{% tab title="Order" %}

```javascript
{
    "id": "188418250336",
    ...
    "creditMemoPDFs": [
        {
            "id": "fb50c8c2-8b32-4a3d-9947-dbdef12a5cdc",
            "url": "https://api.digitalriver.com/files/fb50c8c2-8b32-4a3d-9947-dbdef12a5cdc/content",
            "liveMode": false
        }
    ],
    ...
}
```

{% endtab %}
{% endtabs %}

### Creating a publicly accessible link

To create a publicly accessible link to a customer's credit memo [file](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/files), assign its identifier to `fileId` and send it in the body of a [`POST /file-links`](https://app.gitbook.com/s/x8fSFzVR3sg0TsNWwwVz/file-links#file-links-1) request.

The response contains a `url` you can share with your customers by email, in their account management portals, or by another method of your choice.

## Mock order invoices and credit memos

You can also generate the order invoice and credit memo files in [test mode](https://app.gitbook.com/s/ZrhMyLX5esFYS64lNWVW/digital-river-api-reference-guide/best-practices#test-mode). Accessing them is the same as in the production environment.

The following are example mock tax invoice and credit memo PDFs:

{% file src="<https://334437993-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LqH4RJfLVLuHPXuJyTZ%2F-MVMHOxyPPi4pryE9JwH%2F-MVMHyzq1f3aveCeHKnO%2Fvat-invoice.pdf?alt=media&token=ccc410d2-27f4-48d9-ace9-ab0e8166c5d2>" %}
Sample VAT invoice
{% endfile %}

{% file src="<https://334437993-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LqH4RJfLVLuHPXuJyTZ%2F-MVMHOxyPPi4pryE9JwH%2F-MVMIFqfiOZifgzWvuBZ%2Fcredit-memo.pdf?alt=media&token=dd0fe3d4-fe97-45db-b269-9c8e59e7eab1>" %}
Sample credit memo
{% endfile %}
