gitlabEdit

๐Ÿ’ณCredit Note (Avoir)

Learn how to generate and dispatch credit notes through Docs-Dispatcher with complete end-to-end examples in 4 languages (curl, Node.js, PHP, Java).

Overview

This comprehensive recipe walks you through the complete credit note generation and dispatch workflow:

  1. Authenticate and set up Basic Authentication

  2. Prepare your credit note data with original invoice reference

  3. Validate the request (recommended safety check)

  4. Send the credit note to your accounting provider

  5. Handle the response and track status

By the end of this guide, you'll have working code to automatically generate and send credit notes (refunds, corrections, cancellations) to providers like Qonto, PennyLane, iPaidThat.

What You'll Learn

  • How to structure credit note requests for different providers

  • Reference original invoices correctly

  • Handle negative amounts and corrections

  • Best practices for validation before sending

  • Error handling strategies

  • Provider-specific credit note requirements

  • Complete working examples in 4 languages

Prerequisites

Before you begin:

  • Docs-Dispatcher account with email and password

  • At least one invoicing provider configured (Qonto, PennyLane, iPaidThat, or SuperPDP)

  • Template created in Templater (or use API to create one)

  • Original invoice ID/reference (the invoice you're crediting)

  • Basic understanding of REST APIs

circle-info

No provider configured yet? You can still test with the validation endpoint - it checks your request format without calling external APIs or charging credits.

What is a Credit Note?

A credit note (avoir in French) is a document that:

  • Cancels all or part of an invoice

  • Refunds amounts already paid

  • Corrects errors in original invoices

  • Adjusts prices or quantities

  • Credits customer accounts

Common scenarios:

  • Product returned by customer

  • Service not delivered as agreed

  • Pricing error on original invoice

  • Quantity correction

  • Discount applied retroactively

  • Invoice cancellation

Step 1: Authentication

Dispatcher API uses HTTP Basic Authentication. You'll need your Dispatcher account email and password for all API calls.

Setup Credentials

circle-info

No token management needed! Unlike JWT-based APIs, Basic Auth doesn't require separate authentication endpoints or token refresh. Your credentials are sent with each request.

Quick links:

Step 2: Prepare Credit Note Data

Structure your credit note data according to the CompositeRequest model. Credit notes require special fields to reference the original invoice.

Basic Credit Note Structure

Required Fields

Field
Type
Description

providerName

string

Provider to use: qonto, pennylane, ipaidthat, superpdp

documentType

string

Must be CREDIT for credit notes

template.id

number

Template ID from Templater (use credit note template)

template.data

object

Template variables (schema depends on template)

invoicing.originalInvoiceId

string

Provider's invoice ID being credited

Credit Note Specific Fields

Field
Type
Description

template.data.originalInvoice

object

Original invoice reference details

template.data.originalInvoice.number

string

Original invoice number

template.data.originalInvoice.id

string

Provider's invoice ID

template.data.reason

string

Reason for credit note

invoicing.creditReason

string

Structured reason code (see below)

Credit Reason Codes

Code
Description
When to Use

PRODUCT_RETURN

Product returned by customer

Physical goods returned

SERVICE_NOT_DELIVERED

Service not provided

Service cancelled or incomplete

PRICING_ERROR

Error in original pricing

Wrong price charged

QUANTITY_ERROR

Quantity correction needed

Wrong quantity invoiced

DISCOUNT_APPLIED

Retroactive discount

Price adjustment after invoice

INVOICE_CANCELLATION

Full invoice cancellation

Complete cancellation

OTHER

Other reason

Custom scenarios

Partial vs Full Credit

Partial Credit (some items/amounts):

Full Credit (entire invoice):

circle-info

Amounts in Credit Notes: Most providers expect positive amounts in credit notes (not negative). The document type CREDIT indicates these amounts should be subtracted from customer balance. Check your provider's specific requirements.

Before sending real credit notes, validate your request structure. This checks for errors without calling external providers or charging credits.

Why Validate?

  • Catch errors early (before external API calls)

  • Verify original invoice reference is correct

  • Free and fast (< 100ms response)

  • No risk of duplicate credit notes

  • Test during development

Validation Request

Validation Success Response

Validation Error Response

circle-check

More on validation:

Step 4: Send Credit Note (Real Dispatch)

Once validation passes, send the actual credit note by changing the endpoint from /validate to /invoicing.

Sync Mode (Default)

Synchronous mode waits for the provider to complete the operation and returns the full response immediately.

Success Response:

When to use sync mode:

  • User is waiting for result (interactive workflows)

  • Quick operations (expected completion < 30 seconds)

  • Simple error handling (errors returned immediately)

  • Testing and development

Asynchronous mode queues the request immediately and processes it in the background. You receive a webhook notification when complete.

Immediate Response:

More on execution modes:

Step 5: Handle Response

Process the dispatch response and handle errors gracefully.

Success Response Fields

Field
Description

success

true if dispatch succeeded

dispatchId

Unique dispatch identifier (use for tracking)

providerResponse.creditNoteId

Provider's credit note ID

providerResponse.originalInvoiceId

Original invoice reference

providerResponse.creditedAmount

Amount credited to customer

generatedDocument

Generated PDF document URL and metadata

metadata

Your custom tracking data (echoed back)

Error Response

Common Error Types

Error Type
Cause
Solution

validation_error

Invalid request format

Check required fields

invoice_not_found

Original invoice doesn't exist

Verify invoice ID

invoice_already_credited

Invoice already has credit note

Check existing credits

credit_exceeds_invoice

Credit amount > invoice amount

Reduce credit amount

authentication_error

Invalid/expired JWT

Refresh token

provider_error

Provider API error

Check provider error details

Complete Examples

Here are complete, runnable examples in 4 languages showing the full credit note workflow from authentication to dispatch.

curl (Complete Flow)

Node.js (Complete Flow)

PHP (Complete Flow)

Java (Complete Flow)

Provider-Specific Notes

Different invoicing providers have unique credit note features and requirements.

Qonto

Provider name: qonto

Credit Note Features:

  • Full and partial credit notes supported

  • Automatic linking to original invoice

  • Customer notification optional

  • Sandbox mode available for testing

Specific requirements:

  • Original invoice ID required (Qonto's invoice ID)

  • Credit note number must be unique

  • Cannot exceed original invoice amount

  • Customer email required if sending notification

Example:

PennyLane

Provider name: pennylane

Credit Note Features:

  • Comprehensive credit note support

  • Automatic Chorus Pro submission for e-invoices

  • Detailed reason tracking

  • Multiple credit notes per invoice

Specific requirements:

  • Product codes required for credited items

  • Detailed reason documentation

  • SIRET required for French B2B credits

  • Tax breakdown must match original

Example:

iPaidThat

Provider name: ipaidthat

Credit Note Features:

  • Standard credit note support

  • Invoice reference tracking

  • Customer balance adjustment

Specific requirements:

  • Original invoice number required

  • Credit note must not exceed original amount

  • Customer email required

SuperPDP

Provider name: superpdp

Credit Note Features:

  • E-invoice compliant credit notes

  • Automatic archiving

  • Legal documentation trail

Specific requirements:

  • Complete original invoice reference

  • Detailed justification required

  • SIRET/SIREN for French companies

Provider Comparison

Feature
iPaidThat
Qonto
PennyLane
SuperPDP

Credit Notes

โœ…

โœ…

โœ…

โœ…

Partial Credits

โœ…

โœ…

โœ…

โœ…

Multiple Credits

โœ…

โœ…

โœ…

โš ๏ธ Limited

E-Invoice Credits

โŒ

โœ…

โœ…

โœ…

Sandbox

โœ…

โœ…

โœ…

โœ…

Reason Tracking

โœ…

โœ…

โœ…

โœ…

Auto-linking

โœ…

โœ…

โœ…

โœ…

Error Handling

Common Credit Note Errors

1. Original Invoice Not Found

Cause: Invoice ID doesn't exist in provider

Solution:

  • Verify invoice ID is correct

  • Check invoice exists in provider

  • Ensure invoice belongs to same company

2. Credit Exceeds Invoice Amount

Cause: Credit total > original invoice total

Solution:

  • Reduce credit amount

  • Check calculation

  • Verify original invoice amount

3. Invoice Already Fully Credited

Cause: Invoice has already been fully credited

Solution:

  • Check existing credit notes

  • Calculate remaining crediteable amount

  • Adjust credit amount accordingly

Troubleshooting Common Issues

Issue 1: "Missing original invoice reference"

Symptoms:

  • Validation error on originalInvoiceId

  • Provider rejects credit note

Solutions:

  1. Include invoicing.originalInvoiceId in request

  2. Use provider's invoice ID (not your internal ID)

  3. Verify invoice exists before crediting

Issue 2: "Credit amount calculation mismatch"

Symptoms:

  • Provider rejects due to amount inconsistency

  • Tax calculation errors

Solutions:

  1. Ensure amounts are positive (not negative)

  2. Match tax rates from original invoice

  3. Use same rounding rules as invoice

Issue 3: "Duplicate credit note number"

Symptoms:

  • Provider error about existing credit note

  • Unique constraint violation

Solutions:

  1. Use unique credit note numbers

  2. Check existing credit notes first

  3. Implement retry with new number

Next Steps

Now that you know how to generate and send credit notes:

Core Concepts

Provider Documentation

Summary

You've learned how to:

  • โœ… Authenticate and obtain Basic Auth credentials

  • โœ… Structure credit note requests with original invoice references

  • โœ… Handle partial and full credits correctly

  • โœ… Validate requests before sending

  • โœ… Send credit notes in sync and async modes

  • โœ… Handle responses and errors gracefully

  • โœ… Implement complete workflows in 4 languages

  • โœ… Troubleshoot common credit note issues

Ready for production? Follow this checklist:

  1. Configure your provider credentials

  2. Create credit note templates in Templater

  3. Validate all requests before dispatch

  4. Implement error handling for invoice references

  5. Track existing credits to prevent over-crediting

  6. Use async mode for scalability

  7. Monitor credit note success rates

Happy crediting!

Last updated