/** * Get errors, sorted into two buckets - 'general' errors to display at * the top of the form, and 'field' errors to display inline. * Also get some error-related flags. * @return array */ protected function getErrors() { $errors = $this->gateway->getAllErrors(); $return = array('errors' => array('general' => array(), 'field' => array())); $fieldNames = DonationData::getFieldNames(); foreach ($errors as $key => $error) { if (is_array($error)) { // TODO: set errors consistently $message = implode('<br/>', $error); } else { $message = $error; } $errorContext = array('key' => $key, 'message' => $message); if (in_array($key, $fieldNames)) { $return['errors']['field'][$key] = $errorContext; } else { $return['errors']['general'][] = $errorContext; } $return["{$key}_error"] = true; if ($key === 'currency_code' || $key === 'amount') { $return['show_amount_input'] = true; } } return $return; }
public function getRetryData() { $params = array(); foreach ($this->dataObj->getRetryFields() as $field) { $params[$field] = $this->getData_Unstaged_Escaped($field); } return $params; }
/** * 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 */ } }
/** * */ public function testSetNormalizedLanguage_language() { $data = $this->testData; unset($data['uselang']); unset($data['language']); $data['language'] = 'no'; $ddObj = new DonationData($this->getFreshGatewayObject(self::$initial_vars), $data); //change to test mode with explicit test data $returned = $ddObj->getDataEscaped(); $this->assertEquals('no', $returned['language'], "Language 'no' was normalized out of existance. Sad."); $this->assertArrayNotHasKey('uselang', $returned, "'uselang' should have been removed from the data"); }
/** * */ public function testSetNormalizedAmount_noGoodAmount() { $data = $this->testData; $data['amount'] = 'splunge'; $data['amountGiven'] = 'wombat'; $data['amountOther'] = 'macedonia'; //unset($data['zip']); $ddObj = new DonationData('', true, $data); $returned = $ddObj->getDataEscaped(); $this->assertEquals($returned['amount'], 0.0, "Amount was not properly reset"); $this->assertTrue(!array_key_exists('amountOther', $returned), "amountOther should have been removed from the data"); $this->assertTrue(!array_key_exists('amountGiven', $returned), "amountGiven should have been removed from the data"); }