gform_paypalpaymentspro_args_before_payment

Description

This filter can be used to modify the product transaction arguments before they are sent to PayPal.

Usage

The filter which would run for all ‘Product’ type PayPal Payments Pro feeds can be used like so:

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

Parameters

  • $args array

    An associative array containing the billing details, payment amount, and line items created using the submitted pricing field values and any discounts from coupons.

  • $form_id integer

    The ID of the form 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. Available from v2.0.

  • $feed Feed Object

    The Feed which is currently being processed. Available from v2.0.

  • $entry Entry Object

    The Entry which is currently being processed. Available from v2.0.

Examples

1. Add New Parameter

The following example shows how you can set the COMMENT1 parameter using the value from a form field. See PayPal API documentation for supported parameters.

add_filter( 'gform_paypalpaymentspro_args_before_payment', function ( $args, $form_id ) {
// Change 3 to the id number of your form.
if ( $form_id == 3 ) {
// Change 5 to the id number of the field containing the information.
$args['COMMENT1'] = rgpost( 'input_5' );
}

return $args;
}, 10, 2 );

2. Map Billing Address to Shipping Address

The following example shows how you can map the billing address to shipping address.

add_filter('gform_paypalpaymentspro_args_before_payment','gf_add_shipping_address', 10, 2 );
function gf_add_shipping_address($args, $form_id) {
gf_paypalpaymentspro()->log_debug( __METHOD__ . '(): Running...' );

$args["SHIPTOLASTNAME"] = $args["LASTNAME"];
$args["SHIPTOSTREET"] = $args["STREET"];
$args["SHIPTOCITY"] = $args["CITY"];
$args["SHIPTOSTATE"] = $args["STATE"];
$args["SHIPTOZIP"] = $args["ZIP"];
$args["SHIPTOCOUNTRY"] = $args["BILLTOCOUNTRY"];

gf_paypalpaymentspro()->log_debug( __METHOD__ . '(): Modified $args: ' . print_r( $args, true ) );

return $args;
}

Placement

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

Source Code

This filter is located in GFPayPalPaymentsPro::authorize() in class-gf-paypalpaymentspro.php.