This guide covers how to implement refunds using Conductor’s QuickBooks Desktop API. We’ll cover two main scenarios:

  1. Invoice-based refunds (full or partial)
  2. Custom refunds (not linked to any invoice)

Invoice-based refund

For invoice-based refunds, you will create a credit memo and then apply it to the relevant invoice using a receive payment transaction to reduce the outstanding balance.

Step 1: Create the credit memo

First, create a credit memo for the customer for the amount you wish to refund. This credit memo can be for the full or partial amount of the invoice.

Here’s an example of how to create a credit memo:

const creditMemo = await conductor.qbd.creditMemo.add("{{END_USER_ID}}", {
  CustomerRef: {
    ListID: "customer_list_id", // Customer's ListID from the original invoice
  },
  TxnDate: "2024-10-23", // Current date
  RefNumber: "REFUND-123", // Optional: Your reference number
  Memo: "Refund for Invoice INV-001", // Add a memo for reference
  CreditMemoLineAdd: [
    {
      ItemRef: {
        ListID: "item_list_id", // Original item from the invoice
      },
      Desc: "Refund for Invoice #123",
      Quantity: 1, // Quantity being refunded
      Amount: "50.00", // Amount being refunded for the item
    },
  ],
});

Step 2: Apply the credit memo to the invoice

Next, apply the credit memo to the outstanding invoice using a receive payment request. This will reduce the balance of the invoice by the credit amount.

Here’s an example of how to apply the credit:

const receivePayment = await conductor.qbd.receivePayment.add(
  "{{END_USER_ID}}",
  {
    CustomerRef: {
      ListID: "customer_list_id", // Must match the customer from credit memo
    },
    TotalAmount: "0.00", // No new payment being received
    Memo: "Applying credit memo to invoice",
    AppliedToTxnAdd: {
      TxnID: "original_invoice_txn_id", // Original invoice's TxnID
      PaymentAmount: "0.00", // No payment being made
      SetCredit: {
        CreditTxnID: creditMemo.TxnID, // TxnID from the credit memo we just created
        AppliedAmount: "50.00", // Amount of credit to apply
      },
    },
  },
);

Custom refund (not linked to any invoice)

For a custom refund not linked to any specific invoice, simply create a credit memo to record the amount owed to the customer.

Here’s an example of how to create a custom credit memo:

const standaloneCreditMemo = await conductor.qbd.creditMemo.add(
  "{{END_USER_ID}}",
  {
    CustomerRef: {
      ListID: "customer_list_id", // Required: Customer's ListID
    },
    TxnDate: "2024-10-23", // Current date
    RefNumber: "REFUND-124", // Optional: Your reference number
    Memo: "Goodwill refund",
    CreditMemoLineAdd: [
      {
        ItemRef: {
          ListID: "refund_item_list_id", // Use a specific item for refunds
        },
        Desc: "Customer satisfaction refund",
        Amount: "75.00", // Refund amount
      },
    ],
  },
);

Common scenarios

Partial refund

Modify the CreditMemoLineAdd.Amount to match the partial refund amount:

CreditMemoLineAdd: [
  {
    ItemRef: { ListID: "item_list_id" },
    Desc: "Partial refund - 50%",
    Amount: "25.00", // Half of the original amount
  },
];

Multiple item refund

Use multiple CreditMemoLineAdd entries:

CreditMemoLineAdd: [
  {
    ItemRef: { ListID: "item1_list_id" },
    Desc: "Refund - Item 1",
    Amount: "30.00",
  },
  {
    ItemRef: { ListID: "item2_list_id" },
    Desc: "Refund - Item 2",
    Amount: "20.00",
  },
];