Data Loss while Pledge Creation

Hi,

While debugging the fundraising plugin we came across some anomalies in the code due to which, we think. data is getting lost during pledge creation process in certain cases. @Mainu can you please look into this regard and reply back.

In gateway/paypal.php process_advanced function

this part of code is getting the $_POST values after the form submission

$custom = array();
$custom['reward'] = (isset($_SESSION['wdf_reward'])) ? $_SESSION['wdf_reward'] : 0);
$custom['country'] = (isset($_POST['country']) ? $_POST['country'] : 0 );
$custom['address1'] = (isset($_POST['address1']) ? $_POST['address1'] : 0 );
$custom['address2'] = (isset($_POST['address2']) ? $_POST['address2'] : 0 );
$custom['city'] = (isset($_POST['city']) ? $_POST['city'] : 0 );
$custom['state'] = (isset($_POST['state']) ? $_POST['state'] : 0 );
$custom['zip'] = (isset($_POST['zip']) ? $_POST['zip'] : 0 );

the weird thing is that the isset statement is not working if a record is not present we didnt get a zero but a blank is generated and this upsets the piping structure for the ipn url

for example consider this case in which address 2 is not entered so the query string will not have zero appended in it.

1||America||542 lighthouse ave||||Monterey||California||93940

..................................

this code chunk is making query string with piping structure

$custom_ready = array();
foreach ($custom as $key => $value)
      $custom_ready[$key] = str_replace('||', '', $value);
$custom = implode('||', $custom_ready);

but this code is not considering spaces and these spaces mess up the data in the ipn_handle function. like this is the final piping structure formed

1||United States of America||167 Romaine Dr||address 2||Santa Barbara||CA||93175

so the response we get in ipn_handle function is something like this

Array
(
    [action] => wdf-ipn-return-paypal
    [fundraiser] => 24962
    [pledge_id] => 7f391f078a04
    [custom] => 1||United
    [max_number_of_payments] => null
    [starting_date] => 2015-06-17T00:00:48.000Z
    [pin_type] => NOT_REQUIRED
    [max_amount_per_payment] => 87.21
    [currency_code] => USD
    [sender_email] =>
    [verify_sign] => AiPC9BjkCyDFQXbSkoZcgqH3hhjbhjbjhbjbsT3SOoiB8q5LIxLE0UafKF
    [date_of_month] => 0
    [current_number_of_payments] => 0
    [preapproval_key] => PA-2ND67893SF841481D
    [ending_date] => 2015-06-30T23:59:48.000Z
    [approved] => false
    [transaction_type] => Adaptive Payment PREAPPROVAL
    [day_of_week] => NO_DAY_SPECIFIED
    [status] => Active
    [current_total_amount_of_all_payments] => 0.00
    [current_period_attempts] => 0
    [charset] => UTF-8
    [payment_period] => 0
    [notify_version] => UNVERSIONED
    [max_total_amount_of_all_payments] => 87.21
)

see the custom values from the paypal breaks with a space we only get 1||United not all the information and because of this, this code chunk doesnt work in ipn_handle function

$custom = explode('||',$_REQUEST['custom']);
$possible_custom_fields = array('reward', 'country', 'address1', 'address2', 'city', 'state', 'zip');
foreach ($possible_custom_fields as $key => $possible_custom_field)
          if(isset($custom[$key]) && $custom[$key])
                   $transaction[$possible_custom_field] = $custom[$key];

and the record is lost, so we are not able to understand why these bugs are there in the code. Especially if its working in few cases while not in others.

Looking forward for a prompt reply on this. Thanks