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

# Send Transaction Confirmation

> This webhook is used when a transaction is confirmed by the user via OTP

## Webhook Endpoint

You should configure your webhook endpoint to receive POST requests from Propaga. The webhook will send the transaction confirmation data in JSON format.
Please contact us to set up the webhook.

## Payload Structure

Here's an example of the webhook payload you'll receive:

```json theme={null}
{
  "transactionId": "671f75a4-f145-4f4b-82ff-4eaf0fd1e5aa",
  "cornerStoreId": "57b9d911-1c6e-45c0-be98-bfaeec8d9cf8",
  "wholesalerTransactionId": "bd0880c6-45a7-4998-b30f-65f91f28956d",
  "totalAmount": 1000,
  "interest": 200,
  "totalAmountWithInterest": 1200,
  "movementDate": "2024-01-01T00:00:00Z",
  "status": "on-hold"
}
```

### Payload Fields

| Field                     | Type   | Description                                         |
| ------------------------- | ------ | --------------------------------------------------- |
| `transactionId`           | String | The Propaga's ID of the transaction.                |
| `cornerStoreId`           | String | The ID of the corner store.                         |
| `wholesalerTransactionId` | String | The ID of the transaction in the wholesaler system. |
| `totalAmount`             | Number | The total amount of the transaction.                |
| `interest`                | Number | The interest of the transaction.                    |
| `totalAmountWithInterest` | Number | The total amount of the transaction with interest.  |
| `movementDate`            | String | The date when the transaction was moved to on-hold. |
| `status`                  | String | The status of the transaction.                      |

## Handling the Webhook

Here's an example of how to handle the webhook in different programming languages:

<CodeGroup>
  ```javascript JavaScript theme={null}
  app.post('/webhook/transaction-confirmation', async (req, res) => {
    try {
      const transactionConfirmation = req.body;
      
      // Process the paid transaction notification data
      await processTransactionConfirmation(transactionConfirmation);
      
      // Respond with success
      res.status(200).json({ status: 'success' });
    } catch (error) {
      console.error('Error processing transaction confirmation:', error);
      res.status(500).json({ status: 'error', message: error.message });
    }
  });

  async function processTransactionConfirmation(transactionConfirmation) {
    // Validate the transaction confirmation
    console.log(`Processing transaction confirmation: ${transactionConfirmation.id}`);
    console.log(`Status: ${transactionConfirmation.status}`);
    
    // Process each transaction
    console.log(`Transaction ID: ${transactionConfirmation.transactionId}`);
    console.log(`Corner Store ID: ${transactionConfirmation.cornerStoreId}`);
    console.log(`Wholesaler Transaction ID: ${transactionConfirmation.wholesalerTransactionId}`);
    console.log(`Total Amount: ${transactionConfirmation.totalAmount}`);
    console.log(`Interest: ${transactionConfirmation.interest}`);
    console.log(`Total Amount With Interest: ${transactionConfirmation.totalAmountWithInterest}`);
    console.log(`Movement Date: ${transactionConfirmation.movementDate}`);
    console.log(`Status: ${transactionConfirmation.status}`);
  }
  ```

  ```python Python theme={null}
  from flask import Flask, request, jsonify

  app = Flask(__name__)

  @app.route('/webhook/transaction-confirmation', methods=['POST'])
  def handle_transaction_confirmation():
      try:
          transactionConfirmation = request.json
          
          # Process the transaction confirmation data
          process_transaction_confirmation(transactionConfirmation)
          
          return jsonify({'status': 'success'}), 200
      except Exception as e:
          print(f'Error processing transaction confirmation: {str(e)}')
          return jsonify({'status': 'error', 'message': str(e)}), 500

  def process_transaction_confirmation(transactionConfirmation):
      # Validate the transfer amount
      print(f"Processing transaction confirmation: {transactionConfirmation['id']}")
      
      # Process each transaction
      print(f"Transaction ID: {transactionConfirmation['transactionId']}")
      print(f"Corner Store ID: {transactionConfirmation['cornerStoreId']}")
      print(f"Wholesaler Transaction ID: {transactionConfirmation['wholesalerTransactionId']}")
      print(f"Total Amount: {transactionConfirmation['totalAmount']}")
      print(f"Interest: {transactionConfirmation['interest']}")
      print(f"Total Amount With Interest: {transactionConfirmation['totalAmountWithInterest']}")
      print(f"Movement Date: {transactionConfirmation['movementDate']}")
      print(f"Status: {transactionConfirmation['status']}")
  ```
</CodeGroup>

## Best Practices

1. **Verify the Webhook Source**: Implement security measures to verify that the webhook is coming from Propaga.

2. **Implement Idempotency**: Store the `referenceNumber` to avoid processing the same conciliation multiple times.

3. **Handle Errors Gracefully**: Implement proper error handling and logging to track any issues with webhook processing.

4. **Respond Quickly**: Your webhook endpoint should respond as quickly as possible. If processing takes time, handle it asynchronously.

5. **Validate Data**: Always validate the incoming data before processing it.
