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.

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注