Refund Eligibility Gate
Evaluates refund eligibility from order status, fulfillment state, payment capture, age, and prior refunds.
Purpose
Evaluates refund eligibility from order status, fulfillment state, payment capture, age, and prior refunds.
Snippet details
ContextEcommerceLevelAdvancedCopy-and-paste statusMarked safe after review.Categories
- Security
Code
<?php
/*
* Copyright (c) 2026 Jeffery L. Paris <jparis@phpog.com>.
* Free for personal and internal use. Paid project use requires visible credit
* to Jeffery L. Paris. Corporate use requires a paid license fee unless a
* separate written license states otherwise.
*/
/**
* Refund Eligibility Gate.
*
* Purpose:
* Evaluates refund eligibility from order status, fulfillment state, payment capture, age, and prior refunds.
*
* @param array $order Order facts.
* @return array Refund eligibility decision.
*/
function ogSnippetRefundEligibilityGate(array $order): array {
$eligible = true;
$reasons = array();
if (!in_array($order['status'], array('paid', 'fulfilled', 'partially_fulfilled'), true)) {
$eligible = false;
$reasons[] = 'order_status_not_refundable';
}
if ((int) $order['captured_cents'] <= (int) $order['refunded_cents']) {
$eligible = false;
$reasons[] = 'nothing_left_to_refund';
}
if ((int) $order['age_days'] > 30) {
$eligible = false;
$reasons[] = 'refund_window_expired';
}
return array('eligible' => $eligible, 'reasons' => $reasons);
}
$refund = ogSnippetRefundEligibilityGate(array('status' => 'paid', 'captured_cents' => 10000, 'refunded_cents' => 0, 'age_days' => 12));
if ($refund['eligible'] === true) {
echo 'eligible';
} else {
echo 'blocked';
}