/**
  * Instead of pulling all the DonationData back through to update one local
  * value, use this. It updates both staged_data (which is intended to be
  * staged and used _just_ by the gateway) and unstaged_data, which is actually
  * just normalized and sanitized form data as entered by the user.
  * You should restage the data after running this.
  *
  * Not doing this right now, though, because it's not yet necessary for
  * anything we have at the moment.
  *
  * @param string $val The field name that we are looking to retrieve from
  * our DonationData object.
  */
 function refreshGatewayValueFromSource($val)
 {
     $refreshed = $this->dataObj->getVal_Escaped($val);
     if (!is_null($refreshed)) {
         $this->staged_data[$val] = $refreshed;
         $this->unstaged_data[$val] = $refreshed;
     } else {
         unset($this->staged_data[$val]);
         unset($this->unstaged_data[$val]);
     }
 }
 /**
  * Get the required dynamic form elements
  *
  * The first time a PayflowProGateway credit card form is loaded, there are
  * some dynamic elements that also need to be loaded, primarily for CSRF
  * prevention and tracking data.  This will fetch the values for those
  * elements.
  */
 protected function dispatch_get_required_dynamic_form_elements($params)
 {
     //Get the gateway class name. We don't need to instantiate: Just get the name
     //so we can get a new DonationData that *thinks* it's being instantiated by
     //the relevent gateway class.
     $gateway_class = '';
     switch ($params['gateway']) {
         case 'globalcollect':
             $gateway_class = 'GlobalCollectAdapter';
             break;
         case 'payflowpro':
         default:
             $gateway_class = 'PayflowProAdapter';
             break;
     }
     /**
      * retrieve and unpack the json encoded string of tracking data
      *
      * it should include two bits:
      * 	url => the full url-encoded user-requested URL
      * 	pageref => the url-encoded referrer to the full user-requested URL
      */
     $tracking_data = $this->parseTrackingData(json_decode($params['tracking_data'], true));
     //instantiate a new DonationData that behaves like it's owned by the correct gateway.
     $donationDataObj = new DonationData($gateway_class, false, $tracking_data);
     // fetch the order_id
     $order_id = $donationDataObj->getVal_Escaped('order_id');
     // fetch the CSRF prevention token and set it if it's not already set
     $token = $donationDataObj->token_getSaltedSessionToken();
     //I'd just call DD's saveContributionTracking, but we need all the parts out here.
     $tracking_data = $donationDataObj->getCleanTrackingData();
     $contribution_tracking_id = $donationDataObj::insertContributionTracking($tracking_data);
     // this try/catch design pattern stolen from ClickTracking/ApiSpecialClickTracking.php
     try {
         // add dynamic elements to result object
         $this->getResult()->addValue(array('dynamic_form_elements'), 'order_id', $order_id);
         $this->getResult()->addValue(array('dynamic_form_elements'), 'token', $token);
         $this->getResult()->addValue(array('dynamic_form_elements'), 'contribution_tracking_id', $contribution_tracking_id);
         $this->getResult()->addValue(array('dynamic_form_elements'), 'tracking_data', $tracking_data);
     } catch (Exception $e) {
         /* no result */
     }
 }