Skip to main content
POST
/
api
/
products
/
:id
/
payments
curl -X POST https://juadah-backend.vercel.app/api/products/1/payments \
  -H "Content-Type: application/json" \
  -H "Cookie: accessToken=your_access_token" \
  -d '{
    "transaction_details": {
      "product_id": 1,
      "gross_amount": 50000,
      "product_count_total": 5
    },
    "customer_details": {
      "email": "customer@example.com",
      "fullname": "John Doe",
      "address_id": 1
    }
  }'
{
  "status": "success",
  "data": {
    "token": "66e4fa55-fdac-4ef9-91b5-733b97d1b862",
    "redirect_url": "https://app.sandbox.midtrans.com/snap/v2/vtweb/66e4fa55-fdac-4ef9-91b5-733b97d1b862"
  }
}

Overview

This endpoint creates a new order and requests a payment token from Midtrans payment gateway. The token is used to redirect customers to the Midtrans payment page where they can complete their transaction.

Authentication

This endpoint requires authentication via cookie-based access token.
id
number
required
The ID of the product to purchase

Request Body

The request must include transaction details and customer information.
transaction_details
object
required
Details about the transaction
customer_details
object
required
Customer information for the order

Response

status
string
Response status, always “success” for successful requests
data
object
Payment token data from Midtrans
curl -X POST https://juadah-backend.vercel.app/api/products/1/payments \
  -H "Content-Type: application/json" \
  -H "Cookie: accessToken=your_access_token" \
  -d '{
    "transaction_details": {
      "product_id": 1,
      "gross_amount": 50000,
      "product_count_total": 5
    },
    "customer_details": {
      "email": "customer@example.com",
      "fullname": "John Doe",
      "address_id": 1
    }
  }'
{
  "status": "success",
  "data": {
    "token": "66e4fa55-fdac-4ef9-91b5-733b97d1b862",
    "redirect_url": "https://app.sandbox.midtrans.com/snap/v2/vtweb/66e4fa55-fdac-4ef9-91b5-733b97d1b862"
  }
}

Notes

  • The endpoint generates a unique order_id (UUID) for each request
  • The order is created in the database before requesting the Midtrans token
  • The gross_amount should match the calculation: product price × product_count_total
  • The returned token is used with Midtrans Snap to display the payment page
  • The redirect_url can be used to redirect customers directly to the payment page
  • After payment, Midtrans will send a webhook notification to update the order status