Process a large number of refunds
If you need to regularly process a large number of refunds, you can create a workflow to automate the processing logic. In this article, we'll create a workflow to process refunds based on an uploaded list of invoices.
Exported JSON of the workflow
You can create a copy of the workflow that we introduce in this topic by copying the JSON code in bulk_refund_processing.json and paste it into a blank workflow. Alternatively, you can create a blank workflow and manually add in tasks and configure the settings based on the information in this article.
To learn about how to create a copy of a workflow, see Create a Copy of a Workflow.
Prerequisites
- We assume that you have the list of invoices that you want to refund. The list of invoice IDs and corresponding refund comments are saved into a CSV file.
- Because we'll use credit memos to process refunds, you need to enable Invoice Settlement for this workflow to run successfully.
Workflow overview
To start, you need to define an input field for the uploaded file using the following settings.
- Object: Files
- Field Name: InvoiceRefund. If you use a different field name, you need to revise the conditions in the queries.
- Required: Yes
- Datatype: File-Field
The workflow consists of 10 tasks. Callout tasks are used to process operations that are related to credit memos.
- Iterate: Iterates the uploaded CSV file of invoices.
- Query: Retrieves Account ID, Amount, Balance, Invoice ID, Invoice Number, and Payment Amount from the Invoice object.
- Query: Retrieves Default Payment Method ID from the Account object based on the account ID retrieved in task 2.
- Query: Retrieves Payment Method Name from the PaymentMethod object based on the default payment ID retrieved in task 3.
- Query: Retrieves Invoice ID, Charge Amount, and Charge ID from the Invoice Item object based on the invoice ID obtained in task 2.
- Callout: Creates a credit memo based on the data obtained from tasks 2 and 5.
- Callout: Posts the credit memo that is created in task 6.
- Callout: If task 7 succeeds, refunds the credit memo using the data retrieved in tasks 2, 3, and 7.
- If: If task 7 fails, verifies if the credit memo is still in Draft status by checking the error code returned from task 7.
- Callout: If the credit memo is in Draft status, cancels the credit memo.
Configurations
Please view detailed task configurations in your copy of the workflow. You can customize the settings.
- If the effective date of the credit memo is not the day when the workflow is run, you can change the value of the 'effectiveDate' to a specific date in the body of the create credit memo task (task 6).
- If the input field name or the data structure of your CSV file is different, you need to modify the liquid statements in the conditions of the query tasks.
For example, we use the following condition in task 2 to find corresponding invoice data.InvoiceNumber = '{{Data.InvoiceRefund.Invoice.InvoiceNumber}}'
If your input field for the file is 'Refund' and 'InvoiceNumber' (not Invoice.InvoiceNumber) is the field name in your CSV file, then you need to use this condition instead.InvoiceNumber = '{{Data.Refund.InvoiceNumber}}'
This also applies to the refund comment field that is used in the refund credit memo task (task 8).