# Initiate fee processing between master and investment accounts

To initiate fee calculation and deduction from investment accounts subscribed to a specific master account, use the following method:

<mark style="color:blue;">`POST`</mark> `[host]/api/admin/fees/v2/fee/feeservice/processext`

## Request

**Body parameters**

<table><thead><tr><th>Name</th><th width="81">Type</th><th width="105">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>account_login</code></td><td>string</td><td>Yes</td><td>The account login (number).</td></tr><tr><td><code>request_id</code></td><td>string</td><td>Yes</td><td>The identifier of a withdrawal request initiated in the external CRM system.</td></tr></tbody></table>

{% hint style="success" %}

### Key points about request\_id

The `request_id` represents the withdrawal operation ID in your external CRM system. It's used is to link a withdrawal request in the CRM with fee processing in B2COPY.

**How it works:**

* A user initiates a withdrawal request in your CRM.
* The CRM generates a unique ID for this withdrawal.
* You pass this ID as `request_id` to the B2COPY API method.
* Use the same `request_id` in subsequent polling requests to track the fee payment status for this withdrawal.

This ensures a direct and reliable connection between the withdrawal in your CRM and its corresponding fee processing in B2COPY.
{% endhint %}

**Request example**

```sh
curl -X POST "https://demo-standalone-v2.prod.b2copy.tech/api/admin/fees/v2/fee/feeservice/processext" \
     -H "Authorization: Bearer <your-access-token>" \
     -d '{
           "account_login": "123456",
           "request_id": "withdrawal_req_789"
         }'
```

## Response

The response returns the status of the initiated fee processing.

**Response example**

```json
{
  "account_login": "123456",
  "request_id": "withdrawal_req_789",
  "status": 1
}
```

Possible statuses:

* 1 —`FEE_PROCESS_STATUS_PENDING`: the request is being processed (temporary status).

  Fee payments from investment accounts to the master account are in progress. After receiving this status, start monitoring by using [polling](#polling-implementation).
* 2 — `FEE_PROCESS_STATUS_SUCCESS`: the request completed successfully (final status).

  All fees have been paid from investment accounts to the master account. No further action is required.

{% hint style="info" %}
If no fee deduction is required for the account, the response returns `FEE_PROCESS_STATUS_SUCCESS` immediately without going through the `PENDING` status.
{% endhint %}

* 3 — `FEE_PROCESS_STATUS_ERROR`: an error occurred during request processing (final status).

  Check the error details and retry if necessary.

## Polling implementation

The `FEE_PROCESS_STATUS_PENDING` status is temporary and indicates that B2COPY is actively processing fee payments between accounts. Implement polling as follows:

1. After make the initial request with `account_login` and `request_id` and receiving the `FEE_PROCESS_STATUS_PENDING` status, wait 3-5 seconds.
2. Repeat the request with the same `request_id`.
3. Continue polling until you receive `FEE_PROCESS_STATUS_SUCCESS` or `FEE_PROCESS_STATUS_ERROR`.

**Polling example**

```java
/**
 * Poll fee processing status for a withdrawal operation
 * 
 * @param accountLogin Account identifier
 * @param withdrawalId Withdrawal operation ID from your CRM
 * @return Final status (SUCCESS or ERROR)
 */
public FeeProcessStatus pollFeeProcessing(
        String accountLogin, 
        String withdrawalId) throws Exception {
    
    while (true) {
        // Make API call with your CRM withdrawal ID
        FeeProcessResponse response = feeService.processExt(
            accountLogin, 
            withdrawalId  // Your CRM withdrawal operation ID
        );
        
        if (response.getStatus() == FeeProcessStatus.SUCCESS) {
            // Fee processing completed - safe to proceed with withdrawal
            return FeeProcessStatus.SUCCESS;
        }
        
        if (response.getStatus() == FeeProcessStatus.ERROR) {
            // Error occurred - handle accordingly in your CRM
            throw new FeeProcessingException(
                "Fee processing failed for withdrawal " + withdrawalId
            );
        }
        
        if (response.getStatus() == FeeProcessStatus.PENDING) {
            // Fees are being paid from investors to master
            // Wait and retry with the same withdrawal ID
            Thread.sleep(3000); // Wait 3 seconds
            continue;
        }
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.b2copy.b2broker.com/api-documentation/initiate-fee-processing-between-master-and-investment-accounts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
