# Payment API

## **Payment APIs**

The Payment APIs facilitate the payment process for orders on the e-commerce platform. These APIs support multiple payment methods, including Cash on Delivery (COD) and online payments via Stripe.

<figure><img src="https://3686328336-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fd1Iq7THDAagTQzeC9rTN%2Fuploads%2FvQRxZNgiSBH9MNzPgFOf%2Fimage.png?alt=media&#x26;token=08c7e1eb-3ac6-4322-abe0-f95d9acaa973" alt=""><figcaption><p><strong>Payment interface</strong> </p></figcaption></figure>

### **1. Get Payment Methods API**&#x20;

The Get Payment Methods API retrieves a list of available payment methods for the authenticated user. It provides information about various payment options, such as Cash on Delivery (COD) and online payment via Stripe.

### **Endpoint**

* `{{baseurl}}/api/v1/payment-methods`

### **Method**

* **GET**

### **Request Parameters:**

None

### **Request Body:**

None

### **Authorization:**

The API requires a bearer token in the request header for authentication. Users need to include their valid bearer token in the "Authorization" header of the HTTP request to access the available payment methods.

### **Response Format:**&#x20;

The API responds with a JSON object containing a list of payment method objects. Each payment method object represents a specific payment option and includes details such as the payment method name and its availability.

```json
{
    "success": true,
    "data": {
        "Payment Methods": [
            {
                "name": "stripe",
                "settings": {
                    "ACTIVATION": "1",
                    "SANDBOX": "0"
                }
            },
            {
                "name": "cod",
                "settings": {
                    "ACTIVATION": "1",
                    "SANDBOX": "0"
                }
            }
        ]
    },
    "message": "Success",
    "status_code": 200
}
```

###

###

###

### **2. Receive Payment Status API**&#x20;

The Receive Payment Status API is used to update the payment status of an order after successful payment. For online orders paid via Stripe, this API receives the payment response from Stripe and updates the payment status for the corresponding order.

### **Endpoint**

* `{{baseurl}}/api/v1/payment-received-status`

### **Method**

* **POST**

### **Request Parameters:**

None

### **Request Body:**

The request body should include the order ID, payment response ID from Stripe, and the order type (COD or online) as follows:

```json
{
    "order_id": "your_order_id_here",
    "payment_response_id": "stripe_payment_response_id_here",
    "order_type": "COD" // or "online(stripe)"
}
```

### **Authorization:**

The API requires a bearer token in the request header for authentication. Users need to include their valid bearer token in the "Authorization" header of the HTTP request to update the payment status.

### **Response Format:**&#x20;

The API responds with a success message or appropriate status code indicating that the payment status has been successfully updated.

```json
{
    "success": true,
    "message": "Order has been placed",
    "order_id": "20230807-11172436O",
    "data": []
}
```

###

###

### **3. Stripe Webhook API**&#x20;

The Stripe Webhook API receives real-time event notifications from Stripe, such as successful payments, failed payments, and chargebacks. This API ensures that the e-commerce platform stays updated with the latest payment-related information from Stripe.

### **Endpoint**

* `{{baseurl}}/api/stripe/webhook/us`

### **Method**

* **POST**

### **Request Parameters:**<br>

None

### **Request Body:**

The request body includes the event data sent by Stripe as part of the webhook notification.

### **Authorization:**

No bearer token is required for this API since it receives incoming webhooks from Stripe.

### **Response Format:**&#x20;

The API responds with a success message or appropriate status code indicating that the webhook has been received and processed successfully.

```json
{
    "success": true,
    "message": {  "id": "evt_3NcMHoAyA3K5najM0JgtPSIG",  "object": "event",  "api_version": "2022-11-15",  "created": 1691387259,  "data": {    "object": {      "id": "pi_3NcMHoAyA3K5najM01KwAlhz",      "object": "payment_intent",      "amount": 48000,      "amount_capturable": 0,      "amount_details": {        "tip": {        }      },      "amount_received": 48000,      "application": null,      "application_fee_amount": null,      "automatic_payment_methods": {        "allow_redirects": "always",        "enabled": true      },      "canceled_at": null,      "cancellation_reason": null,      "capture_method": "automatic",      "client_secret": "pi_3NcMHoAyA3K5najM01KwAlhz_secret_E7jDo7n7dNBz0JiZfkCA3YTuy",      "confirmation_method": "automatic",      "created": 1691387244,      "currency": "usd",      "customer": null,      "description": null,      "invoice": null,      "last_payment_error": null,      "latest_charge": "ch_3NcMHoAyA3K5najM0pkEpW3u",      "livemode": false,      "metadata": {      },      "next_action": null,      "on_behalf_of": null,      "payment_method": "pm_1NcMI2AyA3K5najMrfqLtW0w",      "payment_method_options": {        "card": {          "installments": null,          "mandate_options": null,          "network": null,          "request_three_d_secure": "automatic"        },        "link": {          "persistent_token": null        }      },      "payment_method_types": [        "card",        "link"      ],      "processing": null,      "receipt_email": null,      "review": null,      "setup_future_usage": null,      "shipping": null,      "source": null,      "statement_descriptor": null,      "statement_descriptor_suffix": null,      "status": "succeeded",      "transfer_data": null,      "transfer_group": null    }  },  "livemode": false,  "pending_webhooks": 2,  "request": {    "id": "req_pX7YzxK2EwSoKz",    "idempotency_key": "25096deb-8c9a-422b-a62f-7b880f046e7d"  },  "type": "payment_intent.succeeded"},
    "status_code": 200
}
```

**Features:**

* The Get Payment Methods API allows users to view available payment options for their orders, including COD and online payment via Stripe.
* The Receive Payment Status API updates the payment status of an order after successful payment, specifically for online orders paid via Stripe.
* The Stripe Webhook API receives real-time event notifications from Stripe, ensuring the e-commerce platform remains updated with the latest payment-related information.
