# Transaction Lifecycle

## Overview
This guide outlines the complete process of creating and managing a transaction within the system. The flow involves setting up merchants, payout accounts, and handling transaction approvals while leveraging the **API** or the [**Partners Platform**](https://partners.service.cedar.money/).

## Transaction Flow Steps

### **1. Create the Source Merchant**
The source merchant can be created either via:
- [**API**](https://docs.service.cedar.money/create-merchant)
- [**Partners Platform**](https://partners.service.cedar.money/) (by manually filling in the details)

Once created, the **onboarding process must be completed** using the [**Partners Platform**](https://partners.service.cedar.money/).

> In the **Sandbox** environment you can manually trigger KYC status changes (and thus the relevant webhooks) via update of merchants. See [Update Merchant](https://docs.service.cedar.money/update-merchant)

### **2. Complete Onboarding & Approval**
The created source merchant undergoes an **approval process** within the [**Partners Platform**](https://partners.service.cedar.money/). Once the merchant is **approved**, it becomes eligible for transactions.

### **3. Create the Target Merchant**
A target merchant must be created before transactions can be made. This can be done using:
- [**API**](https://docs.service.cedar.money/create-merchant)
- [**Partners Platform**](https://partners.service.cedar.money/)

### **4. Create a Payout Account for the relevant Merchant**
The relevant merchant (target merchant for Payout / End-to-End, source merchant for Collections) needs a **Payout Account**, which stores bank or wallet details for receiving funds. The payout account can be created via:
- [**API**](https://docs.service.cedar.money/create-payout-account)
- [**Partners Platform**](https://partners.service.cedar.money/)

**Note:** The payout account must be **approved** before it can be used in transactions.

> In the **Sandbox** environment payout accounts will be approved automatically a few seconds after they are created.

### **5. Create a Transaction**
A transaction can be initiated through:
- **API** - [Payout API](https://docs.service.cedar.money/create-payout-transaction) / [End-to-End API](https://docs.service.cedar.money/create-end-to-end-transaction) / [Collections API](https://docs.service.cedar.money/create-collections-transaction)
- [**Partners Platform**](https://partners.service.cedar.money/)

### **6. Quote Generation & Notifications**
Once the transaction is **approved**, a **quote will be generated**. Updates will be sent through:
- **Webhooks** (to notify your system)
- **Emails** (to keep you informed)

### **7. Approve the Quote**
The quote must be approved via:
- **API** - [Payout API](https://docs.service.cedar.money/approve-payout-transaction-quote) / [End-to-End API](https://docs.service.cedar.money/approve-end-to-end-transaction-quote) / [Collections API](https://docs.service.cedar.money/approve-collections-transaction-quote)
- [**Partners Platform**](https://partners.service.cedar.money/)

### **8. Deposit Funds**
Based on the transaction type, the deposit details will be provided:
- **Fiat transactions:** Bank account details
- **Crypto transactions:** Wallet address

The source merchant must **deposit funds** accordingly.

### **9. Approve the Deposit**
After the deposit is made, it must be confirmed using:
- **API** - [Payout API](https://docs.service.cedar.money/approve-payout-transaction-deposit) / [End-to-End API](https://docs.service.cedar.money/approve-end-to-end-transaction-deposit) / [Collections API](https://docs.service.cedar.money/approve-collections-transaction-deposit)
- [**Partners Platform**](https://partners.service.cedar.money/)

### **10. Transaction Processing & Notifications**
Once the deposit is approved, the transaction will be processed. Updates will be sent through:
- **Webhooks** (for system integration)
- **Emails** (for manual tracking)

## Transaction Flow Diagram
Below is a diagram illustrating the full transaction lifecycle.

### **A. Payout / End-to-End Transactions**

```mermaid
graph TD;
    A[Create Source Merchant] --> D[Complete Onboarding]
    B[Create Target Merchant] --> C[Create Payout Account]
    D -->|Source Approved| E[Create Transaction]
    C -->|Account Approved|E
    E -->|API or UI| F[Generate Quote]
    F -->|Webhook & Email| G[Approve Quote]
    G -->|API or UI| H[Deposit Funds]
    H -->|Bank Account or Wallet| I[Approve Deposit]
    I -->|API or UI| J[Transaction Processed]
    J -->|Webhook & Email| K[Transaction Completed]
```

### **B. Collections Transactions**

```mermaid
graph TD;
    A[Create Source Merchant] --> D[Complete Onboarding]
    D -->|Source Approved| C[Create Payout Account]
    C -->|Account Approved|E
    B[Create Target Merchant] --> E[Create Transaction]
    E -->|API or UI| F[Generate Quote]
    F -->|Webhook & Email| G[Approve Quote]
    G -->|API or UI| H[Deposit Funds]
    H -->|Bank Account or Wallet| I[Approve Deposit]
    I -->|API or UI| J[Transaction Processed]
    J -->|Webhook & Email| K[Transaction Completed]
```

## Summary
- Merchants and payout accounts must be **created and approved** before transacting.
- Transactions can be initiated via **API or UI**.
- A **quote is generated** and must be approved.
- Funds must be **deposited and approved** before processing.
- Notifications are sent via **webhooks and emails** at each stage.



