> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wepayout.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Change Fee Target Account

> Transfer Cashout fee from one account to another within the same customer domain

This endpoint allows the transfer of a Cashout fee (Payout/Cashout fee) to another account within the same customer domain. This functionality is useful when fee charges need to be reallocated between internal accounts belonging to the same customer (e.g., between segregated wallets or cost centers).

## Business Rules

<Warning>
  **Important Restrictions**:

  * The target account must belong to the same customer domain as the original account
  * After the transfer, the fee becomes exclusively associated with the new account, but it remains linked to the originating entity of the fee
  * Fees related to Payin/Cashin transactions are not affected by this functionality — they will continue to be charged to the originating account (i.e., the account where the Cashin occurred)
</Warning>

<Note>
  **Note**: This setting only defines which wallet will be charged the merchant fee, but it does not change the operational model (prepaid or postpaid) of the merchant itself.
</Note>

### Prepaid Model

The destination wallet must have sufficient balance at the time of the fee charge.

### Postpaid Model

The destination wallet does not need to have sufficient balance, but all fees will be consolidated and invoiced monthly by the WEpayments finance team.

## About Removing This Setting

<Info>
  **Update as of 2023-06-11**: Currently, this removal cannot be performed via API. If you need to remove this configuration, please contact our CA team to request the change. In the coming weeks, new account management endpoints will be made available to support this functionality, eliminating the need to open a support ticket with our CA team.
</Info>

## Path Parameters

<ParamField path="merchantId" type="string" required>
  Merchant ID
</ParamField>

## Request Body

<ParamField body="merchant_fee" type="integer" required>
  Provide the ID of the account that should receive the fees from the account you are updating (the account specified in the endpoint path).

  **Important**: Your "Free fee" to be charged to the destination account should be posted to the fee wallet.
</ParamField>

<ParamField body="fee_wallet" type="boolean">
  Indicate "true" if the fee to be charged to the destination account should be posted to the fee wallet.
</ParamField>

## Response

<ResponseField name="id" type="integer">
  Account ID
</ResponseField>

<ResponseField name="merchant_id" type="integer">
  Merchant ID
</ResponseField>

<ResponseField name="recipient_id" type="integer or null">
  Recipient ID
</ResponseField>

<ResponseField name="currency_id" type="integer">
  Currency ID
</ResponseField>

<ResponseField name="account_fee" type="object or null">
  Account fee configuration
</ResponseField>

<ResponseField name="id" type="integer">
  Fee configuration ID
</ResponseField>

<ResponseField name="merchant_id" type="integer">
  Merchant ID
</ResponseField>

<ResponseField name="currency_id" type="integer">
  Currency ID
</ResponseField>

<ResponseField name="use_fee_billing" type="boolean">
  Whether fee billing is enabled
</ResponseField>

## Request Example

<CodeGroup>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.sandbox.wepayout.com.br/v2/account/{merchantId}/fee-target \
    --header 'Accept: application/json' \
    --header 'Authorization: Bearer {token}' \
    --header 'Content-Type: application/json' \
    --data '{
      "merchant_fee": 1234,
      "fee_wallet": true
    }'
  ```

  ```javascript JavaScript theme={null}
  const merchantId = 'your_merchant_id';

  const response = await fetch(
    `https://api.wepayments.com/v2/account/${merchantId}/fee-target`,
    {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        merchant_fee: 123,
        fee_wallet: true
      })
    }
  );

  const data = await response.json();
  console.log('Fee target updated:', data);
  ```

  ```python Python theme={null}
  import requests

  merchant_id = 'your_merchant_id'

  url = f'https://api.wepayments.com/v2/account/{merchant_id}/fee-target'
  headers = {
      'Accept': 'application/json',
      'Authorization': 'Bearer YOUR_TOKEN',
      'Content-Type': 'application/json'
  }
  data = {
      'merchant_fee': 123,
      'fee_wallet': True
  }

  response = requests.post(url, headers=headers, json=data)
  result = response.json()

  print(f"Fee target updated: {result}")
  ```
</CodeGroup>

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "id": 0,
    "merchant_id": 0,
    "recipient_id": 0,
    "currency_id": 0,
    "account_fee": {
      "id": 0,
      "merchant_id": 0,
      "currency_id": 0,
      "use_fee_billing": true
    }
  }
  ```

  ```json 401 Unauthorized theme={null}
  {
    "error": "Unauthorized"
  }
  ```

  ```json 500 Internal Server Error theme={null}
  {
    "error": "Internal server error"
  }
  ```
</ResponseExample>

## Use Cases

<AccordionGroup>
  <Accordion title="Centralize Fee Management">
    Route all fees to a dedicated fee management account:

    ```javascript theme={null}
    async function centralizeFees(merchantId, feeAccountId) {
      const response = await fetch(
        `https://api.wepayments.com/v2/account/${merchantId}/fee-target`,
        {
          method: 'POST',
          headers: {
            'Authorization': 'Bearer YOUR_TOKEN',
            'Content-Type': 'application/json'
          },
          body: JSON.stringify({
            merchant_fee: feeAccountId,
            fee_wallet: true
          })
        }
      );
      
      return await response.json();
    }

    // Route all fees from account 456 to central fee account 789
    await centralizeFees(456, 789);
    ```
  </Accordion>

  <Accordion title="Cost Center Allocation">
    Allocate fees to specific cost centers:

    ```javascript theme={null}
    async function allocateFeesToCostCenter(accounts, costCenterId) {
      const results = [];
      
      for (const accountId of accounts) {
        const result = await fetch(
          `https://api.wepayments.com/v2/account/${accountId}/fee-target`,
          {
            method: 'POST',
            headers: {
              'Authorization': 'Bearer YOUR_TOKEN',
              'Content-Type': 'application/json'
            },
            body: JSON.stringify({
              merchant_fee: costCenterId,
              fee_wallet: true
            })
          }
        );
        
        results.push({
          accountId,
          status: result.status,
          data: await result.json()
        });
      }
      
      return results;
    }

    // Allocate fees from multiple accounts to cost center
    const accounts = [101, 102, 103];
    await allocateFeesToCostCenter(accounts, 999);
    ```
  </Accordion>

  <Accordion title="Segregated Wallet Management">
    Manage fees across segregated wallets:

    ```javascript theme={null}
    async function setupSegregatedWalletFees(mainWalletId, feeWalletId) {
      // Configure main wallet to send fees to fee wallet
      const response = await fetch(
        `https://api.wepayments.com/v2/account/${mainWalletId}/fee-target`,
        {
          method: 'POST',
          headers: {
            'Authorization': 'Bearer YOUR_TOKEN',
            'Content-Type': 'application/json'
          },
          body: JSON.stringify({
            merchant_fee: feeWalletId,
            fee_wallet: true
          })
        }
      );
      
      const result = await response.json();
      
      return {
        mainWallet: mainWalletId,
        feeWallet: feeWalletId,
        configuration: result
      };
    }
    ```
  </Accordion>

  <Accordion title="Multi-Account Fee Routing">
    Set up fee routing for multiple accounts:

    ```javascript theme={null}
    async function setupMultiAccountFeeRouting(feeRoutingConfig) {
      const results = [];
      
      for (const config of feeRoutingConfig) {
        try {
          const response = await fetch(
            `https://api.wepayments.com/v2/account/${config.sourceAccount}/fee-target`,
            {
              method: 'POST',
              headers: {
                'Authorization': 'Bearer YOUR_TOKEN',
                'Content-Type': 'application/json'
              },
              body: JSON.stringify({
                merchant_fee: config.targetAccount,
                fee_wallet: config.useFeeWallet
              })
            }
          );
          
          results.push({
            source: config.sourceAccount,
            target: config.targetAccount,
            success: response.ok,
            data: await response.json()
          });
        } catch (error) {
          results.push({
            source: config.sourceAccount,
            target: config.targetAccount,
            success: false,
            error: error.message
          });
        }
      }
      
      return results;
    }

    // Usage
    const config = [
      { sourceAccount: 101, targetAccount: 201, useFeeWallet: true },
      { sourceAccount: 102, targetAccount: 201, useFeeWallet: true },
      { sourceAccount: 103, targetAccount: 202, useFeeWallet: false }
    ];

    const results = await setupMultiAccountFeeRouting(config);
    console.log('Fee routing setup:', results);
    ```
  </Accordion>
</AccordionGroup>

## Important Considerations

### Fee Types Affected

<CardGroup cols={2}>
  <Card title="Affected" icon="check" color="#16a34a">
    **Cashout/Payout Fees**

    * Withdrawal fees
    * Transfer fees
    * Payout processing fees
  </Card>

  <Card title="Not Affected" icon="xmark" color="#dc2626">
    **Cashin/Payin Fees**

    * Deposit fees
    * Payment processing fees
    * Remain on original account
  </Card>
</CardGroup>

### Payment Models

<Tabs>
  <Tab title="Prepaid">
    **Prepaid Model Requirements**:

    * Destination account must have sufficient balance
    * Fees are deducted immediately
    * Transaction fails if insufficient funds

    ```javascript theme={null}
    // Check balance before setting fee target
    const balance = await getBalance(targetAccountId);
    if (balance.available_balance >= expectedFees) {
      await changeFeeTarget(sourceAccountId, targetAccountId);
    }
    ```
  </Tab>

  <Tab title="Postpaid">
    **Postpaid Model Characteristics**:

    * No balance requirement
    * Fees are consolidated monthly
    * Invoiced by WEpayments finance team
    * Better for high-volume operations

    ```javascript theme={null}
    // Postpaid setup - no balance check needed
    await changeFeeTarget(sourceAccountId, targetAccountId, {
      fee_wallet: true
    });
    ```
  </Tab>
</Tabs>

## Best Practices

<Note>
  **Same Customer Domain**: Ensure both source and target accounts belong to the same customer domain before attempting the transfer.
</Note>

<Warning>
  **Fee Wallet Configuration**: When using `fee_wallet: true`, ensure the destination account is properly configured as a fee wallet.
</Warning>

<Tip>
  **Audit Trail**: Keep a log of all fee target changes for accounting and reconciliation purposes.
</Tip>
