Skip to main content

GET /api/payments/refund/payment-intent/:paymentIntentId

Retrieves a list of all refunds associated with a specific payment intent. This is useful for tracking refund history and verifying which charges have been refunded.

Path Parameters

paymentIntentId
string
required
The unique identifier for the payment intent. Must be a valid Stripe payment intent ID starting with pi_.Example: pi_3OJxRe2eZvKYlo2C0XYZ1234

Response

status
boolean
Indicates if the request was successful
message
string
Human-readable message describing the resultExample: Reembolsos obtenidos correctamente
data
object
Stripe’s list response object containing refunds

Success Response

{
  "status": true,
  "message": "Reembolsos obtenidos correctamente",
  "data": {
    "object": "list",
    "data": [
      {
        "id": "re_3OJxRe2eZvKYlo2C0XYZ9999",
        "object": "refund",
        "amount": 50000,
        "charge": "ch_3OJxRe2eZvKYlo2C0ABC5678",
        "currency": "eur",
        "payment_intent": "pi_3OJxRe2eZvKYlo2C0XYZ1234",
        "reason": "requested_by_customer",
        "status": "succeeded",
        "created": 1672617600
      },
      {
        "id": "re_3OJxRe2eZvKYlo2C0DEF0000",
        "object": "refund",
        "amount": 25000,
        "charge": "ch_3OJxRe2eZvKYlo2C0ABC5678",
        "currency": "eur",
        "payment_intent": "pi_3OJxRe2eZvKYlo2C0XYZ1234",
        "reason": "duplicate",
        "status": "succeeded",
        "created": 1672704000
      }
    ],
    "has_more": false,
    "url": "/v1/refunds"
  }
}

Error Responses

{
  "status": false,
  "message": "paymentIntentId es requerido",
  "code": null
}

Code Examples

curl -X GET https://api.example.com/api/payments/refund/payment-intent/pi_3OJxRe2eZvKYlo2C0XYZ1234 \
  -H "Authorization: Bearer YOUR_API_KEY"

Use Cases

Calculate Total Refunded Amount

const getTotalRefunded = async (paymentIntentId) => {
  const response = await fetch(`/api/payments/refund/payment-intent/${paymentIntentId}`);
  const { data } = await response.json();
  
  const totalRefunded = data.data.reduce((sum, refund) => {
    return sum + (refund.status === 'succeeded' ? refund.amount : 0);
  }, 0);
  
  console.log(`Total refunded: €${totalRefunded / 100}`);
  return totalRefunded;
};

Check if Payment is Fully Refunded

const isFullyRefunded = async (paymentIntentId) => {
  // Get payment intent to get original amount
  const paymentResponse = await fetch(`/api/payments/${paymentIntentId}`);
  const { data: payment } = await paymentResponse.json();
  
  // Get all refunds
  const refundsResponse = await fetch(`/api/payments/refund/payment-intent/${paymentIntentId}`);
  const { data: refunds } = await refundsResponse.json();
  
  // Calculate total refunded
  const totalRefunded = refunds.data.reduce((sum, refund) => {
    return sum + (refund.status === 'succeeded' ? refund.amount : 0);
  }, 0);
  
  return totalRefunded >= payment.amount;
};

// Usage
if (await isFullyRefunded('pi_3OJxRe2eZvKYlo2C0XYZ1234')) {
  console.log('This payment has been fully refunded');
}

List Refunds with Details

const listRefundDetails = async (paymentIntentId) => {
  const response = await fetch(`/api/payments/refund/payment-intent/${paymentIntentId}`);
  const { data } = await response.json();
  
  const refundDetails = data.data.map(refund => ({
    id: refund.id,
    amount: `€${refund.amount / 100}`,
    status: refund.status,
    reason: refund.reason || 'Not specified',
    date: new Date(refund.created * 1000).toLocaleDateString(),
    chargeId: refund.charge
  }));
  
  console.table(refundDetails);
  return refundDetails;
};

Filter Refunds by Reason

const getRefundsByReason = async (paymentIntentId, reason) => {
  const response = await fetch(`/api/payments/refund/payment-intent/${paymentIntentId}`);
  const { data } = await response.json();
  
  const filtered = data.data.filter(refund => refund.reason === reason);
  
  console.log(`Found ${filtered.length} refunds with reason: ${reason}`);
  return filtered;
};

// Usage
const customerRequestedRefunds = await getRefundsByReason(
  'pi_3OJxRe2eZvKYlo2C0XYZ1234',
  'requested_by_customer'
);

Notes

The API returns up to 100 refunds per request. For payment intents with more than 100 refunds, you would need to implement pagination (though this is rare in practice).
Refunds are listed in reverse chronological order, with the most recent refunds appearing first.
This endpoint returns refunds specifically for the given payment intent. If you need to list refunds by charge ID or across multiple payment intents, you’ll need to call this endpoint multiple times or query Stripe directly.

Build docs developers (and LLMs) love