# Refunds from Salesforce

FinDock supports initiating refunds from Salesforce in addition to refunds initiated from PSPs. You can refund individual Payment records for an existing (receivable) installment. The refund amount can be less than or equal to the payment.

The Refunds from Salesforce feature is in a closed pilot. Please contact FinDock Support if you would like to participate.

**Pilot scope and limitations**

* Supported PSPs
  * Paya
* Supported sources
  * FinDock Standalone
  * Fundraising (NPC, EDU)


## Setting up Refunds from Salesforce

Refunds from Salesforce currently does not have any explicit setting in the FinDock Setup. However, please do note that the feature requires the FinDock Core Refunds Run permission set.

## Enabling refunds from Salesforce with Flows

Refunds can be initiated through an invocable action that requires a specific FinDock permission set.

To enable refunds:

1. Include the invocable action FinDock Initiate Refund in a custom Flow. The class includes the following parameters:
  * `paymentId`: Id of the originating Payment record to refund
  * `IdempotencyKey`: custom-generated idempotency key to prevent duplicate refund requests
  * `amount`: decimal amount to be refunded (less than or equal to originating payment amount)
  * `refundReason`: reason for refund (values of customizable picklist field Refund Reason)
  * `refundReference`: unique generated reference for tracking the refund payment
2. Assign the FinDock Core Refunds Run permission set (included in the FinDock Service Agent permission set group) to Salesforce users who handle refunds.


When the action is invoked, FinDock creates an inbound report to validate the refund parameters and create a new Refund record. Once validated, FinDock automatically makes callouts to the PSP to process the refund, updating the status of the Refund record and creating a new, negative Payment record for the successful refund. The refund-related notifications and actions are handled using inbound reports and [Guided Matching](/docs/reconciliation/what-is-guided-matching).

## Refunds with Fundraising as source

If you have customizations on top of the default Salesforce Gift Refund capabilities, please carefully test refunds in your unique context and flows to ensure everything works as expected.

If you are using [Fundraising as a source](/docs/source-connectors/introduction-to-findock-for-fundraising), processing refunds through FinDock automatically creates corresponding Gift Refund records. The Gift Refund records are created and updated based on the Guided Matching results from processed inbound reports.

Refunds triggered from FinDock automatically create a corresponding, linked Gift Refund record with the following mapping. Limitations on field updating only apply when a Gift Refund record in linked to a Refund record.

| Gift Refund | FinDock Refund | Sync | Comments |
|  --- | --- | --- | --- |
| Amount | Amount | One way | Can only be changed from the Refund record |
| Date | Created Date / Refund Date | One way | Create Date when initiated, Refund Date when completed |
| Reason | Refund Reason | Two way | Only synced if values are same |
| Status | Status | One way | Can only be changed from the Refund record |


FinDock uses the following status mapping between Refund and Gift Refund:

| Refund Status | Gift Refund Status |
|  --- | --- |
| Pending Processing | Initiated |
| Failed | Failed |
| Completed | Completed |


We recommend updating the Refund page layout to include a Gift Refund field to the Details tab so you can easily see the linked record from the Refund record.

Please also note that the Reason picklist on Gift Refund is restricted. Therefore, when setting up Refunds from Salesforce, you need to modify the Refund Reason picklist on the FinDock Refund object to match the Gift Refund Reason values.

## Refunds data model

The following ERD illustrates how the custom FinDock Refund object relates to other custom objects and Salesforce objects.

FinDock ERD with Refund
## Refund object

FinDock uses the custom Refund object (`cpm_Refunds__c`) to capture refunds. When the Refund record is created, FinDock makes callouts to the defined PSP and receives notifications that are processed as InBound Report records through Guided Matching.

| Field Name | Description |
|  --- | --- |
| Account | The account that requested the refund, taken from the related original Payment record. |
| Amount | The refund amount. This may be less than or equal to Amount of the Originating Payment record amount. |
| Contact | The contact that requested the refund, taken from the related original Payment record. |
| Comments | Optional free text field for a more detailed explanation of the refund event. This field can be used as input, for example, for later follow up as part of an internal review process. |
| Installment | Installment record related to the refund request. |
| Last Status Reason | Details about the latest Status update for the record, received from the PSP or provided by FinDock. |
| Original Payment Reference | Payment reference of the original payment being refunded, taken from the Payment record of the linked Installment record. |
| Originating Payment | The Payment record that represents the original receivable transaction to be refunded. |
| Refund Date | Date the refund was confirmed. |
| Payment Method | The payment method used to pay the refund. |
| Payment Processor | The payment processor used to process the refund transaction. |
| Processor Reference | Refund payment reference provided by the PSP. |
| Refund Type | Optional field that can be used to classify refunds. |
| Refund Reference | Final payment reference for the refund transaction. |
| Refund Reason | Customizable picklist of refund reasons. Default values include Customer request, Duplicate and Other. |
| Refund Payment | The Payment record that represents the refund transaction. |
| Status | Status of the refund transaction. Once the transaction is complete, the Refund record status is set to Completed, and a Payment record is created and linked to the Refund record. |
| Target | The target (merchant account) from which the refund payment is made. |