Awight has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/342553 )
Change subject: [WIP] A few changes. distinguish between unstaged and normalized, split construct, validate and stage steps. ...................................................................... [WIP] A few changes. distinguish between unstaged and normalized, split construct, validate and stage steps. Bug: T159910 Change-Id: Ib29a85fec1c7ccf11b99c8538651cde792c75e15 --- M adyen_gateway/adyen.adapter.php M amazon_gateway/amazon.adapter.php M astropay_gateway/astropay.adapter.php M extras/FraudFilter.php M extras/banner_history/BannerHistoryLogIdProcessor.php M extras/conversion_log/conversion_log.body.php M extras/custom_filters/custom_filters.body.php M extras/custom_filters/filters/ip_velocity/ip_velocity.body.php M extras/custom_filters/filters/minfraud/minfraud.body.php M extras/custom_filters/filters/referrer/referrer.body.php M extras/custom_filters/filters/source/source.body.php M extras/session_velocity/session_velocity.body.php M gateway_common/DonationData.php M gateway_common/GatewayType.php M gateway_common/gateway.adapter.php M gateway_forms/Form.php M gateway_forms/Mustache.php M gateway_forms/MustacheErrorForm.php M globalcollect_gateway/GlobalCollectOrphanRectifier.php M globalcollect_gateway/globalcollect.adapter.php M globalcollect_gateway/orphan.adapter.php M paypal_gateway/express_checkout/paypal_express.adapter.php M paypal_gateway/legacy/paypal_legacy.adapter.php M tests/phpunit/Adapter/Adyen/AdyenTest.php M tests/phpunit/Adapter/Amazon/AmazonTest.php M tests/phpunit/Adapter/AstroPay/AstroPayTest.php M tests/phpunit/Adapter/GatewayAdapterTest.php M tests/phpunit/Adapter/GlobalCollect/BankTransferTest.php M tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php M tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php M tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php M tests/phpunit/Adapter/GlobalCollect/YandexTest.php M tests/phpunit/Adapter/PayPal/PayPalLegacyTest.php M tests/phpunit/DonationInterfaceTestCase.php M tests/phpunit/GatewayPageTest.php 35 files changed, 343 insertions(+), 353 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/53/342553/1 diff --git a/adyen_gateway/adyen.adapter.php b/adyen_gateway/adyen.adapter.php index 140fa6b..e94b086 100644 --- a/adyen_gateway/adyen.adapter.php +++ b/adyen_gateway/adyen.adapter.php @@ -98,23 +98,6 @@ //'deliveryAddressType', ); - // Add address fields for countries that use them. - $addressFields = array ( - 'billingAddress.street', - 'billingAddress.city', - 'billingAddress.postalCode', - 'billingAddress.stateOrProvince', - 'billingAddress.country', - 'billingAddressType', - 'billingAddress.houseNumberOrName', - ); - - if ( in_array( 'street', $this->getRequiredFields() ) ) { - $requestFields = array_merge( $requestFields, $addressFields ); - } - - - $this->transactions[ 'donate' ] = array( 'request' => $requestFields, 'values' => array( @@ -131,6 +114,30 @@ ); } + public function stageData() { + parent::stageData(); + + $this->tuneTransactions(); + } + + protected function tuneTransactions() { + if ( in_array( 'street', $this->getRequiredFields() ) ) { + // Add address fields for countries that use them. + $addressFields = array ( + 'billingAddress.street', + 'billingAddress.city', + 'billingAddress.postalCode', + 'billingAddress.stateOrProvince', + 'billingAddress.country', + 'billingAddressType', + 'billingAddress.houseNumberOrName', + ); + + $requestFields &= $this->transactions['donate']['request']; + $requestFields = array_merge( $requestFields, $addressFields ); + } + } + protected function getAllowedPaymentMethods() { return array( 'card', diff --git a/amazon_gateway/amazon.adapter.php b/amazon_gateway/amazon.adapter.php index 151bbd1..9a916cf 100644 --- a/amazon_gateway/amazon.adapter.php +++ b/amazon_gateway/amazon.adapter.php @@ -57,13 +57,12 @@ function __construct( $options = array() ) { parent::__construct( $options ); + } - if ( $this->getData_Unstaged_Escaped( 'payment_method' ) == null ) { - $this->addRequestData( - array( 'payment_method' => 'amazon' ) - ); - } - $this->session_addDonorData(); + function setGatewayDefaults( $options = array() ) { + $this->addRequestData( + array( 'payment_method' => 'amazon' ) + ); } public function getCommunicationType() { @@ -123,7 +122,7 @@ } try { - if ( $this->getData_Unstaged_Escaped( 'recurring' ) === '1' ) { + if ( $this->getNormalized( 'recurring' ) === '1' ) { $this->confirmBillingAgreement(); $this->authorizeAndCapturePayment( true ); } else { diff --git a/astropay_gateway/astropay.adapter.php b/astropay_gateway/astropay.adapter.php index 950f5b4..4aaaff6 100644 --- a/astropay_gateway/astropay.adapter.php +++ b/astropay_gateway/astropay.adapter.php @@ -365,7 +365,7 @@ } else if ( preg_match( '/invalid control/i', $response['desc'] ) ) { // They think we screwed up the signature. Log what we signed. $signed = AstroPaySignature::getNewInvoiceMessage( - $this->getData_Staged() + $this->getData_Staged_All() ); $signature = $this->getData_Staged( 'control' ); $this->logger->error( "$logme Signed message: '$signed' Signature: '$signature'" ); diff --git a/extras/FraudFilter.php b/extras/FraudFilter.php index 9113c88..a130b41 100644 --- a/extras/FraudFilter.php +++ b/extras/FraudFilter.php @@ -29,7 +29,7 @@ 'risk_score' => $totalScore, 'score_breakdown' => $scoreBreakdown, 'php-message-class' => 'SmashPig\CrmLink\Messages\DonationInterfaceAntifraud', - 'user_ip' => $this->gateway_adapter->getData_Unstaged_Escaped( 'user_ip' ), + 'user_ip' => $this->gateway_adapter->getNormalized( 'user_ip' ), ); //If we need much more here to help combat fraud, we could just //start stuffing the whole maxmind query in the fredge, too. diff --git a/extras/banner_history/BannerHistoryLogIdProcessor.php b/extras/banner_history/BannerHistoryLogIdProcessor.php index ecc7206..6f2cebe 100644 --- a/extras/banner_history/BannerHistoryLogIdProcessor.php +++ b/extras/banner_history/BannerHistoryLogIdProcessor.php @@ -58,7 +58,7 @@ } $contributionTrackingId = $this->gatewayAdapter - ->getData_Unstaged_Escaped( 'contribution_tracking_id' ); + ->getNormalized( 'contribution_tracking_id' ); if ( !$contributionTrackingId ) { $this->logger->info( 'No contribution tracking ID for ' . diff --git a/extras/conversion_log/conversion_log.body.php b/extras/conversion_log/conversion_log.body.php index 07e19ba..71e962a 100644 --- a/extras/conversion_log/conversion_log.body.php +++ b/extras/conversion_log/conversion_log.body.php @@ -11,7 +11,7 @@ // if the trxn has been outright rejected, log it if ( $this->gateway_adapter->getValidationAction() == 'reject' ) { $this->log( - $this->gateway_adapter->getData_Unstaged_Escaped( 'contribution_tracking_id' ), 'Rejected' + $this->gateway_adapter->getNormalized( 'contribution_tracking_id' ), 'Rejected' ); return true; } @@ -23,9 +23,7 @@ } $this->log( - $this->gateway_adapter->getData_Unstaged_Escaped( - 'contribution_tracking_id' - ), + $this->gateway_adapter->getNormalized( 'contribution_tracking_id' ), "Gateway response: " . addslashes( $response->getTxnMessage() ), '"' . addslashes( json_encode( $response->getData() ) ) . '"' diff --git a/extras/custom_filters/custom_filters.body.php b/extras/custom_filters/custom_filters.body.php index 2b45757..393fea7 100644 --- a/extras/custom_filters/custom_filters.body.php +++ b/extras/custom_filters/custom_filters.body.php @@ -137,9 +137,9 @@ $this->fraud_logger->info( '"CustomFiltersScores" ' . $log_message ); $utm = array( - 'utm_campaign' => $this->gateway_adapter->getData_Unstaged_Escaped( 'utm_campaign' ), - 'utm_medium' => $this->gateway_adapter->getData_Unstaged_Escaped( 'utm_medium' ), - 'utm_source' => $this->gateway_adapter->getData_Unstaged_Escaped( 'utm_source' ), + 'utm_campaign' => $this->gateway_adapter->getNormalized( 'utm_campaign' ), + 'utm_medium' => $this->gateway_adapter->getNormalized( 'utm_medium' ), + 'utm_source' => $this->gateway_adapter->getNormalized( 'utm_source' ), ); $log_message = '"' . addslashes( json_encode( $utm ) ) . '"'; $this->fraud_logger->info( '"utm" ' . $log_message ); diff --git a/extras/custom_filters/filters/ip_velocity/ip_velocity.body.php b/extras/custom_filters/filters/ip_velocity/ip_velocity.body.php index 9b05f21..6231b86 100644 --- a/extras/custom_filters/filters/ip_velocity/ip_velocity.body.php +++ b/extras/custom_filters/filters/ip_velocity/ip_velocity.body.php @@ -33,7 +33,7 @@ } protected function filter() { - $user_ip = $this->gateway_adapter->getData_Unstaged_Escaped( 'user_ip' ); + $user_ip = $this->gateway_adapter->getNormalized( 'user_ip' ); //first, handle the whitelist / blacklist before you do anything else. if ( DataValidator::ip_is_listed( $user_ip, $this->gateway_adapter->getGlobal( 'IPWhitelist' ) ) ) { @@ -79,7 +79,7 @@ protected function getCachedValue(){ //check to see if the user ip is in memcache - $user_ip = $this->gateway_adapter->getData_Unstaged_Escaped( 'user_ip' ); + $user_ip = $this->gateway_adapter->getNormalized( 'user_ip' ); $stored = $this->cache_obj->get( $user_ip ); return $stored; } @@ -111,7 +111,7 @@ $timeout = $this->gateway_adapter->getGlobal( 'IPVelocityTimeout' ); } - $user_ip = $this->gateway_adapter->getData_Unstaged_Escaped( 'user_ip' ); + $user_ip = $this->gateway_adapter->getNormalized( 'user_ip' ); $ret = $this->cache_obj->set( $user_ip, self::addNowToVelocityData( $oldvalue, $timeout ), $timeout ); if (!$ret){ $this->gateway_logger->alert( "IPVelocityFilter unable to set new memcache data." ); @@ -204,7 +204,7 @@ public static function penalize( GatewayType $gateway ) { $logger = DonationLoggerFactory::getLogger( $gateway ); $logger->info( 'IPVelocityFilter penalizing IP address ' - . $gateway->getData_Unstaged_Escaped( 'user_ip' ) + . $gateway->getNormalized( 'user_ip' ) . ' for toxic card attempt.' ); $velocity = Gateway_Extras_CustomFilters_IP_Velocity::singleton( diff --git a/extras/custom_filters/filters/minfraud/minfraud.body.php b/extras/custom_filters/filters/minfraud/minfraud.body.php index 03786a2..dd742ac 100644 --- a/extras/custom_filters/filters/minfraud/minfraud.body.php +++ b/extras/custom_filters/filters/minfraud/minfraud.body.php @@ -156,7 +156,7 @@ $this->minfraudQuery["license_key"] = $this->minfraudLicenseKey; // user's IP address - $this->minfraudQuery["i"] = ( $this->gateway_adapter->getData_Unstaged_Escaped( 'user_ip' ) ); + $this->minfraudQuery["i"] = ( $this->gateway_adapter->getNormalized( 'user_ip' ) ); // We only have access to these fields when the user's request is still // present, but not when in batch mode. @@ -215,8 +215,11 @@ */ protected function can_bypass_minfraud() { // if the data bits data_hash and action are not set, we need to hit minFraud - $localdata = $this->gateway_adapter->getData_Unstaged_Escaped(); - if ( !isset($localdata['data_hash']) || !strlen( $localdata['data_hash'] ) || !isset($localdata['action']) || !strlen( $localdata['action'] ) ) { + // FIXME: I think we want the raw post, without calculated fields. + $localdata = $this->gateway_adapter->getData_Unstaged_Escaped_All(); + if ( empty($localdata['data_hash']) + || empty($localdata['action']) + ) { return FALSE; } @@ -227,7 +230,8 @@ // compare the data hash to make sure it's legit if ( $this->compare_hash( $data_hash, serialize( $localdata ) ) ) { - $this->gateway_adapter->setHash( $this->generate_hash( $this->gateway_adapter->getData_Unstaged_Escaped() ) ); // hash the data array + // FIXME: Looks like we just hashed the same data twice, can't we pass $data_hash now? + $this->gateway_adapter->setHash( $this->generate_hash( $localdata ) ); // hash the data array // check to see if we have a valid action set for us to bypass minfraud $actions = array( 'process', 'challenge', 'review', 'reject' ); $action_hash = $localdata['action']; // a hash of the action to take passed in by the form submission @@ -257,7 +261,8 @@ return TRUE; } - $minfraud_query = $this->build_query( $this->gateway_adapter->getData_Unstaged_Escaped() ); + // TODO: or posted fields? + $minfraud_query = $this->build_query( $this->gateway_adapter->getData_Unstaged_Escaped_All() ); $this->query_minfraud( $minfraud_query ); // Write the query/response to the log before we go mad. @@ -321,10 +326,10 @@ $log_message = ''; $log_message .= "\t" . '"' . date( 'c' ) . '"'; - $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData_Unstaged_Escaped( 'amount' ) . ' ' . $this->gateway_adapter->getData_Unstaged_Escaped( 'currency_code' ) ) . '"'; + $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getNormalized( 'amount' ) . ' ' . $this->gateway_adapter->getNormalized( 'currency_code' ) ) . '"'; $log_message .= "\t" . '"' . addslashes( json_encode( $this->minfraudQuery ) ) . '"'; $log_message .= "\t" . '"' . addslashes( json_encode( $encoded_response ) ) . '"'; - $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getData_Unstaged_Escaped( 'referrer' ) ) . '"'; + $log_message .= "\t" . '"' . addslashes( $this->gateway_adapter->getNormalized( 'referrer' ) ) . '"'; $this->fraud_logger->info( '"minFraud query" ' . $log_message ); } diff --git a/extras/custom_filters/filters/referrer/referrer.body.php b/extras/custom_filters/filters/referrer/referrer.body.php index 1745979..2fc69a7 100644 --- a/extras/custom_filters/filters/referrer/referrer.body.php +++ b/extras/custom_filters/filters/referrer/referrer.body.php @@ -25,7 +25,7 @@ protected function filter() { // pull out the referrer from the gateway_adapter - $referrer = $this->gateway_adapter->getData_Unstaged_Escaped( 'referrer' ); + $referrer = $this->gateway_adapter->getNormalized( 'referrer' ); // a very complex filtering algorithm for referrers $refRules = $this->gateway_adapter->getGlobal( 'CustomFiltersRefRules' ); @@ -43,7 +43,7 @@ $log_msg .= "\t\"" . addslashes( $regex ) . "\""; $log_msg .= "\t\"" . $this->cfo->getRiskScore() . "\""; $this->log( - $this->gateway_adapter->getData_Unstaged_Escaped( 'contribution_tracking_id' ), 'Filter: Referrer', $log_msg + $this->gateway_adapter->getNormalized( 'contribution_tracking_id' ), 'Filter: Referrer', $log_msg ); } } diff --git a/extras/custom_filters/filters/source/source.body.php b/extras/custom_filters/filters/source/source.body.php index 705d687..af392d3 100644 --- a/extras/custom_filters/filters/source/source.body.php +++ b/extras/custom_filters/filters/source/source.body.php @@ -25,7 +25,7 @@ protected function filter() { // pull out the source from the filter object - $source = $this->gateway_adapter->getData_Unstaged_Escaped( 'utm_source' ); + $source = $this->gateway_adapter->getNormalized( 'utm_source' ); // a very complex filtering algorithm for sources $srcRules = $this->gateway_adapter->getGlobal( 'CustomFiltersSrcRules' ); @@ -42,7 +42,7 @@ $log_msg .= "\t\"" . addslashes( $regex ) . "\""; $log_msg .= "\t\"" . $this->cfo->getRiskScore() . "\""; $this->log( - $this->gateway_adapter->getData_Unstaged_Escaped( 'contribution_tracking_id' ), 'Filter: Source', $log_msg + $this->gateway_adapter->getNormalized( 'contribution_tracking_id' ), 'Filter: Source', $log_msg ); } } diff --git a/extras/session_velocity/session_velocity.body.php b/extras/session_velocity/session_velocity.body.php index 597b771..f0948f1 100644 --- a/extras/session_velocity/session_velocity.body.php +++ b/extras/session_velocity/session_velocity.body.php @@ -69,7 +69,7 @@ */ private function filter() { - $user_ip = $this->gateway_adapter->getData_Unstaged_Escaped( 'user_ip' ); + $user_ip = $this->gateway_adapter->getNormalized( 'user_ip' ); // Determine IP status before doing anything complex $wl = DataValidator::ip_is_listed( $user_ip, $this->gateway_adapter->getGlobal( 'IPWhitelist' ) ); diff --git a/gateway_common/DonationData.php b/gateway_common/DonationData.php index 72aac42..28d7ba9 100644 --- a/gateway_common/DonationData.php +++ b/gateway_common/DonationData.php @@ -102,53 +102,52 @@ /** * DonationData constructor * @param GatewayAdapter $gateway - * @param mixed $data An optional array of donation data that will, if - * present, circumvent the usual process of gathering the data from various - * places in the request, or 'false' to gather the data the usual way. - * Default is false. */ - function __construct( GatewayType $gateway, $data = false ) { + public function __construct( GatewayType $gateway, $data = false ) { $this->gateway = $gateway; $this->gatewayID = $this->gateway->getIdentifier(); $this->logger = DonationLoggerFactory::getLogger( $gateway, '', $this ); - $this->populateData( $data ); } /** - * populateData, called on construct, pulls donation data from various - * sources. Once the data has been pulled, it will handle any session data - * if present, normalize the data regardless of the source, and handle the - * caching variables. - * @param mixed $external_data An optional array of donation data that will, - * if present, circumvent the usual process of gathering the data from - * various places in the request, or 'false' to gather the data the usual way. - * Default is false. + * Adds an array of data to the normalized array, and then re-normalizes it. + * NOTE: If any gateway is using this function, it should then immediately + * repopulate its own data set with the DonationData source, and then + * re-stage values as necessary. + * + * @param array $newdata An array of data to integrate with the existing + * data held by the DonationData object. */ - protected function populateData( $external_data = false ) { - $this->normalized = array(); - if ( is_array( $external_data ) ) { - //I don't care if you're a test or not. At all. - $this->normalized = $external_data; - } else { - foreach ( self::$fieldNames as $var ) { - $this->normalized[$var] = $this->sourceHarvest( $var ); + public function addData( $newdata ) { + if ( is_array( $newdata ) && !empty( $newdata ) ) { + foreach ( $newdata as $key => $val ) { + if ( !is_array( $val ) ) { + $this->setVal( $key, $val ); + } } + } - if ( !$this->wasPosted() ) { - $this->setVal( 'posted', false ); - } + $this->normalize(); + } + + /** + * Gather data from all sources. + * + * TODO: Harvesting should be split into its own class. + */ + public function harvestData() { + foreach ( self::$fieldNames as $var ) { + $this->normalized[$var] = $this->sourceHarvest( $var ); + } + + if ( !$this->wasPosted() ) { + $this->setVal( 'posted', false ); } //if we have saved any donation data to the session, pull them in as well. $this->integrateDataFromSession(); - // We have some data, so normalize it. - if ( $this->normalized ) { - $this->normalize(); - - // FIXME: This should be redundant now? - $this->expungeNulls(); - } + $this->normalize(); } public static function getFieldNames() { @@ -246,16 +245,14 @@ } /** - * Sets a key in the normalized data array, to a new value. - * This function should only ever be used for keys that are not listed in - * DonationData::getCalculatedFields(). - * TODO: If the $key is listed in DonationData::getCalculatedFields(), use - * DonationData::addData() instead. Or be a jerk about it and throw an - * exception. (Personally I like the second one) + * Sets a value in the normalized data array. + * + * You rascal, don't even think about it--use DonationData::addData() instead. + * * @param string $key The key you want to set. * @param string $val The value you'd like to assign to the key. */ - public function setVal( $key, $val ) { + protected function setVal( $key, $val ) { // Convert empty to null for consistency. if ( $val === '' ) { $val = null; @@ -269,6 +266,9 @@ /** * Removes a value from $this->normalized. + * + * TODO: Why is this exposed as public? + * * @param string $key type */ public function expunge( $key ) { @@ -874,26 +874,6 @@ } } return $ctid; - } - - /** - * Adds an array of data to the normalized array, and then re-normalizes it. - * NOTE: If any gateway is using this function, it should then immediately - * repopulate its own data set with the DonationData source, and then - * re-stage values as necessary. - * - * @param array $newdata An array of data to integrate with the existing - * data held by the DonationData object. - */ - public function addData( $newdata ) { - if ( is_array( $newdata ) && !empty( $newdata ) ) { - foreach ( $newdata as $key => $val ) { - if ( !is_array( $val ) ) { - $this->setVal( $key, $val ); - } - } - } - $this->normalize(); } /** diff --git a/gateway_common/GatewayType.php b/gateway_common/GatewayType.php index f6d66d8..c5184ed 100644 --- a/gateway_common/GatewayType.php +++ b/gateway_common/GatewayType.php @@ -206,8 +206,16 @@ function getResponseType(); /** - * This is the ONLY getData type function anything should be using - * outside the adapter. + * @param string $key Key into data. + * @return string Normalized data, the most reliable and canonical value. + * Always use normalized data if you want sensitive values like user_ip or + * country. + * FIXME: oops, should we continue the heinous convention and spell getData_Normalized? + */ + public function getNormalized( $key ); + public function getNormalized_All(); + + /** * Short explanation of the data population up to now: * *) When the gateway adapter is constructed, it constructs a DonationData * object. @@ -220,7 +228,8 @@ * sanitized) data sent to the adapter, or if $val was set, either the * specific value held for $val, or null if none exists. */ - public function getData_Unstaged_Escaped( $val = '' ); + public function getData_Unstaged_Escaped( $key ); + public function getData_Unstaged_Escaped_All(); /** * Get metadata for the specified payment method as set in diff --git a/gateway_common/gateway.adapter.php b/gateway_common/gateway.adapter.php index a7b360d..cd66cb7 100644 --- a/gateway_common/gateway.adapter.php +++ b/gateway_common/gateway.adapter.php @@ -247,16 +247,6 @@ $this->session_resetOnSwitch(); // Need to do this before creating DonationData - // FIXME: this should not have side effects like setting order_id_meta['final'] - // TODO: On second thought, neither set data nor validate in this constructor. - $this->dataObj = new DonationData( $this, $options['external_data'] ); - - $this->unstaged_data = $this->dataObj->getData(); - $this->staged_data = $this->unstaged_data; - - // checking to see if we have an edit token in the request... - $this->posted = ( $this->dataObj->wasPosted() && ( !is_null( WmfFramework::getRequestValue( 'wmf_token', null ) ) ) ); - $this->findAccount(); $this->defineAccountInfo(); $this->defineTransactions(); @@ -265,22 +255,6 @@ $this->defineReturnValueMap(); $this->setGatewayDefaults( $options ); - - // FIXME: Same as above, don't validate or stage in the constructor. - $this->validate(); - - $this->stageData(); - - BannerHistoryLogIdProcessor::onGatewayReady( $this ); - Gateway_Extras_CustomFilters::onGatewayReady( $this ); - - if ( $this->getValidationAction() !== 'process' ) { - $this->finalizeInternalStatus( FinalStatus::FAILED ); - $error = array( 'general' => array( 'internal-0001' => - $this->getErrorMapByCodeAndTranslate( 'internal-0001' ) - ) ); - $this->mergeError( $error ); - } } /** @@ -426,27 +400,7 @@ $this->debugarray[] = 'Token MISMATCH'; } - $this->refreshGatewayValueFromSource( 'wmf_token' ); return $checkResult; - } - - /** - * Returns staged data from the adapter object, or null if a key was - * specified and no value exsits. - * @param string $val An optional specific key you want returned. - * @return mixed All the staged data held by the adapter, or if a key was - * set, the staged value for that key. - */ - protected function getData_Staged( $val = '' ) { - if ( $val === '' ) { - return $this->staged_data; - } else { - if ( array_key_exists( $val, $this->staged_data ) ) { - return $this->staged_data[$val]; - } else { - return null; - } - } } public function getCoreDataTransformers() { @@ -461,6 +415,41 @@ } /** + * Load submitted data, normalize it and store in various registers. + * + * @param array $data Entire parameter map. + */ + protected function populateDonorData( $data ) { + // FIXME: this should not have side effects like setting order_id_meta['final'] + $this->dataObj = new DonationData( $this, $data ); + + // TODO: Stage or unstage intentionally, not as a side effect of submit or normalization. + $this->unstaged_data = $this->dataObj->getData(); + $this->staged_data = $this->unstaged_data; + + // Checking to see if we have an edit token in the request, otherwise + // we're not allowed to post. + $this->posted = ( $this->dataObj->wasPosted() && ( !is_null( WmfFramework::getRequestValue( 'wmf_token', null ) ) ) ); + + $this->validate(); + + $this->stageData(); + + BannerHistoryLogIdProcessor::onGatewayReady( $this ); + Gateway_Extras_CustomFilters::onGatewayReady( $this ); + + if ( $this->getValidationAction() !== 'process' ) { + $this->finalizeInternalStatus( FinalStatus::FAILED ); + $error = array( 'general' => array( 'internal-0001' => + $this->getErrorMapByCodeAndTranslate( 'internal-0001' ) + ) ); + $this->mergeError( $error ); + } + + $this->session_addDonorData(); + } + + /** * A helper function to let us stash extra data after the form has been submitted. * * @param array $dataArray An associative array of data. @@ -468,16 +457,8 @@ public function addRequestData( $dataArray ) { $this->dataObj->addData( $dataArray ); - $calculated_fields = $this->dataObj->getCalculatedFields(); - $data_fields = array_keys( $dataArray ); - $data_fields = array_merge( $data_fields, $calculated_fields ); - - foreach ( $data_fields as $value ) { - $this->refreshGatewayValueFromSource( $value ); - } - // Always restage after changing unstaged_data - $this->stageData(); + $this->populateDonorData(); } /** @@ -502,6 +483,42 @@ } $this->logger->debug( "Adding response data: " . json_encode( $newlyUnstagedData ) ); $this->dataObj->addData( $newlyUnstagedData ); + } + + public function getNormalized( $key ) { + $normalized = $this->dataObj->getData(); + if ( array_key_exists( $key, $normalized ) ) { + return $normalized[$key]; + } else { + return null; + } + } + + public function getNormalized_All() { + return $this->dataObj->getData(); + } + + /** + * Returns staged data from the adapter object, or null if a key was + * specified and no value exsits. + * + * @param string $key The key you want data returned for. + * @return mixed The staged value for that key. + * (TODO: Is this always a string?) + */ + protected function getData_Staged( $key ) { + if ( array_key_exists( $key, $this->staged_data ) ) { + return $this->staged_data[$key]; + } else { + return null; + } + } + + /** + * @return array All the staged fields, e.g. for a signature function. + */ + protected function getData_Staged_All() { + return $this->staged_data; } /** @@ -532,16 +549,19 @@ return $staged_data; } - public function getData_Unstaged_Escaped( $val = '' ) { - if ( $val === '' ) { - return $this->unstaged_data; + /** + * @return string Unstaged value returned from PSP communication. + */ + public function getData_Unstaged_Escaped( $key ) { + if ( array_key_exists( $key, $this->unstaged_data ) ) { + return $this->unstaged_data[$key]; } else { - if ( array_key_exists( $val, $this->unstaged_data ) ) { - return $this->unstaged_data[$val]; - } else { - return null; - } + return null; } + } + + public function getData_Unstaged_Escaped_All() { + return $this->unstaged_data; } static function getGlobal( $varname ) { @@ -565,8 +585,8 @@ */ public function localizeGlobal( $varname ) { $value = self::getGlobal( $varname ); - $language = $this->getData_Unstaged_Escaped( 'language' ); - $country = $this->getData_Unstaged_Escaped( 'country' ); + $language = $this->getNormalized( 'language' ); + $country = $this->getNormalized( 'country' ); $value = str_replace( '$language', $language, $value ); $value = str_replace( '$country', $country, $value ); return $value; @@ -909,7 +929,9 @@ * @return PaymentTransactionResponse */ public function do_transaction( $transaction ) { + // FIXME: Review whether this is still necessary. $this->session_addDonorData(); + if ( !$this->validatedOK() ){ //If the data didn't validate okay, prevent all data transmissions. // TODO: Rename variable to "response". @@ -941,9 +963,7 @@ $this->regenerateOrderID(); // Pull anything changed from dataObj - $this->unstaged_data = $this->dataObj->getData(); - $this->staged_data = $this->unstaged_data; - $this->stageData(); + $this->populateDonorData( $this->dataObj->getData() ); } } while ( ( !empty( $retryVars ) ) && ( ++$retryCount < $loopCount ) ); @@ -1012,7 +1032,7 @@ //in the event that we have a redirect transaction that never displays the form, //save this most recent one before we leave. - $this->session_pushFormName( $this->getData_Unstaged_Escaped( 'ffname' ) ); + $this->session_pushFormName( $this->getNormalized( 'ffname' ) ); $this->transaction_response->setCommunicationStatus( true ); @@ -1227,7 +1247,7 @@ */ public function getPaymentMethod() { // FIXME: this should return the final calculated method - return $this->getData_Unstaged_Escaped( 'payment_method' ); + return $this->getNormalized( 'payment_method' ); } /** @@ -1242,7 +1262,7 @@ } public function getPaymentSubmethod() { - return $this->getData_Unstaged_Escaped( 'payment_submethod' ); + return $this->getNormalized( 'payment_submethod' ); } public function getPaymentSubmethods() { @@ -1272,7 +1292,7 @@ $retval = false; // By default return that we failed $gatewayName = self::getGatewayName(); - $email = $this->getData_Unstaged_Escaped( 'email' ); + $email = $this->getNormalized( 'email' ); /** * This log line is pretty important. Usually when a donor contacts us @@ -1438,7 +1458,7 @@ // Avoid 'bad ffname' logspam on return and try again links. // TODO: deprecate - $this->session_pushFormName( $this->getData_Unstaged_Escaped( 'ffname' ) ); + $this->session_pushFormName( $this->getNormalized( 'ffname' ) ); } /** @@ -1779,10 +1799,8 @@ ); // Add the rest of the relevant data - // FIXME: This is "normalized" data. We should refer to it as such, - // and rename the getData_Unstaged_Escaped function. $stomp_data = array_intersect_key( - $this->getData_Unstaged_Escaped(), + $this->getNormalized(), array_flip( $this->dataObj->getMessageFields() ) ); @@ -1822,14 +1840,14 @@ 'payment_method', //the stomp sender gets mad if we don't have this. @TODO: Stop being lazy someday. ); foreach ( $these_too as $field ) { - $transaction[$field] = $this->getData_Unstaged_Escaped( $field ); + $transaction[$field] = $this->getNormalized( $field ); } return $transaction; } protected function getCorrelationID(){ - return $this->getIdentifier() . '-' . $this->getData_Unstaged_Escaped('order_id'); + return $this->getIdentifier() . '-' . $this->getNormalized('order_id'); } /** @@ -2043,7 +2061,7 @@ ); foreach ( $keys as $key ) { - $msg .= $this->getData_Unstaged_Escaped( $key ) . ', '; + $msg .= $this->getNormalized( $key ) . ', '; } $txn_message = $this->getTransactionMessage(); @@ -2075,7 +2093,7 @@ ); foreach ( $keys as $key ) { - $transaction[$key] = $this->getData_Unstaged_Escaped( $key ); + $transaction[$key] = $this->getNormalized( $key ); } $transaction = $this->makeFreeformStompTransaction( $transaction ); @@ -2220,7 +2238,9 @@ } public function setHash( $hashval ) { - $this->dataObj->setVal( 'data_hash', $hashval ); + $this->dataObj->addData( array( + 'data_hash' => $hashval, + ) ); } public function unsetHash() { @@ -2271,7 +2291,7 @@ } protected function sendPendingMessage() { - $order_id = $this->getData_Unstaged_Escaped( 'order_id' ); + $order_id = $this->getNormalized( 'order_id' ); $this->logger->info( "Sending donor details for $order_id to pending queue" ); DonationQueue::instance()->push( $this->getStompTransaction(), 'pending' ); } @@ -2297,30 +2317,6 @@ return $this->transactions[$transaction][$option_value]; } return NULL; - } - - /** - * 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( $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] ); - } } public function setRiskScore( $score ) { @@ -2374,7 +2370,7 @@ // Add any country-specific required fields if ( isset( $this->config['country_fields'] ) ) { - $country = $this->getData_Unstaged_Escaped( 'country' ); + $country = $this->getNormalized( 'country' ); if ( $country && isset( $this->config['country_fields'][$country] ) ) { $validation = $this->config['country_fields'][$country]; } @@ -2412,7 +2408,7 @@ //however, that's not happening in this class in the code I'm replacing, so... //TODO: Something clever in the DataValidator with data groups like these. ); - $country = $this->getData_Unstaged_Escaped( 'country' ); + $country = $this->getNormalized( 'country' ); if ( $country && Subdivisions::getByCountry( $country ) ) { $check_not_empty[] = 'state'; } @@ -2584,8 +2580,8 @@ * @return integer */ public function getScoreName(){ - $fName = $this->getData_Unstaged_Escaped( 'fname' ); - $lName = $this->getData_Unstaged_Escaped( 'lname' ); + $fName = $this->getNormalized( 'fname' ); + $lName = $this->getNormalized( 'lname' ); $nameArray = str_split( strtolower( $fName . $lName ) ); $rules = $this->getGlobal( 'NameFilterRules' ); @@ -2639,7 +2635,7 @@ $score = 0; - $country = $this->getData_Unstaged_Escaped( 'country' ); + $country = $this->getNormalized( 'country' ); $countryMap = $this->getGlobal( 'CountryMap' ); @@ -2679,7 +2675,7 @@ $score = 0; - $email = $this->getData_Unstaged_Escaped( 'email' ); + $email = $this->getNormalized( 'email' ); $emailDomain = substr( strstr( $email, '@' ), 1 ); @@ -2723,7 +2719,7 @@ $score = 0; - $campaign = $this->getData_Unstaged_Escaped( 'utm_campaign' ); + $campaign = $this->getNormalized( 'utm_campaign' ); $campaignMap = $this->getGlobal( 'UtmCampaignMap' ); $msg = self::getGatewayName() . ': UTM Campaign map: ' @@ -2767,7 +2763,7 @@ $score = 0; - $medium = $this->getData_Unstaged_Escaped( 'utm_medium' ); + $medium = $this->getNormalized( 'utm_medium' ); $mediumMap = $this->getGlobal( 'UtmMediumMap' ); $msg = self::getGatewayName() . ': UTM Medium map: ' @@ -2810,7 +2806,7 @@ $score = 0; - $source = $this->getData_Unstaged_Escaped( 'utm_source' ); + $source = $this->getNormalized( 'utm_source' ); $sourceMap = $this->getGlobal( 'UtmSourceMap' ); $msg = self::getGatewayName() . ': UTM Source map: ' @@ -2907,7 +2903,7 @@ $data = array(); foreach ( $sessionFields as $field ) { - $data[$field] = $this->getData_Unstaged_Escaped( $field ); + $data[$field] = $this->getNormalized( $field ); } WmfFramework::setSessionValue( 'Donor', $data ); } @@ -3116,7 +3112,7 @@ if ( !$ffname ) { return false; } - $data = $this->getData_Unstaged_Escaped(); + $data = $this->getNormalized_All(); //have to check to see if the last loaded form is *still* valid. if ( GatewayFormChooser::isValidForm( $ffname, $data ) ) { return $ffname; @@ -3184,7 +3180,7 @@ WmfFramework::setSessionValue( $gateway_ident . 'EditToken', $unsalted ); $salted = $this->token_getSaltedSessionToken(); - $this->addRequestData( array ( 'wmf_token' => $salted ) ); + $this->addRequestData( array( 'wmf_token' => $salted ) ); } /** @@ -3236,7 +3232,7 @@ if ( !$this->dataObj->isSomething( 'wmf_token' ) ) { $this->addRequestData( array ( 'wmf_token' => $token ) ); } - $token_check = $this->getData_Unstaged_Escaped( 'wmf_token' ); + $token_check = $this->getNormalized( 'wmf_token' ); $match = $this->token_matchEditToken( $token_check ); if ( $this->dataObj->wasPosted() ) { @@ -3507,8 +3503,10 @@ //tell DonationData about it $this->addRequestData( array ( 'order_id' => $id ) ); + // Add new Order ID to the session. $this->session_addDonorData(); + return $id; } @@ -3601,7 +3599,7 @@ $this->unstaged_data // need data for country filter && isset( $available_submethod['countries'] ) // if the list exists, the current country key needs to exist and have a true value - && empty( $available_submethod['countries'][$this->getData_Unstaged_Escaped( 'country' )] ) + && empty( $available_submethod['countries'][$this->getNormalized( 'country' )] ) ) { continue; // skip 'em if they're not allowed round here } @@ -3633,7 +3631,7 @@ ); foreach ( $logObj as $key => $value ) { - $logObj[$value] = $this->getData_Unstaged_Escaped( $value ); + $logObj[$value] = $this->getNormalized( $value ); unset( $logObj[$key] ); } @@ -3689,8 +3687,8 @@ * @see ClientSideValidationHelper::getClientSideValidation */ protected function getClientSideValidationRules() { - $language = $this->getData_Unstaged_Escaped( 'language' ); - $country = $this->getData_Unstaged_Escaped( 'country' ); + $language = $this->getNormalized( 'language' ); + $country = $this->getNormalized( 'country' ); // Start with the server required field validations. $requiredRules = array(); foreach ( $this->getRequiredFields() as $field ) { diff --git a/gateway_forms/Form.php b/gateway_forms/Form.php index 88032ea..cdee9e0 100644 --- a/gateway_forms/Form.php +++ b/gateway_forms/Form.php @@ -67,7 +67,7 @@ // make sure no other data that might overwrite posted data makes it into the URL - $all_form_data = $this->gateway->getData_Unstaged_Escaped(); + $all_form_data = $this->gateway->getNormalized_All(); $keys_we_need_for_form_loading = array( 'form_name', 'ffname', diff --git a/gateway_forms/Mustache.php b/gateway_forms/Mustache.php index 6629553..087ff2c 100644 --- a/gateway_forms/Mustache.php +++ b/gateway_forms/Mustache.php @@ -94,7 +94,7 @@ } protected function getData() { - $data = $this->gateway->getData_Unstaged_Escaped(); + $data = $this->gateway->getNormalized_All(); $output = $this->gatewayPage->getContext()->getOutput(); $data['script_path'] = $this->scriptPath; diff --git a/gateway_forms/MustacheErrorForm.php b/gateway_forms/MustacheErrorForm.php index 434f9b3..8d322d8 100644 --- a/gateway_forms/MustacheErrorForm.php +++ b/gateway_forms/MustacheErrorForm.php @@ -12,7 +12,7 @@ * @throw RuntimeException */ public function getForm() { - $data = $this->gateway->getData_Unstaged_Escaped(); + $data = $this->gateway->getNormalized_All(); self::$country = $data['country']; $this->addMessageParameters( $data ); diff --git a/globalcollect_gateway/GlobalCollectOrphanRectifier.php b/globalcollect_gateway/GlobalCollectOrphanRectifier.php index ac404b1..b6eff40 100644 --- a/globalcollect_gateway/GlobalCollectOrphanRectifier.php +++ b/globalcollect_gateway/GlobalCollectOrphanRectifier.php @@ -164,7 +164,7 @@ $is_rectified = false; $this->adapter->loadDataAndReInit( $normalized ); - $civiId = $this->adapter->getData_Unstaged_Escaped( 'contribution_id' ); + $civiId = $this->adapter->getNormalized( 'contribution_id' ); if ( $civiId ) { $this->logger->error( $normalized['contribution_tracking_id'] . diff --git a/globalcollect_gateway/globalcollect.adapter.php b/globalcollect_gateway/globalcollect.adapter.php index 3527c96..355cd59 100644 --- a/globalcollect_gateway/globalcollect.adapter.php +++ b/globalcollect_gateway/globalcollect.adapter.php @@ -537,7 +537,7 @@ if ( $payment_method === 'dd' and !$this->getPaymentSubmethod() ) { // Synthesize a submethod based on the country. - $country_code = strtolower( $this->getData_Unstaged_Escaped( 'country' ) ); + $country_code = strtolower( $this->getNormalized( 'country' ) ); $this->addRequestData( array( 'payment_submethod' => "dd_{$country_code}", ) ); @@ -889,7 +889,7 @@ * @return PaymentResult */ public function doRefund() { - $effortId = $this->getData_Unstaged_Escaped( 'effort_id' ); + $effortId = $this->getNormalized( 'effort_id' ); // Don't want to use standard ct_id staging $this->var_map['MERCHANTREFERENCE'] = 'merchant_reference'; @@ -1088,7 +1088,9 @@ $data['PAYMENT'] = $this->xmlChildrenToArray( $response, 'PAYMENT' ); //if we have no order ID yet (or it's somehow wrong), retrieve it and put it in the usual place. - if ( array_key_exists( 'ORDERID', $data ) && ( $data['ORDERID'] != $this->getData_Unstaged_Escaped( 'order_id' ) ) ) { + if ( array_key_exists( 'ORDERID', $data ) + && $data['ORDERID'] !== $this->getNormalized( 'order_id' ) + ) { $this->logger->info( "inside " . $data['ORDERID'] ); $this->normalizeOrderID( $data['ORDERID'] ); $this->logger->info( print_r( $this->getOrderIDMeta(), true ) ); @@ -1280,7 +1282,7 @@ return; } - if ( $this->getData_Unstaged_Escaped( 'payment_method' ) !== 'cc' ) { + if ( $this->getNormalized( 'payment_method' ) !== 'cc' ) { $this->finalizeInternalStatus( FinalStatus::FAILED ); $this->logger->error( "Payment method is not CC, OID: {$oid}" ); return; @@ -1327,7 +1329,7 @@ //set the transaction result message $responseStatus = isset( $data['STATUSID'] ) ? $data['STATUSID'] : ''; $this->transaction_response->setTxnMessage( "Response Status: " . $responseStatus ); //TODO: Translate for GC. - $this->transaction_response->setGatewayTransactionId( $this->getData_Unstaged_Escaped( 'order_id' ) ); + $this->transaction_response->setGatewayTransactionId( $this->getNormalized( 'order_id' ) ); $retErrCode = null; $retErrMsg = ''; @@ -1478,8 +1480,8 @@ ); $enable3ds = false; - $currency = $this->getData_Unstaged_Escaped( 'currency_code' ); - $country = strtoupper( $this->getData_Unstaged_Escaped( 'country' ) ); + $currency = $this->getNormalized( 'currency_code' ); + $country = strtoupper( $this->getNormalized( 'country' ) ); if ( isset( $this->staged_data['payment_product'] ) && in_array( $this->staged_data['payment_product'], $authenticationIndicatorTypes ) ) { @@ -1622,7 +1624,7 @@ */ protected function tuneForMethod() { - switch ( $this->getData_Unstaged_Escaped( 'payment_method' ) ) { + switch ( $this->getNormalized( 'payment_method' ) ) { case 'dd': case 'ew': // TODO: Review. Why is this set to country_bank_code in other cases? @@ -1645,7 +1647,7 @@ * INSERT_ORDERWITHPAYMENT if the recurring field is populated. */ protected function tuneForRecurring(){ - if ( $this->getData_Unstaged_Escaped( 'recurring' ) ) { + if ( $this->getNormalized( 'recurring' ) ) { $this->transactions['INSERT_ORDERWITHPAYMENT']['request']['REQUEST']['PARAMS']['ORDER'][] = 'ORDERTYPE'; $this->transactions['INSERT_ORDERWITHPAYMENT']['values']['ORDERTYPE'] = '4'; } @@ -1657,7 +1659,7 @@ * Right now, we only have the one, but there could be more here later. */ protected function tuneForCountry() { - switch ( $this->getData_Unstaged_Escaped( 'country' ) ){ + switch ( $this->getNormalized( 'country' ) ){ case 'AR' : $this->transactions['INSERT_ORDERWITHPAYMENT']['request']['REQUEST']['PARAMS']['ORDER'][] = 'USAGETYPE'; $this->transactions['INSERT_ORDERWITHPAYMENT']['request']['REQUEST']['PARAMS']['ORDER'][] = 'PURCHASETYPE'; @@ -1694,7 +1696,7 @@ $action = $this->findCodeAction( 'GET_ORDERSTATUS', 'STATUSID', $data['STATUSID'] ); if ( $action != FinalStatus::FAILED ){ // TODO: if method_loses_control rather than hardcode cc. - if ( $this->getData_Unstaged_Escaped( 'payment_method' ) === 'cc' ) { + if ( $this->getNormalized( 'payment_method' ) === 'cc' ) { $this->sendPendingMessage(); } } @@ -1706,8 +1708,8 @@ // Run antifraud only once per request. static $checked = array(); - $oid = $this->getData_Unstaged_Escaped('order_id'); - $method = $this->getData_Unstaged_Escaped( 'payment_method' ); + $oid = $this->getNormalized('order_id'); + $method = $this->getNormalized( 'payment_method' ); if ( $method === 'cc' && empty( $checked[$oid] ) ) { $this->runAntifraudFilters(); $checked[$oid] = true; @@ -1769,8 +1771,8 @@ if ( !is_array( $this->unstaged_data ) ) { return; } - $country = $this->getData_Unstaged_Escaped( 'country' ); - $currency = $this->getData_Unstaged_Escaped( 'currency_code' ); + $country = $this->getNormalized( 'country' ); + $currency = $this->getNormalized( 'currency_code' ); if ( $country === null || $currency === null ) { return; } diff --git a/globalcollect_gateway/orphan.adapter.php b/globalcollect_gateway/orphan.adapter.php index aaf48c2..a231eec 100644 --- a/globalcollect_gateway/orphan.adapter.php +++ b/globalcollect_gateway/orphan.adapter.php @@ -104,7 +104,7 @@ } public function getContributionTracking() { - if ( $this->getData_Unstaged_Escaped( 'utm_source' ) ) { + if ( $this->getNormalized( 'utm_source' ) ) { // We already have the info. return array(); } @@ -119,7 +119,7 @@ throw new RuntimeException( 'Might as well fall over.' ); } - $ctid = $this->getData_Unstaged_Escaped( 'contribution_tracking_id' ); + $ctid = $this->getNormalized( 'contribution_tracking_id' ); $data = array( ); @@ -166,10 +166,10 @@ $transaction = parent::getStompTransaction(); // Overwrite the time field, if historical date is available. - if ( !is_null( $this->getData_Unstaged_Escaped( 'date' ) ) ) { - $transaction['date'] = $this->getData_Unstaged_Escaped( 'date' ); - } elseif ( !is_null( $this->getData_Unstaged_Escaped( 'ts' ) ) ) { - $transaction['date'] = strtotime( $this->getData_Unstaged_Escaped( 'ts' ) ); //I hate that this works. FIXME: wat. + if ( !is_null( $this->getNormalized( 'date' ) ) ) { + $transaction['date'] = $this->getNormalized( 'date' ); + } elseif ( !is_null( $this->getNormalized( 'ts' ) ) ) { + $transaction['date'] = strtotime( $this->getNormalized( 'ts' ) ); //I hate that this works. FIXME: wat. } return $transaction; diff --git a/paypal_gateway/express_checkout/paypal_express.adapter.php b/paypal_gateway/express_checkout/paypal_express.adapter.php index b12472c..9870e67 100644 --- a/paypal_gateway/express_checkout/paypal_express.adapter.php +++ b/paypal_gateway/express_checkout/paypal_express.adapter.php @@ -80,7 +80,7 @@ } function setGatewayDefaults( $options = array ( ) ) { - if ( $this->getData_Unstaged_Escaped( 'payment_method' ) == null ) { + if ( $this->getNormalized( 'payment_method' ) == null ) { $this->addRequestData( array( 'payment_method' => 'paypal' ) ); @@ -366,7 +366,7 @@ } public function doPayment() { - if ( $this->getData_Unstaged_Escaped( 'recurring' ) ) { + if ( $this->getNormalized( 'recurring' ) ) { // Build the billing agreement and get a token to redirect. $resultData = $this->do_transaction( 'SetExpressCheckout_recurring' ); } else { @@ -486,7 +486,7 @@ return; } - if ( $this->getData_Unstaged_Escaped( 'recurring' ) ) { + if ( $this->getNormalized( 'recurring' ) ) { // Set up recurring billing agreement. $this->addRequestData( array( // Start in a month; we're making today's payment as an one-time charge. diff --git a/paypal_gateway/legacy/paypal_legacy.adapter.php b/paypal_gateway/legacy/paypal_legacy.adapter.php index 6649846..6815063 100644 --- a/paypal_gateway/legacy/paypal_legacy.adapter.php +++ b/paypal_gateway/legacy/paypal_legacy.adapter.php @@ -32,7 +32,7 @@ function __construct( $options = array() ) { parent::__construct( $options ); - if ( $this->getData_Unstaged_Escaped( 'payment_method' ) == null ) { + if ( $this->getNormalized( 'payment_method' ) == null ) { $this->addRequestData( array( 'payment_method' => 'paypal' ) ); @@ -147,14 +147,14 @@ } public function doPayment() { - $ctid = $this->getData_Unstaged_Escaped( 'contribution_tracking_id' ); + $ctid = $this->getNormalized( 'contribution_tracking_id' ); $this->normalizeOrderID( $ctid ); $this->addRequestData( array ( 'order_id' => $ctid ) ); - if ( $this->getData_Unstaged_Escaped( 'recurring' ) ) { + if ( $this->getNormalized( 'recurring' ) ) { $resultData = $this->do_transaction( 'DonateRecurring' ); } else { - $country = $this->getData_Unstaged_Escaped( 'country' ); + $country = $this->getNormalized( 'country' ); if ( in_array( $country, $this->getGlobal( 'XclickCountries' ) ) ) { $resultData = $this->do_transaction( 'DonateXclick' ); } else { diff --git a/tests/phpunit/Adapter/Adyen/AdyenTest.php b/tests/phpunit/Adapter/Adyen/AdyenTest.php index bc70637..39f0134 100644 --- a/tests/phpunit/Adapter/Adyen/AdyenTest.php +++ b/tests/phpunit/Adapter/Adyen/AdyenTest.php @@ -89,7 +89,7 @@ } $this->assertEquals( $expected, $ret, 'Adyen "donate" transaction not constructing the expected redirect URL' ); - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), "Adyen order_id is null, and we need one for 'merchantReference'" ); + $this->assertNotNull( $gateway->getNormalized( 'order_id' ), "Adyen order_id is null, and we need one for 'merchantReference'" ); } function testRiskScoreAddedToQueueMessage() { @@ -149,6 +149,6 @@ } $this->assertEquals( $expected, $ret, 'Adyen "donate" transaction not constructing the expected redirect URL' ); - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), "Adyen order_id is null, and we need one for 'merchantReference'" ); + $this->assertNotNull( $gateway->getNormalized( 'order_id' ), "Adyen order_id is null, and we need one for 'merchantReference'" ); } } diff --git a/tests/phpunit/Adapter/Amazon/AmazonTest.php b/tests/phpunit/Adapter/Amazon/AmazonTest.php index b7c2ef9..08d2b7d 100644 --- a/tests/phpunit/Adapter/Amazon/AmazonTest.php +++ b/tests/phpunit/Adapter/Amazon/AmazonTest.php @@ -142,12 +142,12 @@ $result = $gateway->doPayment(); // FIXME: PaymentResult->isFailed returns null for false $this->assertTrue( !( $result->isFailed() ), 'Result should not be failed when responses are good' ); - $this->assertEquals( 'Testy', $gateway->getData_Unstaged_Escaped( 'fname' ), 'Did not populate first name from Amazon data' ); - $this->assertEquals( 'Test', $gateway->getData_Unstaged_Escaped( 'lname' ), 'Did not populate last name from Amazon data' ); - $this->assertEquals( 'nob...@wikimedia.org', $gateway->getData_Unstaged_Escaped( 'email' ), 'Did not populate email from Amazon data' ); + $this->assertEquals( 'Testy', $gateway->getNormalized( 'fname' ), 'Did not populate first name from Amazon data' ); + $this->assertEquals( 'Test', $gateway->getNormalized( 'lname' ), 'Did not populate last name from Amazon data' ); + $this->assertEquals( 'nob...@wikimedia.org', $gateway->getNormalized( 'email' ), 'Did not populate email from Amazon data' ); $mockClient = TestingAmazonAdapter::$mockClient; $setOrderReferenceDetailsArgs = $mockClient->calls['setOrderReferenceDetails'][0]; - $oid = $gateway->getData_Unstaged_Escaped( 'order_id' ); + $oid = $gateway->getNormalized( 'order_id' ); $this->assertEquals( $oid, $setOrderReferenceDetailsArgs['seller_order_id'], 'Did not set order id on order reference' ); $this->assertEquals( $init['amount'], $setOrderReferenceDetailsArgs['amount'], 'Did not set amount on order reference' ); $this->assertEquals( $init['currency_code'], $setOrderReferenceDetailsArgs['currency_code'], 'Did not set currency code on order reference' ); @@ -265,12 +265,12 @@ $result = $gateway->doPayment(); // FIXME: PaymentResult->isFailed returns null for false $this->assertTrue( !( $result->isFailed() ), 'Result should not be failed when responses are good' ); - $this->assertEquals( 'Testy', $gateway->getData_Unstaged_Escaped( 'fname' ), 'Did not populate first name from Amazon data' ); - $this->assertEquals( 'Test', $gateway->getData_Unstaged_Escaped( 'lname' ), 'Did not populate last name from Amazon data' ); - $this->assertEquals( 'nob...@wikimedia.org', $gateway->getData_Unstaged_Escaped( 'email' ), 'Did not populate email from Amazon data' ); + $this->assertEquals( 'Testy', $gateway->getNormalized( 'fname' ), 'Did not populate first name from Amazon data' ); + $this->assertEquals( 'Test', $gateway->getNormalized( 'lname' ), 'Did not populate last name from Amazon data' ); + $this->assertEquals( 'nob...@wikimedia.org', $gateway->getNormalized( 'email' ), 'Did not populate email from Amazon data' ); $mockClient = TestingAmazonAdapter::$mockClient; $setBillingAgreementDetailsArgs = $mockClient->calls['setBillingAgreementDetails'][0]; - $oid = $gateway->getData_Unstaged_Escaped( 'order_id' ); + $oid = $gateway->getNormalized( 'order_id' ); $this->assertEquals( $oid, $setBillingAgreementDetailsArgs['seller_billing_agreement_id'], 'Did not set order id on billing agreement' ); $authorizeOnBillingAgreementDetailsArgs = $mockClient->calls['authorizeOnBillingAgreement'][0]; $this->assertEquals( $init['amount'], $authorizeOnBillingAgreementDetailsArgs['authorization_amount'], 'Did not authorize correct amount' ); diff --git a/tests/phpunit/Adapter/AstroPay/AstroPayTest.php b/tests/phpunit/Adapter/AstroPay/AstroPayTest.php index 90a7dbc..30b1c0b 100644 --- a/tests/phpunit/Adapter/AstroPay/AstroPayTest.php +++ b/tests/phpunit/Adapter/AstroPay/AstroPayTest.php @@ -379,7 +379,7 @@ $this->setUpRequest( $init, $session ); $gateway = new TestingAstroPayAdapter(); - $amount = $gateway->getData_Unstaged_Escaped( 'amount' ); + $amount = $gateway->getNormalized( 'amount' ); $this->assertEquals( '22.55', $amount ); $requestValues = array( @@ -394,7 +394,7 @@ ); $gateway->processDonorReturn( $requestValues ); - $amount = $gateway->getData_Unstaged_Escaped( 'amount' ); + $amount = $gateway->getNormalized( 'amount' ); $this->assertEquals( '100.00', $amount, 'Not recording correct amount' ); } diff --git a/tests/phpunit/Adapter/GatewayAdapterTest.php b/tests/phpunit/Adapter/GatewayAdapterTest.php index ec58ebc..4ff03cb 100644 --- a/tests/phpunit/Adapter/GatewayAdapterTest.php +++ b/tests/phpunit/Adapter/GatewayAdapterTest.php @@ -149,9 +149,9 @@ $adyen_gateway->batch_mode = true; $session = $secondRequest->getSessionArray(); - $ctId = $adyen_gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ); + $ctId = $adyen_gateway->getNormalized( 'contribution_tracking_id' ); $expected_order_id = "$ctId.{$session['sequence']}"; - $this->assertEquals( $expected_order_id, $adyen_gateway->getData_Unstaged_Escaped( 'order_id' ), + $this->assertEquals( $expected_order_id, $adyen_gateway->getNormalized( 'order_id' ), 'Order ID was not regenerated on gateway switch!' ); } @@ -167,7 +167,7 @@ $donorData = $firstRequest->getSessionData( 'Donor' ); $this->assertEquals( '', $donorData['recurring'], 'Test setup failed.' ); - $oneTimeOrderId = $gateway->getData_Unstaged_Escaped( 'order_id' ); + $oneTimeOrderId = $gateway->getNormalized( 'order_id' ); // Then they go back and decide they want to make a recurring donation @@ -179,7 +179,7 @@ $donorData = $secondRequest->getSessionData( 'Donor' ); $this->assertEquals( '1', $donorData['recurring'], 'Test setup failed.' ); - $recurOrderId = $gateway->getData_Unstaged_Escaped( 'order_id' ); + $recurOrderId = $gateway->getNormalized( 'order_id' ); $this->assertNotEquals( $oneTimeOrderId, $recurOrderId, 'Order ID was not regenerated on recurring switch!' ); @@ -206,8 +206,8 @@ $secondRequest = $this->setUpRequest( $init, $firstRequest->getSessionArray() ); $gateway = new TestingAstroPayAdapter(); - $newMethod = $gateway->getData_Unstaged_Escaped( 'payment_method' ); - $newSubmethod = $gateway->getData_Unstaged_Escaped( 'payment_submethod' ); + $newMethod = $gateway->getNormalized( 'payment_method' ); + $newSubmethod = $gateway->getNormalized( 'payment_submethod' ); $this->assertEquals( 'cc', $newMethod, 'Test setup failed' ); $this->assertEquals( '', $newSubmethod, 'Submethod was not blanked on method switch' ); @@ -290,7 +290,7 @@ $data['user_ip'] = '8.8.8.8'; $gateway = $this->getFreshGatewayObject( $data ); - $this->assertEquals( '127.0.0.1', $gateway->getData_Unstaged_Escaped( 'user_ip' ) ); + $this->assertEquals( '127.0.0.1', $gateway->getNormalized( 'user_ip' ) ); } public function testCanOverrideIpInBatchMode() { @@ -299,7 +299,7 @@ $data['user_ip'] = '8.8.8.8'; $gateway = $this->getFreshGatewayObject( $data, array( 'batch_mode' => true ) ); - $this->assertEquals( '8.8.8.8', $gateway->getData_Unstaged_Escaped( 'user_ip' ) ); + $this->assertEquals( '8.8.8.8', $gateway->getNormalized( 'user_ip' ) ); } function testGetScoreName() { diff --git a/tests/phpunit/Adapter/GlobalCollect/BankTransferTest.php b/tests/phpunit/Adapter/GlobalCollect/BankTransferTest.php index c2ee03d..51ee8aa 100644 --- a/tests/phpunit/Adapter/GlobalCollect/BankTransferTest.php +++ b/tests/phpunit/Adapter/GlobalCollect/BankTransferTest.php @@ -40,7 +40,6 @@ * @covers GatewayAdapter::__construct * @covers GatewayAdapter::setCurrentTransaction * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped */ public function testBuildRequestXml() { diff --git a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php index 2d1ce00..cf605fb 100644 --- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php +++ b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php @@ -77,18 +77,18 @@ //no data on construct, generate Order IDs $gateway = $this->getFreshGatewayObject( null, array ( 'order_id_meta' => array ( 'generate' => TRUE ) ) ); $this->assertTrue( $gateway->getOrderIDMeta( 'generate' ), 'The order_id meta generate setting override is not working properly. Order_id generation may be broken.' ); - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed asserting that an absent order id is not left as null, when generating our own' ); + $this->assertNotNull( $gateway->getNormalized( 'order_id' ), 'Failed asserting that an absent order id is not left as null, when generating our own' ); $data = array_merge( $this->getDonorTestData(), $this->dummy_utm_data ); $data['order_id'] = '55555'; //now, add data and check that we didn't kill the oid. Still generating. $gateway->loadDataAndReInit( $data ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '55555', 'loadDataAndReInit failed to stick OrderID' ); + $this->assertEquals( $gateway->getNormalized( 'order_id' ), '55555', 'loadDataAndReInit failed to stick OrderID' ); $data['order_id'] = '444444'; $gateway->loadDataAndReInit( $data ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '444444', 'loadDataAndReInit failed to stick OrderID' ); + $this->assertEquals( $gateway->getNormalized( 'order_id' ), '444444', 'loadDataAndReInit failed to stick OrderID' ); $this->verifyNoLogErrors(); } @@ -98,18 +98,18 @@ //no data on construct, do not generate Order IDs $gateway = $this->getFreshGatewayObject( null, array ( 'order_id_meta' => array ( 'generate' => FALSE ) ) ); $this->assertFalse( $gateway->getOrderIDMeta( 'generate' ), 'The order_id meta generate setting override is not working properly. Deferred order_id generation may be broken.' ); - $this->assertEmpty( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed asserting that an absent order id is left as null, when not generating our own' ); + $this->assertEmpty( $gateway->getNormalized( 'order_id' ), 'Failed asserting that an absent order id is left as null, when not generating our own' ); $data = array_merge( $this->getDonorTestData(), $this->dummy_utm_data ); $data['order_id'] = '66666'; //now, add data and check that we didn't kill the oid. Still not generating $gateway->loadDataAndReInit( $data ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '66666', 'loadDataAndReInit failed to stick OrderID' ); + $this->assertEquals( $gateway->getNormalized( 'order_id' ), '66666', 'loadDataAndReInit failed to stick OrderID' ); $data['order_id'] = '777777'; $gateway->loadDataAndReInit( $data ); - $this->assertEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), '777777', 'loadDataAndReInit failed to stick OrderID on second batch item' ); + $this->assertEquals( $gateway->getNormalized( 'order_id' ), '777777', 'loadDataAndReInit failed to stick OrderID on second batch item' ); $this->verifyNoLogErrors(); } diff --git a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php index 4c46ab2..713d24c 100644 --- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php +++ b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php @@ -56,6 +56,9 @@ * Non-exhaustive integration tests to verify that order_id * normalization works as expected with different settings and * conditions in theGlobalCollect adapter + * + * TODO: Data provider + * * @covers GatewayAdapter::normalizeOrderID */ public function testNormalizeOrderID() { @@ -66,38 +69,38 @@ //no order_id from anywhere, explicit no generate $gateway = $this->getFreshGatewayObject( $externalData, array ( 'order_id_meta' => array ( 'generate' => FALSE ) ) ); $this->assertFalse( $gateway->getOrderIDMeta( 'generate' ), 'The order_id meta generate setting override is not working properly. Deferred order_id generation may be broken.' ); - $this->assertNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed asserting that an absent order id is left as null, when not generating our own' ); + $this->assertNull( $gateway->getNormalized( 'order_id' ), 'Failed asserting that an absent order id is left as null, when not generating our own' ); //no order_id from anywhere, explicit generate $gateway = $this->getFreshGatewayObject( $externalData, array ( 'order_id_meta' => array ( 'generate' => TRUE ) ) ); $this->assertTrue( $gateway->getOrderIDMeta( 'generate' ), 'The order_id meta generate setting override is not working properly. Self order_id generation may be broken.' ); - $this->assertInternalType( 'numeric', $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Generated order_id is not numeric, which it should be for GlobalCollect' ); + $this->assertInternalType( 'numeric', $gateway->getNormalized( 'order_id' ), 'Generated order_id is not numeric, which it should be for GlobalCollect' ); // conflicting order_id in request and session, default GC generation $request['order_id'] = '55555'; $session['Donor']['order_id'] = '44444'; $this->setUpRequest( $request, $session ); $gateway = new TestingGlobalCollectAdapter(); - $this->assertEquals( '55555', $gateway->getData_Unstaged_Escaped( 'order_id' ), 'GlobalCollect gateway is preferring session data over the request. Session should be secondary.' ); + $this->assertEquals( '55555', $gateway->getNormalized( 'order_id' ), 'GlobalCollect gateway is preferring session data over the request. Session should be secondary.' ); // conflicting order_id in request and session, garbage data in request, default GC generation $request['order_id'] = 'nonsense!'; $this->setUpRequest( $request, $session ); $gateway = new TestingGlobalCollectAdapter(); - $this->assertEquals( '44444', $gateway->getData_Unstaged_Escaped( 'order_id' ), 'GlobalCollect gateway is not ignoring nonsensical order_id candidates' ); + $this->assertEquals( '44444', $gateway->getNormalized( 'order_id' ), 'GlobalCollect gateway is not ignoring nonsensical order_id candidates' ); // order_id in session, default GC generation unset( $request['order_id'] ); $this->setUpRequest( $request, $session ); $gateway = new TestingGlobalCollectAdapter(); - $this->assertEquals( '44444', $gateway->getData_Unstaged_Escaped( 'order_id' ), 'GlobalCollect gateway is not recognizing the session order_id' ); + $this->assertEquals( '44444', $gateway->getNormalized( 'order_id' ), 'GlobalCollect gateway is not recognizing the session order_id' ); // conflicting order_id in external data, request and session, explicit GC generation, batch mode $request['order_id'] = '33333'; $externalData['order_id'] = '22222'; $this->setUpRequest( $request, $session ); $gateway = $this->getFreshGatewayObject( $externalData, array ( 'order_id_meta' => array ( 'generate' => true ), 'batch_mode' => true ) ); - $this->assertEquals( $externalData['order_id'], $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed asserting that an extrenally provided order id is being honored in batch mode' ); + $this->assertEquals( $externalData['order_id'], $gateway->getNormalized( 'order_id' ), 'Failed asserting that an extrenally provided order id is being honored in batch mode' ); //make sure that decimal numbers are rejected by GC. Should be a toss and regen $externalData['order_id'] = '2143.0'; @@ -106,7 +109,7 @@ $this->setUpRequest( $request, $session ); //conflicting order_id in external data, request and session, explicit GC generation, batch mode $gateway = $this->getFreshGatewayObject( $externalData, array ( 'order_id_meta' => array ( 'generate' => true, 'disallow_decimals' => true ), 'batch_mode' => true ) ); - $this->assertNotEquals( $externalData['order_id'], $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Failed assering that a decimal order_id was regenerated, when disallow_decimals is true' ); + $this->assertNotEquals( $externalData['order_id'], $gateway->getNormalized( 'order_id' ), 'Failed assering that a decimal order_id was regenerated, when disallow_decimals is true' ); } /** @@ -121,18 +124,18 @@ //no order_id from anywhere, explicit generate $gateway = $this->getFreshGatewayObject( $init, array ( 'order_id_meta' => array ( 'generate' => TRUE ) ) ); - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Generated order_id is null. The rest of this test is broken.' ); - $original_order_id = $gateway->getData_Unstaged_Escaped( 'order_id' ); + $this->assertNotNull( $gateway->getNormalized( 'order_id' ), 'Generated order_id is null. The rest of this test is broken.' ); + $original_order_id = $gateway->getNormalized( 'order_id' ); $gateway->normalizeOrderID(); - $this->assertEquals( $original_order_id, $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Re-normalized order_id has changed without explicit regeneration.' ); + $this->assertEquals( $original_order_id, $gateway->getNormalized( 'order_id' ), 'Re-normalized order_id has changed without explicit regeneration.' ); //this might look a bit strange, but we need to be able to generate valid order_ids without making them stick to anything. $gateway->generateOrderID(); - $this->assertEquals( $original_order_id, $gateway->getData_Unstaged_Escaped( 'order_id' ), 'function generateOrderID auto-changed the selected order ID. Not cool.' ); + $this->assertEquals( $original_order_id, $gateway->getNormalized( 'order_id' ), 'function generateOrderID auto-changed the selected order ID. Not cool.' ); $gateway->regenerateOrderID(); - $this->assertNotEquals( $original_order_id, $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Re-normalized order_id has not changed, after explicit regeneration.' ); + $this->assertNotEquals( $original_order_id, $gateway->getNormalized( 'order_id' ), 'Re-normalized order_id has not changed, after explicit regeneration.' ); } /** @@ -147,11 +150,11 @@ //no order_id from anywhere, explicit generate $gateway = $this->getFreshGatewayObject( $init, array ( 'order_id_meta' => array ( 'generate' => FALSE ) ) ); - $this->assertNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'Ungenerated order_id is not null. The rest of this test is broken.' ); + $this->assertNull( $gateway->getNormalized( 'order_id' ), 'Ungenerated order_id is not null. The rest of this test is broken.' ); $gateway->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); - $this->assertNotNull( $gateway->getData_Unstaged_Escaped( 'order_id' ), 'No order_id was retrieved from INSERT_ORDERWITHPAYMENT' ); + $this->assertNotNull( $gateway->getNormalized( 'order_id' ), 'No order_id was retrieved from INSERT_ORDERWITHPAYMENT' ); } /** @@ -242,7 +245,7 @@ $gateway->do_transaction( 'Confirm_CreditCard' ); - $this->assertEquals( 'N', $gateway->getData_Unstaged_Escaped('cvv_result'), 'CVV Result not taken from XML response' ); + $this->assertEquals( 'N', $gateway->getNormalized('cvv_result'), 'CVV Result not taken from XML response' ); } /** @@ -261,15 +264,15 @@ $gateway = $this->getFreshGatewayObject( $init ); - $amount = $gateway->getData_Unstaged_Escaped( 'amount' ); - $currency = $gateway->getData_Unstaged_Escaped( 'currency_code' ); + $amount = $gateway->getNormalized( 'amount' ); + $currency = $gateway->getNormalized( 'currency_code' ); $this->assertEquals( '12.50', $amount ); $this->assertEquals( 'USD', $currency ); $gateway->do_transaction( 'Confirm_CreditCard' ); - $amount = $gateway->getData_Unstaged_Escaped( 'amount' ); - $currency = $gateway->getData_Unstaged_Escaped( 'currency_code' ); + $amount = $gateway->getNormalized( 'amount' ); + $currency = $gateway->getNormalized( 'currency_code' ); $this->assertEquals( '23.45', $amount, 'Not recording correct amount' ); $this->assertEquals( 'EUR', $currency, 'Not recording correct currency' ); } @@ -563,9 +566,9 @@ unset( $init['order_id'] ); $gateway = $this->getFreshGatewayObject( $init ); - $orig_id = $gateway->getData_Unstaged_Escaped( 'order_id' ); + $orig_id = $gateway->getNormalized( 'order_id' ); $gateway->setDummyGatewayResponseCode( function ( $gateway ) use ( $orig_id ) { - if ( $gateway->getData_Unstaged_Escaped( 'order_id' ) === $orig_id ) { + if ( $gateway->getNormalized( 'order_id' ) === $orig_id ) { return 'duplicate'; } else { return null; @@ -574,7 +577,7 @@ $result = $gateway->doPayment(); $this->assertEmpty( $result->isFailed(), 'PaymentResult should not be failed' ); $this->assertEmpty( $result->getErrors(), 'PaymentResult should have no errors' ); - $this->assertNotEquals( $gateway->getData_Unstaged_Escaped( 'order_id' ), $orig_id, + $this->assertNotEquals( $gateway->getNormalized( 'order_id' ), $orig_id, 'Order ID regenerated in DonationData.' ); $this->assertNotEquals( $gateway->session_getData( 'order_id' ), $orig_id, 'Order ID regenerated in session.' ); diff --git a/tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php b/tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php index 335467c..87cf91e 100644 --- a/tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php +++ b/tests/phpunit/Adapter/GlobalCollect/RealTimeBankTransferIdealTest.php @@ -101,7 +101,6 @@ * @covers GatewayAdapter::__construct * @covers GatewayAdapter::setCurrentTransaction * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped */ public function testBuildRequestXmlWithIssuerId21() { @@ -129,7 +128,6 @@ * @covers GatewayAdapter::__construct * @covers GatewayAdapter::setCurrentTransaction * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped */ public function testBuildRequestXmlWithIssuerId31() { @@ -157,7 +155,6 @@ * @covers GatewayAdapter::__construct * @covers GatewayAdapter::setCurrentTransaction * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped */ public function testBuildRequestXmlWithIssuerId91() { @@ -185,7 +182,6 @@ * @covers GatewayAdapter::__construct * @covers GatewayAdapter::setCurrentTransaction * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped */ public function testBuildRequestXmlWithIssuerId161() { @@ -213,7 +209,6 @@ * @covers GatewayAdapter::__construct * @covers GatewayAdapter::setCurrentTransaction * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped */ public function testBuildRequestXmlWithIssuerId511() { @@ -241,7 +236,6 @@ * @covers GatewayAdapter::__construct * @covers GatewayAdapter::setCurrentTransaction * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped */ public function testBuildRequestXmlWithIssuerId721() { @@ -269,7 +263,6 @@ * @covers GatewayAdapter::__construct * @covers GatewayAdapter::setCurrentTransaction * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped */ public function testBuildRequestXmlWithIssuerId751() { @@ -297,7 +290,6 @@ * @covers GatewayAdapter::__construct * @covers GatewayAdapter::setCurrentTransaction * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped */ public function testBuildRequestXmlWithIssuerId761() { @@ -325,7 +317,6 @@ * @covers GatewayAdapter::__construct * @covers GatewayAdapter::setCurrentTransaction * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped */ public function testBuildRequestXmlWithIssuerId771() { diff --git a/tests/phpunit/Adapter/GlobalCollect/YandexTest.php b/tests/phpunit/Adapter/GlobalCollect/YandexTest.php index 2998ff4..c181a2f 100644 --- a/tests/phpunit/Adapter/GlobalCollect/YandexTest.php +++ b/tests/phpunit/Adapter/GlobalCollect/YandexTest.php @@ -38,7 +38,6 @@ * @covers GatewayAdapter::__construct * @covers GatewayAdapter::setCurrentTransaction * @covers GatewayAdapter::buildRequestXML - * @covers GatewayAdapter::getData_Unstaged_Escaped */ public function testBuildRequestXml() { diff --git a/tests/phpunit/Adapter/PayPal/PayPalLegacyTest.php b/tests/phpunit/Adapter/PayPal/PayPalLegacyTest.php index ce97f52..1609fa4 100644 --- a/tests/phpunit/Adapter/PayPal/PayPalLegacyTest.php +++ b/tests/phpunit/Adapter/PayPal/PayPalLegacyTest.php @@ -79,7 +79,7 @@ 'item_name' => 'Donation to the Wikimedia Foundation', 'item_number' => 'DONATE', 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), + 'custom' => $gateway->getNormalized( 'contribution_tracking_id' ), 'lc' => $init['country'], //this works because it's a US donor... 'cancel_return' => 'https://example.com/tryAgain.php/en', 'return' => 'https://example.org/wiki/Thank_You/en?country=US', @@ -87,8 +87,8 @@ $this->assertEquals( $expected, $res, 'Paypal "Donate" transaction not constructing the expected redirect URL' ); $this->assertEquals( - $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - $gateway->getData_Unstaged_Escaped( 'order_id' ), + $gateway->getNormalized( 'contribution_tracking_id' ), + $gateway->getNormalized( 'order_id' ), "Paypal order_id should equal ct_id" ); } @@ -113,7 +113,7 @@ 'item_name' => 'Donation to the Wikimedia Foundation', 'item_number' => 'DONATE', 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), + 'custom' => $gateway->getNormalized( 'contribution_tracking_id' ), 'lc' => $init['country'], //this works because it's a US donor... 't3' => 'M', //hard-coded in transaction definition 'p3' => '1', //hard-coded in transaction definition @@ -150,7 +150,7 @@ 'item_name' => 'Donation to the Wikimedia Foundation', 'item_number' => 'DONATE', 'no_note' => '1', //hard-coded in transaction definition - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), + 'custom' => $gateway->getNormalized( 'contribution_tracking_id' ), // 'lc' => $init['country'], //Apparently, this was removed from our implementation, because 'CN' is weird. 'cancel_return' => 'https://example.com/tryAgain.php/en', 'return' => 'https://example.org/wiki/Thank_You/en?country=US', @@ -245,7 +245,7 @@ 'item_name' => $donateText, 'item_number' => 'DONATE', 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), + 'custom' => $gateway->getNormalized( 'contribution_tracking_id' ), 'lc' => 'BE', 'cancel_return' => "https://example.com/tryAgain.php/$language", 'return' => "https://example.org/wiki/Thank_You/$language?country=BE", @@ -253,8 +253,8 @@ $this->assertEquals( $expected, $res, 'Paypal "Donate" transaction not constructing the expected redirect URL' ); $this->assertEquals( - $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - $gateway->getData_Unstaged_Escaped( 'order_id' ), + $gateway->getNormalized( 'contribution_tracking_id' ), + $gateway->getNormalized( 'order_id' ), "Paypal order_id should equal ct_id" ); } @@ -283,7 +283,7 @@ 'item_name' => $donateText, 'item_number' => 'DONATE', 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), + 'custom' => $gateway->getNormalized( 'contribution_tracking_id' ), 'lc' => 'CA', 'cancel_return' => "https://example.com/tryAgain.php/$language", 'return' => "https://example.org/wiki/Thank_You/$language?country=CA", @@ -291,8 +291,8 @@ $this->assertEquals( $expected, $res, 'Paypal "Donate" transaction not constructing the expected redirect URL' ); $this->assertEquals( - $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - $gateway->getData_Unstaged_Escaped( 'order_id' ), + $gateway->getNormalized( 'contribution_tracking_id' ), + $gateway->getNormalized( 'order_id' ), "Paypal order_id should equal ct_id" ); } @@ -317,7 +317,7 @@ 'item_name' => $donateText, 'item_number' => 'DONATE', 'no_note' => '0', - 'custom' => $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), + 'custom' => $gateway->getNormalized( 'contribution_tracking_id' ), 'lc' => 'IT', 'cancel_return' => 'https://example.com/tryAgain.php/it', 'return' => 'https://example.org/wiki/Thank_You/it?country=IT', @@ -325,8 +325,8 @@ $this->assertEquals( $expected, $res, 'Paypal "Donate" transaction not constructing the expected redirect URL' ); $this->assertEquals( - $gateway->getData_Unstaged_Escaped( 'contribution_tracking_id' ), - $gateway->getData_Unstaged_Escaped( 'order_id' ), + $gateway->getNormalized( 'contribution_tracking_id' ), + $gateway->getNormalized( 'order_id' ), "Paypal order_id should equal ct_id" ); } diff --git a/tests/phpunit/DonationInterfaceTestCase.php b/tests/phpunit/DonationInterfaceTestCase.php index 8fe7ddb..fbac151 100644 --- a/tests/phpunit/DonationInterfaceTestCase.php +++ b/tests/phpunit/DonationInterfaceTestCase.php @@ -342,7 +342,7 @@ global $wgDonationInterfaceThankYouPage; $request = RequestContext::getMain()->getRequest(); - $orderId = $this->gatewayAdapter->getData_Unstaged_Escaped( 'order_id' ); + $orderId = $this->gatewayAdapter->getNormalized( 'order_id' ); $exposed = TestingAccessWrapper::newFromObject( $this->gatewayAdapter ); $merchantref = $exposed->getData_Staged( 'contribution_tracking_id' ); //@TODO: WHY IN THE NAME OF ZARQUON are we building XML in a STRING format here?!?!?!!!1one1!?. Great galloping galumphing giraffes. diff --git a/tests/phpunit/GatewayPageTest.php b/tests/phpunit/GatewayPageTest.php index 49d03a3..d326a69 100644 --- a/tests/phpunit/GatewayPageTest.php +++ b/tests/phpunit/GatewayPageTest.php @@ -82,8 +82,8 @@ $errors = $this->adapter->getErrors(); $msg = $this->page->msg( 'donate_interface-fallback-currency-notice', 'USD' )->text(); $this->assertEquals( $msg, $errors['general'] ); - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); + $this->assertEquals( 100, $this->adapter->getNormalized( 'amount' ) ); + $this->assertEquals( 'USD', $this->adapter->getNormalized( 'currency_code' ) ); } public function testCurrencyFallbackIntermediateConversion() { @@ -96,8 +96,8 @@ $errors = $this->adapter->getErrors(); $msg = $this->page->msg( 'donate_interface-fallback-currency-notice', 'OMR' )->text(); $this->assertEquals( $msg, $errors['general'] ); - $this->assertEquals( 38, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'OMR', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); + $this->assertEquals( 38, $this->adapter->getNormalized( 'amount' ) ); + $this->assertEquals( 'OMR', $this->adapter->getNormalized( 'currency_code' ) ); } public function testCurrencyFallbackWithoutNotification() { @@ -108,8 +108,8 @@ $errors = $this->adapter->getErrors(); $this->assertTrue( empty( $errors['general'] ) ); - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); + $this->assertEquals( 100, $this->adapter->getNormalized( 'amount' ) ); + $this->assertEquals( 'USD', $this->adapter->getNormalized( 'currency_code' ) ); } public function testCurrencyFallbackAlwaysNotifiesIfOtherErrors() { @@ -119,8 +119,8 @@ $errors = $this->adapter->getErrors(); $msg = $this->page->msg( 'donate_interface-fallback-currency-notice', 'USD' )->text(); $this->assertEquals( $msg, $errors['general'] ); - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); + $this->assertEquals( 100, $this->adapter->getNormalized( 'amount' ) ); + $this->assertEquals( 'USD', $this->adapter->getNormalized( 'currency_code' ) ); } public function testNoFallbackForSupportedCurrency() { @@ -129,8 +129,8 @@ $errors = $this->adapter->getErrors(); $this->assertTrue( empty( $errors['general'] ) ); - $this->assertEquals( 200, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'BBD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); + $this->assertEquals( 200, $this->adapter->getNormalized( 'amount' ) ); + $this->assertEquals( 'BBD', $this->adapter->getNormalized( 'currency_code' ) ); } public function testCurrencyFallbackByCountry() { @@ -145,8 +145,8 @@ ); $this->setUpAdapter( $extra ); - $this->assertEquals( 100, $this->adapter->getData_Unstaged_Escaped( 'amount' ) ); - $this->assertEquals( 'USD', $this->adapter->getData_Unstaged_Escaped( 'currency_code' ) ); + $this->assertEquals( 100, $this->adapter->getNormalized( 'amount' ) ); + $this->assertEquals( 'USD', $this->adapter->getNormalized( 'currency_code' ) ); } /** -- To view, visit https://gerrit.wikimedia.org/r/342553 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib29a85fec1c7ccf11b99c8538651cde792c75e15 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: master Gerrit-Owner: Awight <awi...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits