Skip to content

feat: Void and generate credit notes #3748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 52 commits into from
Jun 18, 2025

Conversation

brunomiguelpinto
Copy link
Contributor

@brunomiguelpinto brunomiguelpinto commented May 27, 2025

Context

This PR extends the invoice voiding logic to support optional credit note generation, with refund and credit amounts.

Originally, a confirm_void parameter was proposed to make the override explicit. After internal discussion, we decided to simplify the API: the presence of generate_credit_note is now considered an explicit intent to force the void.

This change preserves backwards compatibility while unlocking more powerful workflows.

Description

This pr adds support for the following parameters in the void_invoice mutation and endpoint:

{
  "generate_credit_note": true,
  "refund_amount": 2000,
  "credit_amount": 1150
}

If no parameters are passed → invoice must be voidable (as before).
If generate_credit_note parameter is passed → invoice is voided ( all types of invoices can now be voided )

Partial Credit Note + Remaining Voided Credit

When a credit note is generated with a refund_amount and/or credit_amount that does not cover the full invoice amount, the system will:

  1. Generate a first credit note with the specified refund_amount and credit_amount.
  2. Automatically generate a second credit note for the remaining amount, which is immediately voided.

This ensures that:

  • The entire invoice amount is covered across the two credit notes.
  • Only the explicitly requested amounts are usable (refunded or credited).
  • The remaining amount is voided and not usable by the customer, but still bookkept for completeness and compliance.

Example

Invoice total: €20 (2000 cents)
Request:

{
  "generate_credit_note": true,
  "refund_amount": 1000,
  "credit_amount": 500
}

The system will create:
✅ Credit Note 1: €10 refunded + €5 credited (usable)
🚫 Credit Note 2: €5 voided (not usable)

@brunomiguelpinto brunomiguelpinto self-assigned this Jun 2, 2025
@brunomiguelpinto brunomiguelpinto changed the title feat: void and generate credit note feat: Void and generate credit notes Jun 4, 2025
Copy link
Contributor

@floganz floganz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but I think we miss a lot of tests for these changes.

@brunomiguelpinto brunomiguelpinto force-pushed the feat-create-credit-note-on-void branch from e94b60c to 5958476 Compare June 9, 2025 22:51
@brunomiguelpinto brunomiguelpinto added Invoice Related to Invoices Credit Note Related to Credit Note labels Jun 9, 2025
@diegocharles diegocharles force-pushed the feat-create-credit-note-on-void branch from 2f8512e to 89973c2 Compare June 10, 2025 11:52
@brunomiguelpinto brunomiguelpinto merged commit 5d2ee63 into main Jun 18, 2025
14 checks passed
@brunomiguelpinto brunomiguelpinto deleted the feat-create-credit-note-on-void branch June 18, 2025 10:31
diegocharles added a commit that referenced this pull request Jul 11, 2025
## Context

This PR extends the invoice voiding logic to support optional credit
note generation, with refund and credit amounts.

Originally, a `confirm_void` parameter was proposed to make the override
explicit. After internal discussion, we decided to simplify the API: the
presence of `generate_credit_note` is now considered an explicit intent
to force the void.

This change preserves backwards compatibility while unlocking more
powerful workflows.

## Description

This pr adds support for the following parameters in the void_invoice
mutation and endpoint:

``` json
{
  "generate_credit_note": true,
  "refund_amount": 2000,
  "credit_amount": 1150
}
```
If no parameters are passed → invoice must be voidable (as before).
If generate_credit_note parameter is passed → invoice is voided ( all
types of invoices can now be voided )

**Partial Credit Note + Remaining Voided Credit**

When a credit note is generated with a refund_amount and/or
credit_amount that does not cover the full invoice amount, the system
will:

1. Generate a first credit note with the specified refund_amount and
credit_amount.
2. Automatically generate a second credit note for the remaining amount,
which is immediately voided.

This ensures that:

- The entire invoice amount is covered across the two credit notes.
- Only the explicitly requested amounts are usable (refunded or
credited).
- The remaining amount is voided and not usable by the customer, but
still bookkept for completeness and compliance.

Example

Invoice total: €20 (2000 cents)
Request:

```  json
{
  "generate_credit_note": true,
  "refund_amount": 1000,
  "credit_amount": 500
}
```

The system will create:
✅ Credit Note 1: €10 refunded + €5 credited (usable)
🚫 Credit Note 2: €5 voided (not usable)

---------

Co-authored-by: Diego Charles <diegocharles@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Credit Note Related to Credit Note Invoice Related to Invoices
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants