# Orphan transactions

This section provides methods for receiving and withdrawing orphan transactions.

**Orphan Transactions** are transactions randomly sent to an address that was created for another coin.

If such a transaction is detected, you can withdraw the received coins to the specified address.\
Transactions have two stages `DEPOSIT` and `WITHDRAWAL`. The output can be created when the transaction is at the `DEPOSIT` stage and in the `PROCESSED` status, there is also a parameter in the transaction body `canWithdrawal` which can be used when trying to output.

After the output, you will receive a webhook at the specified URL when requesting output (the body of the webhook will be identical to the body of the output). The outgoing transaction will also appear in the `outTransaction` field in the body of the orphan transaction

## Description of transaction fields

| Field            | Description                                                                                         |
| ---------------- | --------------------------------------------------------------------------------------------------- |
| `id`             | Transaction ID in the system                                                                        |
| `organizationId` | ID of the organization that the address belongs to                                                  |
| `orderId`        | ID of the order to which the address was linked at the time the transaction was detected            |
| `stage`          | The current stage of the transaction. There are 2 values available: `DEPOSIT` and `WITHDRAWAL`      |
| `status`         | Status of the current stage of the transaction                                                      |
| `message`        | Message when the operation is rejected                                                              |
| `currency`       | Transaction Coin                                                                                    |
| `network`        | Transaction Network                                                                                 |
| `amount`         | Transaction amount                                                                                  |
| `canWithdrawal`  | Is coin withdrawal available. (Available only at the `DEPOSIT` stage and in the `PROCESSED` status) |
| `inTransaction`  | Incoming transaction data                                                                           |
| `outTransaction` | Data of the outgoing transaction if a withdrawal was requested                                      |
| `createdAt`      | Date of transaction discovery                                                                       |

***

Incoming transaction:

| Field         | Description                                 |
| ------------- | ------------------------------------------- |
| `addressType` | The type of address the transaction came to |
| `addressID`   | ID of the address in the system             |
| `address`     | Address in the blockchain                   |
| `txId`        | Transaction ID in the blockchain            |
| `amount`      | Transaction amount                          |
| `status`      | Transaction status                          |
| `createdAt`   | Date of the transaction                     |

Outgoing transaction transaction:

| Field          | Description                                              |
| -------------- | -------------------------------------------------------- |
| `address`      | Address in the blockchain                                |
| `txId`         | Transaction ID in the blockchain                         |
| `amount`       | Transaction amount                                       |
| `status`       | Transaction status                                       |
| `feeAmount`    | Network commission per transaction                       |
| `feeAmountUSD` | The network's commission per transaction in terms of USD |
| `withdrawalId` | ID of the output in the system                           |
| `createdAt`    | Date of creation of the withdrawal request               |

***

Description of the `addressType` field:

| Value       | Description                    |
| ----------- | ------------------------------ |
| `PAY_IN`    | Address for payments           |
| `PAY_OUT`   | Payment address                |
| `BUSINESS`  | Business wallet                |
| `RECURRENT` | Address for recurrent payments |
| `PERSONAL`  | Personal address               |

Description of the `status` field:

| Value       | Description                               |
| ----------- | ----------------------------------------- |
| `init`      | The transaction was created in the system |
| `processed` | Successfully processed                    |
| `error`     | Error during processing                   |
| `rejected`  | Rejected by the system                    |
| `pending`   | During processing                         |

***

Transaction stages:

| Stage        | Description                                                                                                         |
| ------------ | ------------------------------------------------------------------------------------------------------------------- |
| `DEPOSIT`    | A deposit has been received, for withdrawal it is necessary to wait for the transition to the status of `PROCESSED` |
| `WITHDRAWAL` | Withdrawal of received coins was requested.                                                                         |

***

Transaction statuses:

| Status      | Description                                                                                                                                                                                  |
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `PENDING`   | The operation is in progress. For the `DEPOSIT` stage, waiting for incoming transaction confirmations. For the `WITHDRAWAL` stage - waiting for the transaction to be sent to the blockchain |
| `PROCESSED` | The operation was completed successfully. For the `DEPOSIT` stage, the incoming transaction is confirmed. For the `WITHDRAWAL` stage, the transaction has been successfully sent             |
| `ERROR`     | Error processing the operation                                                                                                                                                               |
| `REJECTED`  | Operation rejected                                                                                                                                                                           |

## Commission token

To request a commission token, you must specify the orphan transit ID. The token is generated for the amount that came to the address in full volume.

| Field              | Description                                                                                              |
| ------------------ | -------------------------------------------------------------------------------------------------------- |
| `currency`         | Withdrawal Coin                                                                                          |
| `network`          | Withdrawal Network                                                                                       |
| `feeSource`        | The source of the commission write-off. There are 2 values available: `ADDRESS`, `ADVANCE`               |
| `blockchainFee`    | Network commission in the transaction coin                                                               |
| `blockchainFeeUSD` | The network's commission in terms of USD                                                                 |
| `serviceFee`       | Service commission                                                                                       |
| `serviceFeeUSD`    | Service fee in USD                                                                                       |
| `amount`           | Withdrawal amount                                                                                        |
| `amountTo`         | The amount that the outgoing address will receive after withdrawal (minus fees for `feeSource: ADDRESS`) |
| `price`            | The conversion rate of the network commission to USD                                                     |
| `token`            | Withdrawal Token                                                                                         |
| `expiresAt`        | Token expiration date                                                                                    |

***

Description of the `feeSource` field:

| Value     | Description                                                                                                                                                                                    |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ADDRESS` | The source of the network's withdrawal fee is the address. In this case, `blockchainFee` will be taken from the withdrawal amount, so the `amount` and `amountTo` fields will be different.    |
| `ADVANCE` | The source of the deduction of the network's commission for withdrawal is the advance balance. In this case, `blockchainFeeUSD` + `blockchainFeeUSD` will be debited from the advance balance. |
