## Filter: wpd_ai_order_payment_gateway_cost_default_value

Filter the default payment gateway fee calculated for an order.

### Description

Customize payment processing fee calculation based on payment method, order amount, card type, or integration with actual gateway data.

### Location

File:`includes/classes/WPDAI_Order_Calculator.php`

Method:`WPDAI_Order_Calculator::get_payment_gateway_cost()`

Line:~540

### Parameters

Parameter | Type | Description
--- | --- | ---
$payment_gateway_cost | float | Calculated payment fee
$order | WC_Order | WooCommerce order object

#### Return

Type: float

Description: Modified payment gateway cost

### Example Usage

### Custom Gateway Fees

    add_filter( 'wpd_ai_order_payment_gateway_cost_default_value', 'custom_gateway_fees', 10, 2 );

    function custom_gateway_fees( $fee, $order ) {
        $payment_method = $order->get_payment_method();
        $order_total = $order->get_total();

        switch ( $payment_method ) {
            case 'stripe':
                // Stripe: 2.9% + $0.30
                return ( $order_total * 0.029 ) + 0.30;

            case 'paypal':
                // PayPal: 2.9% + $0.30 domestic, 4.4% + fixed for international
                if ( $order->get_billing_country() === 'US' ) {
                    return ( $order_total * 0.029 ) + 0.30;
                } else {
                    return ( $order_total * 0.044 ) + 0.30;
                }

            case 'bacs':
                // Bank transfer
                return 0.00; // No fee

            case 'cod':
                // Cash on delivery
                return 2.50; // Flat handling fee

            default:
                return $fee;
        }
    }

### Integration with Stripe API

    add_filter( 'wpd_ai_order_payment_gateway_cost_default_value', 'stripe_actual_fee', 10, 2 );

    function stripe_actual_fee( $fee, $order ) {
        if ( $order->get_payment_method() !== 'stripe' ) {
            return $fee;
        }

        // Get Stripe charge ID from order meta
        $charge_id = get_post_meta( $order->get_id(), '_stripe_charge_id', true );

        if ( $charge_id ) {
            // Fetch actual fee from Stripe (would need Stripe SDK)
            // $charge = \Stripe\Charge::retrieve( $charge_id );
            // $actual_fee = $charge->balance_transaction->fee / 100;
            // return $actual_fee;
        }

        return $fee;
    }

### Volume-Based Merchant Account Fees

    add_filter( 'wpd_ai_order_payment_gateway_cost_default_value', 'volume_based_fees', 10, 2 );

    function volume_based_fees( $fee, $order ) {
        // Get monthly transaction volume
        $monthly_volume = get_monthly_transaction_volume();
        $order_total = $order->get_total();

        // Tiered merchant account rates
        if ( $monthly_volume > 100000 ) {
            // High volume: 1.9% + $0.20
            $fee = ( $order_total * 0.019 ) + 0.20;
        } elseif ( $monthly_volume > 50000 ) {
            // Medium volume: 2.4% + $0.25
            $fee = ( $order_total * 0.024 ) + 0.25;
        } else {
            // Standard volume: 2.9% + $0.30
            $fee = ( $order_total * 0.029 ) + 0.30;
        }

        return $fee;
    }

### Best Practices

- Always return float value
- Check payment method exists before using it
- Cache expensive operations (API calls)
- Handle different currencies if applicable
- Test with various payment methods

### Related Filters

- wpd_ai_calculate_cost_profit_by_order
- wpd_ai_order_shipping_cost_default_value