# Order Initialization for Payment Processing

> Learn how to initialize an order with the EnKash Payment Gateway. Generate a unique OrderID to streamline and manage your payment transaction lifecycle efficiently.

Creating an order is the first and critical step in processing a payment through the EnKash Payment Gateway. The Order API generates a unique `OrderID`, which acts as the core reference throughout the transaction lifecycle.

## <span style="color:#7b2cbf">Purpose</span> 

<div style="line-height: 1.9;">

<Icon icon="material-outline-security"color="#7b2cbf"/> <span style="color:#7b2cbf">Order Security:</span> Ensures transaction integrity by preventing tampering with amount or details.
<Icon icon="material-outline-attach_file"color="#7b2cbf"/> <span style="color:#7b2cbf">Payment Binding:</span> Ties a single successful payment to each order to avoid duplicates. 
<Icon icon="remix-code-box-fill"color="#7b2cbf"/> <span style="color:#7b2cbf">Integration Backbone:</span> Links the order to Checkout, enabling a secure and traceable flow.
    </div>

## <span style="color:#7b2cbf">Workflow</span> 

<Steps>
  <Step title="Customer Action">
    The customer clicks the "Pay" button on your platform.
  </Step>
  <Step title="Order Creation">
    Your backend calls the Order API, which returns a unique Order ID along with transaction details (amount, currency, etc.).
  </Step>
  <Step title="Checkout Integration">
    The Order ID is passed to the EnKash Checkout for secure and streamlined payment handling.
  </Step>
</Steps>

## <span style="color:#7b2cbf">Advantages</span> 

- **Single Successful Payment Enforcement**
Prevents multiple payments from being accepted against the same order.

- **Optimized Querying**
Simplifies reconciliation by associating multiple payment attempts to a single order.
  
## <span style="color:#7b2cbf">Key Integration Steps</span> 

<Steps>
  <Step title="Create Order">
    Use the Create Order API with transaction metadata such as `amount`, `currency`, and optional custom fields.
  </Step>
  <Step title="Initiate Checkout">
    Pass the generated `OrderID` to EnKash Checkout for rendering the payment UI.
  </Step>
  <Step title="Track Order">
    Use Get Order Status or related APIs to monitor order status through the payment lifecycle.
  </Step>
</Steps>

## <span style="color:#7b2cbf">Order Lifecycle Statuses</span> 

| Status              | Description                                       |
| ------------------- | ------------------------------------------------- |
| `CREATED`           | Order successfully created and ready for Checkout |
| `ATTEMPTED`         | Customer attempted payment                        |
| `PAID`              | Payment completed successfully                    |
| `CANCELLED`         | Customer canceled the transaction                 |
| `EXPIRED`           | Order expired due to timeout or inactivity        |

