bookmark_bordergform_paypal_query

Description

Use this filter to modify the query string that will be sent to PayPal. This filter is fired immediately before the user is redirected to PayPal.

Important: DO NOT override the query strings custom parameter doing so will prevent the PayPal IPN updating the payment details in the entry.

Usage

add_filter( 'gform_paypal_query', 'your_function_name', 10, 5 );

Parameters

  • $query_string string

    The query string that will be sent to PayPal; includes the invoice ID, currency, customer fields, products, quantities, prices, and various other PayPal settings.

  • $form

    The Form Object of the entry from which this query string is generated.

  • $entry Entry Object

    The Entry Object from which this query string is generated.

  • $feed Feed Object

    The feed which is being processed.

  • $submission_data Submission Data

    Contains the form title, payment amount, setup fee amount, trial amount, line items created using the submitted pricing field values and any discounts from coupons. Added in PayPal 2.4.4.

Examples

1. Modify Pricing

This example demonstrates how to remove negative prices from the query string (which are would otherwise generate an error with PayPal) and to subtract that value from the highest priced item.

add_filter( 'gform_paypal_query', 'update_paypal_query', 10, 3 );
function update_paypal_query( $query_string, $form, $entry ) {

    parse_str( $query_string, $query );

    $id = 0;
    $amounts = array();

    foreach ( $query as $key => $value ) {

        if ( (int) $value >= 0 ) {
            $amounts[] = $value;
            continue;
        } else {
            $id = str_replace( 'amount_', '*', $key );
            $discount = abs( $value );
        }

    }

    if ( $id ) {
        unset( $query['item_name_' . $id] );
        unset( $query['amount_' . $id] );
        unset( $query['quantity_' . $id] );
    }

    foreach ( $query as $key => &$value ) {
        if ( strpos( $key, 'amount_' ) !== false ) {
            $value = $value - $discount;
        }
    }

    $query_string = http_build_query( $query, '', '&' );

    return '&' . $query_string;
}

2. Disable Tax

This example shows how you can disable tax:

add_filter( 'gform_paypal_query', 'update_paypal_query', 10, 3 );
function update_paypal_query( $query_string, $form, $entry ) {

	$my_forms = array( 1, 5, 7, 9, 276 ); // list of form id's to apply this separated by comma

	// skip processing if the form id is not in the array of forms id's
	if ( !in_array( $form['id'], $my_forms ) ) {
		return $query_string;
        }

	// apply only if form ID is 1
	parse_str( $query_string, $query );
	$query['tax_1'] = '0.00';
	$query['tax_2'] = '0.00';
	$query['tax_3'] = '0.00';
	$query['tax_4'] = '0.00';
	$query['tax_5'] = '0.00';
	$query['tax'] = '0.00';
	$query_string = http_build_query( $query, '', '&' );
	return '&' . $query_string;
}

3. Set the Language Code

This example shows how you can set the language code

add_filter( 'gform_paypal_query', 'update_paypal_query', 10, 3 );
function update_paypal_query( $query_string, $form, $entry ) {
	if ( $form['id'] == 323 ) {
		$query_string .= '&lc=en_GB';
	} else {
		$query_string .= '&lc=en_US';
	}

	return $query_string;
}

Placement

This code should be placed in the functions.php file of your active theme

Source Code

gf_apply_filters( 'gform_paypal_query', $form['id'], $query_string, $form, $entry, $feed, $submission_data )

This filter is located in GFPayPal::redirect_url() in class-gf-paypal.php