gform_paypal_return_url

gform_paypal_return_url

DescriptionUsageParametersExamples1. Use site_url()2. Hardcoded URLPlacementSource Code

Description
Use this filter to modify the return URL, which is the URL that users will be sent to after completing the payment on PayPal』s site. Useful when the return URL isn』t created correctly (could happen on some server configurations using PROXY servers).
Usage
add_filter( 'gform_paypal_return_url', 'your_function_name', 10, 4 ) ;

Parameters

$url string
The return URL, uses the $_SERVER[『SERVER_NAME』] parameter.

$form_id integer
The ID of the form being processed.

$entry_id integer
The ID of the entry being processed.

$query string
The gf_paypal_return parameter and value.

Examples
1. Use site_url()
This example shows how you can replace the default return URL with the url returned by the WordPress site_url function.
add_filter( 'gform_paypal_return_url', 'update_url', 10, 4 );
function update_url( $url, $form_id, $entry_id, $query ) {

return trailingslashit( site_url() ) . '?' . $query;
}

2. Hardcoded URL
This example shows how you can replace the default return URL with a hardcoded url
add_filter( 'gform_paypal_return_url', 'update_url', 10, 4 );
function update_url( $url, $form_id, $entry_id, $query ) {

return 'https://somedomain.com/?' . $query;
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
apply_filters( 'gform_paypal_return_url', $url, $form_id, $lead_id, $query )

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

gform_paypal_return_url_port

gform_paypal_return_url_port

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
This filter allow the port to be changed for the return_url that is sent to PayPal.
Usage
1add_filter( 'gform_paypal_return_url_port', 'your_function_name', 10, 1 );

Parameters

$server_port string
The current port.

Examples
1234add_filter( 'gform_paypal_return_url_port', 'change_port' );function change_port(){    return '81';}
Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in the Gravity Forms PayPal Standard Add-On version 2.4.
Source Code
This filter is located in GFPayPal::return_url() in class-gf-paypal.php.

gform_paypal_request

gform_paypal_request

DescriptionUsageParametersExamplesChange Return URLChange IPN URLPlacementSource Code

Description
Use this filter to modify the URL string that will be sent to PayPal. This filter is fired immediately before the user is redirected to PayPal. See the PayPal Standard documentation for supported arguments.
Usage
1add_filter( 'gform_paypal_request', 'your_function_name', 10, 5 ) ;
You can also specify this per form by adding the form id after the hook name.
1add_filter( 'gform_paypal_request_1', 'your_function_name', 10, 5 ) ;

Parameters

$url string
The entire url that will be sent to PayPal, including the query string; includes the return url, cancel url, notify url, invoice ID, currency, customer fields, products, quantities, prices, and various other PayPal settings.

$form Form Object
The Form Object of the entry created.

$entry Entry Object
The Entry Object created.

$feed Feed Object
The feed currently 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
Change Return URL
This example changes the 「return」 url in the query string. This is where PayPal returns to after payment is made and should be your form.
12345678910111213141516171819add_filter( 'gform_paypal_request', 'update_url', 10, 3 );function update_url( $url, $form, $entry ) {    //parse url into its individual pieces (host, path, querystring, etc.)    $url_array = parse_url( $url );    //start rebuilding url    $new_url = $url_array['scheme'] . '://' . $url_array['host'] . $url_array['path'] . '?';    $query = $url_array['query']; //get querystring    //parse querystring into pieces    parse_str( $query, $qs_param );    $return = $qs_param['return']; //return url    //parse return url so the querystring is left alone while modifying the url    $return_url = parse_url( $return );    //rebuild url with new location    $new_return_url = $return_url['scheme'] . '://' . 'rocketgenius.com/contact-us/?' . $return_url['query'];    $qs_param['return'] = $new_return_url; //update return querystring parameter to new value    $new_qs = http_build_query( $qs_param ); //rebuild querystring    $new_url .= $new_qs; //add querystring to url    return $new_url;}
Change IPN URL
This example changes IPN URL used by PayPal to notify the payment. Bear in mind using this will avoid Gravity Forms to be able to update entries with the payment details and status. Simply replace https://your_url_here.com with your custom IPN URL.
1234567891011121314add_filter( 'gform_paypal_request', 'update_url', 10, 3 );function update_url( $url, $form, $entry ) {    //parse url into its individual pieces (host, path, querystring, etc.)    $url_array = parse_url( $url );    //start rebuilding url    $new_url = $url_array['scheme'] . '://' . $url_array['host'] . $url_array['path'] . '?';    $query = $url_array['query']; //get querystring    //parse querystring into pieces    parse_str( $query, $qs_param );    $qs_param['notify_url'] = 'https://your_url_here.com'; // update notify_url querystring parameter to new value    $new_qs = http_build_query( $qs_param ); //rebuild querystring    $new_url .= $new_qs; //add querystring to url    return $new_url;}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
1gf_apply_filters( 'gform_paypal_request', $form['id'], $url, $form, $entry, $feed, $submission_data )
This filter is located in GFPayPal::redirect_url() in class-gf-paypal.php.

gform_paypal_query

gform_paypal_query

DescriptionUsageParametersExamplesModify PricingDisable TaxSet the Language CodeAnd your Logo to Checkout pageAdd Invoice numberSet the landing pagePlacementSource Code

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 from 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 Form Object
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
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;
}

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;
}

Set the Language Code
This example shows how you can set the language code. You can find the full list of language codes in PayPal』s developer documentation.
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;
}

And your Logo to Checkout page
This example shows how you can set the image URL to display your logo in PayPal』s checkout page.
add_filter( 'gform_paypal_query', 'add_image_url', 10, 3 );
function add_image_url( $query_string, $form, $entry ) {
// Update 1 to your form id. Remove the if statement if you want to add the image to all forms.
if ( $form['id'] == 1 ) {
$query_string .= '&image_url=https://example.com/some/path/image.png'; // Size of the image must be 150 x 150 pixels
}

return $query_string;
}

Add Invoice number
This example shows how you can populate the invoice parameter with a value from a field in your form.
add_filter( 'gform_paypal_query', 'add_invoice_number', 10, 3 );
function add_invoice_number( $query_string, $form, $entry ) {
// Update 1 with the id number for the field that contains your invoice number
$invoice_number = rgar( $entry, '1' );

// Update 323 with your form id
if ( $form['id'] == 323 ) {
$query_string .= '&invoice=' . $invoice_number;
}

return $query_string;
}

Set the landing page
See this gist from WebAware.
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.

gform_paypal_pre_ipn

gform_paypal_pre_ipn

DescriptionUsageParametersExamplesPlacementSource CodeMore Info

Description
This filter is used to cancel to IPN processing.
Usage
add_filter( 'gform_paypal_pre_ipn', 'your_function_name', 10, 4 );

Parameters

$cancel boolean
False by default. Return as true to cancel IPN processing.

$_POST array
The $_POST array posted by the PayPal IPN.

$entry Entry Object
The entry from which the transaction the IPN is responding to was submitted.

$feed Feed Object
The PayPal feed configuration data used to process the entry the IPN is responding to.

Examples
This example shows how to return a false value and cancel the IPN processing.
add_filter( 'gform_paypal_pre_ipn', 'cancel_ipn' );
function cancel_ipn( $cancel ) {
return true;
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
apply_filters( 'gform_paypal_pre_ipn', false, $_POST, $entry, $feed )

This filter is located in GFPayPal::can_process_ipn() in class-gf-paypal.php.
More Info
For more information on the WordPress add_filter function, refer to the WordPress Code Reference.

gform_paypal_post_ipn

gform_paypal_post_ipn

DescriptionUsageParametersExamplesPlacementSource Code

Description
This hook is fired after a PayPal IPN response has been processed.
Usage
add_action( 'gform_paypal_post_ipn', 'your_function_name', 10, 4) ;

Parameters

$_POST array
The $_POST array posted by the PayPal IPN.

$entry Entry Object
The entry from which the transaction the IPN is responding to was submitted.

$feed Feed Object
The PayPal feed configuration data used to process the entry the IPN is responding to.

$cancel boolean
Defaults to false. Indicates whether the IPN processing was canceled by the gform_paypal_pre_ipn hook.

Examples
This example shows how to update your order on a fictional third party order fulfillment service.
add_action( 'gform_paypal_post_ipn', 'update_order_status', 10, 4 );
function update_order_status( $ipn_post, $entry, $feed, $cancel ) {

// if the IPN was canceled, don't process
if ( $cancel )
return;

// get first and last name from $entry
$order_id = $entry['id'];

// use fictional function to add order to fictional My Third Party application
mtp_update_order( $order_id, $ipn_post );
}

The following example deletes the post associated with the entry when the subscription term ends.
add_action( 'gform_paypal_post_ipn', 'delete_post', 10, 4 );
function delete_post( $ipn_post, $entry, $feed, $cancel ) {

// if the IPN was canceled, don't process
if ( $cancel )
return;

$transaction_type = $ipn_post['txn_type'];

//delete post if this is the end of term
if ( strtolower( $transaction_type ) == 'subscr_eot' ) {
wp_delete_post( $entry['post_id'] );
}
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
do_action( 'gform_paypal_post_ipn', $_POST, $entry, $feed, true )

This hook is located in GFPayPal::can_process_ipn() in class-gf-paypal.php.

gform_paypal_ipn_url

gform_paypal_ipn_url

DescriptionUsageParametersExamplesPlacementSource Code

Description
Allows the PayPal IPN URL to which data is being posted to be modified.
Usage
add_filter( 'gform_paypal_ipn_url', 'your_function_name', 10, 1 );

Parameters

$url string
The IPN URL.

Examples
add_filter( 'gform_paypal_ipn_url', 'change_ipn_url', 10, 1 );
function change_ipn_url( $url ){
//send all requests to the sandbox
return "https://www.sandbox.paypal.com/cgi-bin/webscr/";
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFPayPal::verify_paypal_ipn() in gravityformspaypal/class-gf-paypal.php.

gform_paypal_ipn_{transaction_type}

gform_paypal_ipn_{transaction_type}

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
This action hook allows performing actions for a specific IPN transaction type. The 「{transaction_type}」 will be replaced with the current transaction type.
Usage
add_action( 'gform_paypal_ipn_{transaction_type_to_use}', 'your_function_name, 10, 10 );

Parameters

$entry Entry ObjectThe current entry.
$feed Feed Object
The current feed.
$status string
The status of the transaction. For example: completed, reversed, processed, pending, refunded, and others.
$txn_type string
The transaction type. For example: cart, subscr_payment, subscr_cancel.
$transaction_id int
The transaction id.
$parent_txn_id int
The parent transaction id, in case of some transactions, such as a refund.
$subscriber_id int
The subscriber id.
$amount string
The payment amount.
$pending_reason string
If the payment status is 「Pending」, this will explain why.
$reason string
The reason code.

Examples
add_action( 'gform_paypal_ipn_cart', 'create_note', 10, 10 );
function create_note( $entry, $feed, $status, $txn_type, $transaction_id, $parent_txn_id, $subscriber_id, $amount, $pending_reason, $reason ){
GFFormsModel::add_note( $entry['id'], 0, 'PayPal', 'This is a test.', '' );
}

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms PayPal Standard version 1.9.2.
Source Code
This filter is located in GFPayPal::post_callback() in gravityformspaypal/class-gf-paypal.php.

gform_paypal_invoice

gform_paypal_invoice

DescriptionUsageParametersExamplesSource Code

Description
This filter allows the invoice number, sent to PayPal for the PayPal Standard Add-on, to be changed.
Usage
add_filter( 'gform_paypal_invoice', 'your_function_name', 10, 3 );

Parameters

$invoice_id integer
Empty string.

$form Form Object
The form from which the PayPal transaction was submitted.

$entry Entry Object
The entry used to generate the PayPal transaction.

Examples
This example shows how to use the $entry ID as the invoice ID.
add_filter( 'gform_paypal_invoice', 'change_invoice', 10, 3 );
function change_invoice( $invoice_id, $form, $entry ) {
return rgar( $entry, 'id' );
}

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

gform_paypal_hash_matches

gform_paypal_hash_matches

DescriptionUsageParametersExamplesPlacementSource Code

Description
Allows additional validation of the hash to be performed.
Usage
add_filter( 'gform_paypal_hash_matches', 'your_function_name', 10, 4 );

Parameters

$hash_matches bool
Indicates if the hash matches.

$entry_id int
The ID of the current entry

$hash string
The hash.

$custom_field string
The pipe-delimited string in the IPN from PayPal. This contains the entry id and the hash.

Examples
add_filter( 'gform_paypal_hash_matches', 'validate_hash', 10, 4 );
function validate_hash( $hash_matches, $entry_id, $hash, $custom_field ){
//do further checks on the hash or force failure, whatever
if ( $entry_id > 100 ){
return false;
}
return true;
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFPayPal::get_entry() in gravityformspaypal/class-gf-paypal.php.