Hook: mam_pmt_refund_card

Signature

$result = apply_filters( 'mam_pmt_refund_card', array $data_array );

mam-stripe-manager implements this suite-wide refund filter (priority 10). Callers in the suite include MAM WooCommerce Product Vendors order cancellation and MAM RFQ Manager.

Input keys

Key Type Required Meaning
transaction_id string yes What to refund: a PaymentIntent id (pi_…) or a Charge id (ch_…). Other values are treated as a PaymentIntent id for backward compatibility. Missing → status = false.
amount float yes Refund amount in decimal currency units. amount <= 0 is a successful no-op (status = true, charge = null).
post_id int recommended WooCommerce order id — supplies the currency (stored _stripe_currency, falling back to the order currency) and lets the refund id be recorded on the order.

Return shape

The input array, plus:

Key Type Meaning
status bool true when the refund was created (or the amount was ≤ 0).
charge StripeRefund|null The Stripe Refund object on success; null otherwise.
error_message string Present only when a Stripe/API exception occurred — the exception message.

Built-in safety (no caller action needed)

  • Over-refund guard — before refunding, the underlying charge is retrieved and the request is refused (status = false, logged, no exception) if it exceeds the remaining refundable amount (amount_captured − amount_refunded). If the pre-check itself can’t run, Stripe remains the backstop.
  • Idempotency — the Stripe idempotency key is derived from order, transaction, amount, currency, and the order’s refund count, so an identical retried request returns the original refund instead of refunding twice.
  • On success the refund id is appended to the order’s _stripe_refund_ids meta (HPOS-safe CRUD write, re-read immediately before the write).
  • Zero-decimal currencies convert correctly.

Example — refund part of an order

$order = wc_get_order( $order_id );

$result = apply_filters( 'mam_pmt_refund_card', array(
    'transaction_id' => $order->get_meta( '_mam_stripe_intent_id', true ), // pi_...
    'amount'         => 25.00,
    'post_id'        => $order->get_id(),
) );

if ( empty( $result['status'] ) ) {
    $reason = $result['error_message'] ?? 'refund refused (over-refund or missing transaction)';
    // surface $reason to the admin
} else if ( $result['charge'] ) {
    $refund_id = $result['charge']->id; // re_...
}


Metadata

Field Value
Article type Hook Reference
Plugin slug mam-stripe-manager
Applies to plugin version 26.19.1+
Category Extending MAM Suite
Hook type filter (implemented by this plugin; applied by callers)
Audience PHP developer
Last verified 2026-06-10
Contents

    Need Support?

    Can't find the answer you're looking for? Don't worry we're here to help!