entity_id ? null : wc_get_order( $action->entity_id ); if ( ! $order instanceof \WC_Order ) { return 'missing'; } // The refund being created when it was held is left out: the veto // deleted it, so approval must not count it either. $decimals = ( new StoreCurrency() )->decimals(); $in_flight = 'unclassified' === $action->source ? absint( $action->input['refund_id'] ?? 0 ) : 0; $refunded = Orders::refunded( $order, $in_flight, $decimals ); // The gateway and currency too: approval must not send the money // somewhere other than where the decision saw it going. return implode( '|', array( wc_format_decimal( $order->get_total() ), $refunded ?? 'unreadable', $order->get_payment_method(), $order->get_currency() ) ); } /** * No snapshot: a refund is not undone. * * @param ActionDescriptor $action The stored action. */ public function snapshot( ActionDescriptor $action ): ?array { return null; } /** * Never called: nothing is offered as undoable without a snapshot. * * @param ActionDescriptor $action The stored action. * @param array $before The snapshot. */ public function restore( ActionDescriptor $action, array $before ): WP_Error { return new WP_Error( 'adafwc_refund_not_undoable', __( 'A refund cannot be undone.', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ) ); } /** * How far a refund action can be taken back. * * @param ActionDescriptor $action The stored action. */ public function reversibility( ActionDescriptor $action ): Reversibility { if ( 'delete' === $action->action_cat ) { return new Reversibility( Reversibility::PARTIALLY_REVERSIBLE, array( __( 'Deletes the refund record only. Money the payment gateway returned stays returned.', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ) ) ); } $via_gateway = $action->facts['refund.via_gateway'] ?? null; if ( false === $via_gateway ) { return new Reversibility( Reversibility::PARTIALLY_REVERSIBLE, array( __( 'Records the refund on the order and may restock items. No money moves through the payment gateway.', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ) ) ); } return new Reversibility( Reversibility::IRREVERSIBLE, array( __( 'Money will be returned to the customer through the payment gateway.', 'agentic-daisy-ai-agent-firewall-for-woocommerce' ) ) ); } }