Adamw has uploaded a new change for review. https://gerrit.wikimedia.org/r/51808
Change subject: paypal form to make corrections before redirect ...................................................................... paypal form to make corrections before redirect Change-Id: Ide392956212db511fbbd908ff94986d3ab861544 --- M adyen_gateway/adyen.adapter.php M adyen_gateway/forms/html/adyen.html M amazon_gateway/amazon.adapter.php M donationinterface.php M gateway_common/DataValidator.php M gateway_common/gateway.adapter.php M gateway_forms/rapidhtml/RapidHtmlResources.php M globalcollect_gateway/globalcollect.adapter.php M payflowpro_gateway/payflowpro.adapter.php A paypal_gateway/forms/html/_donation-amount/ARS.html A paypal_gateway/forms/html/_donation-amount/CLP.html A paypal_gateway/forms/html/_donation-amount/EUR.html A paypal_gateway/forms/html/_donation-amount/GBP.html A paypal_gateway/forms/html/_donation-amount/MXP.html A paypal_gateway/forms/html/_donation-amount/RUB.html A paypal_gateway/forms/html/_donation-amount/USD.html A paypal_gateway/forms/html/_donation-amount/default.html A paypal_gateway/forms/html/_personal-information/default.html A paypal_gateway/forms/html/paypal.html A paypal_gateway/forms/js/paypal.js M paypal_gateway/paypal.adapter.php M paypal_gateway/paypal_gateway.body.php 22 files changed, 464 insertions(+), 29 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/08/51808/1 diff --git a/adyen_gateway/adyen.adapter.php b/adyen_gateway/adyen.adapter.php index ce3cef8..ab53d09 100644 --- a/adyen_gateway/adyen.adapter.php +++ b/adyen_gateway/adyen.adapter.php @@ -216,10 +216,209 @@ function getResponseData( $response ) { } - function getCurrencies() { + static function getCurrencies() { + // See http://www.adyen.com/platform/all-countries-all-currencies/ + // This should be the list of all global "acceptance currencies". Not + // finding that list, I've used everything for which we keep + // conversion rates. $currencies = array( - //XXX + 'ADF', // Andorran Franc + 'ADP', // Andorran Peseta + 'AED', // Utd. Arab Emir. Dirham + 'AFA', // Afghanistan Afghani + 'AFN', // Afghanistan Afghani + 'ALL', // Albanian Lek + 'AMD', // Armenian Dram + 'ANG', // NL Antillian Guilder + 'AOA', // Angolan Kwanza + 'AON', // Angolan Old Kwanza + 'ARS', // Argentinian peso + 'ATS', // Austrian Schilling + 'AUD', // Australian Dollar + 'AWG', // Aruban Florin + 'AZM', // Azerbaijan Old Manat + 'AZN', // Azerbaijan New Manat + 'BAM', // Bosnian Mark + 'BBD', // Barbadian dollar + 'BDT', // Bangladeshi Taka + 'BEF', // Belgian Franc + 'BGL', // Bulgarian Old Lev + 'BGN', // Bulgarian Lev + 'BHD', // Bahraini Dinar + 'BIF', // Burundi Franc + 'BMD', // Bermudian Dollar + 'BND', // Brunei Dollar + 'BOB', // Bolivian Boliviano + 'BRL', // Brazilian Real + 'BSD', // Bahamian Dollar + 'BTN', // Bhutan Ngultrum + 'BWP', // Botswana Pula + 'BYR', // Belarusian Ruble + 'BZD', // Belize Dollar + 'CAD', // Canadian Dollar + 'CDF', // Congolese Franc + 'CHF', // Swiss Franc + 'CLP', // Chilean Peso + 'CNY', // Chinese Yuan Renminbi + 'COP', // Colombian Peso + 'CRC', // Costa Rican Colon + 'CUC', // Cuban Convertible Peso + 'CUP', // Cuban Peso + 'CVE', // Cape Verde Escudo + 'CYP', // Cyprus Pound + 'CZK', // Czech Koruna + 'DEM', // German Mark + 'DJF', // Djibouti Franc + 'DKK', // Danish Krone + 'DOP', // Dominican R. Peso + 'DZD', // Algerian Dinar + 'ECS', // Ecuador Sucre + 'EEK', // Estonian Kroon + 'EGP', // Egyptian Pound + 'ESP', // Spanish Peseta + 'ETB', // Ethiopian Birr + 'EUR', // Euro + 'FIM', // Finnish Markka + 'FJD', // Fiji Dollar + 'FKP', // Falkland Islands Pound + 'FRF', // French Franc + 'GBP', // British Pound + 'GEL', // Georgian Lari + 'GHC', // Ghanaian Cedi + 'GHS', // Ghanaian New Cedi + 'GIP', // Gibraltar Pound + 'GMD', // Gambian Dalasi + 'GNF', // Guinea Franc + 'GRD', // Greek Drachma + 'GTQ', // Guatemalan Quetzal + 'GYD', // Guyanese Dollar + 'HKD', // Hong Kong Dollar + 'HNL', // Honduran Lempira + 'HRK', // Croatian Kuna + 'HTG', // Haitian Gourde + 'HUF', // Hungarian Forint + 'IDR', // Indonesian Rupiah + 'IEP', // Irish Punt + 'ILS', // Israeli New Shekel + 'INR', // Indian Rupee + 'IQD', // Iraqi Dinar + 'IRR', // Iranian Rial + 'ISK', // Iceland Krona + 'ITL', // Italian Lira + 'JMD', // Jamaican Dollar + 'JOD', // Jordanian Dinar + 'JPY', // Japanese Yen + 'KES', // Kenyan Shilling + 'KGS', // Kyrgyzstanian Som + 'KHR', // Cambodian Riel + 'KMF', // Comoros Franc + 'KPW', // North Korean Won + 'KRW', // South Korean won + 'KWD', // Kuwaiti Dinar + 'KYD', // Cayman Islands Dollar + 'KZT', // Kazakhstani Tenge + 'LAK', // Lao Kip + 'LBP', // Lebanese Pound + 'LKR', // Sri Lankan Rupee + 'LRD', // Liberian Dollar + 'LSL', // Lesotho Loti + 'LTL', // Lithuanian Litas + 'LUF', // Luxembourg Franc + 'LVL', // Latvian Lats + 'LYD', // Libyan Dinar + 'MAD', // Moroccan Dirham + 'MDL', // Moldovan Leu + 'MGA', // Malagasy Ariary + 'MGF', // Malagasy Franc + 'MKD', // Macedonian Denar + 'MMK', // Myanmar Kyat + 'MNT', // Mongolian Tugrik + 'MOP', // Macau Pataca + 'MRO', // Mauritanian Ouguiya + 'MTL', // Maltese Lira + 'MUR', // Mauritius Rupee + 'MVR', // Maldive Rufiyaa + 'MWK', // Malawi Kwacha + 'MXN', // Mexican Peso + 'MYR', // Malaysian Ringgit + 'MZM', // Mozambique Metical + 'MZN', // Mozambique New Metical + 'NAD', // Namibia Dollar + 'NGN', // Nigerian Naira + 'NIO', // Nicaraguan Cordoba Oro + 'NLG', // Dutch Guilder + 'NOK', // Norwegian Kroner + 'NPR', // Nepalese Rupee + 'NZD', // New Zealand Dollar + 'OMR', // Omani Rial + 'PAB', // Panamanian Balboa + 'PEN', // Peruvian Nuevo Sol + 'PGK', // Papua New Guinea Kina + 'PHP', // Philippine Peso + 'PKR', // Pakistani Rupee + 'PLN', // Polish Złoty + 'PTE', // Portuguese Escudo + 'PYG', // Paraguay Guarani + 'QAR', // Qatari Rial + 'ROL', // Romanian Lei + 'RON', // Romanian New Lei + 'RSD', // Serbian Dinar + 'RUB', // Russian Rouble + 'RWF', // Rwandan Franc + 'SAR', // Saudi Riyal + 'SBD', // Solomon Islands Dollar + 'SCR', // Seychelles Rupee + 'SDD', // Sudanese Dinar + 'SDG', // Sudanese Pound + 'SDP', // Sudanese Old Pound + 'SEK', // Swedish Krona + 'SGD', // Singapore Dollar + 'SHP', // St. Helena Pound + 'SIT', // Slovenian Tolar + 'SKK', // Slovak Koruna + 'SLL', // Sierra Leone Leone + 'SOS', // Somali Shilling + 'SRD', // Suriname Dollar + 'SRG', // Suriname Guilder + 'STD', // Sao Tome/Principe Dobra + 'SVC', // El Salvador Colon + 'SYP', // Syrian Pound + 'SZL', // Swaziland Lilangeni + 'THB', // Thai Baht + 'TJS', // Tajikistani Somoni + 'TMM', // Turkmenistan Manat + 'TMT', // Turkmenistan New Manat + 'TND', // Tunisian Dinar + 'TOP', // Tonga Pa'anga + 'TRL', // Turkish Old Lira + 'TRY', // Turkish Lira + 'TTD', // Trinidad/Tobago Dollar + 'TWD', // New Taiwan dollar + 'TZS', // Tanzanian Shilling + 'UAH', // Ukrainian hryvnia + 'UGX', // Uganda Shilling 'USD', // U.S. dollar + 'UYU', // Uruguayan Peso + 'UZS', // Uzbekistan Som + 'VEB', // Venezuelan Bolivar + 'VEF', // Venezuelan Bolivar Fuerte + 'VND', // Vietnamese Dong + 'VUV', // Vanuatu Vatu + 'WST', // Samoan Tala + 'XAF', // Central African CFA franc + 'XAG', // Silver (oz.) + 'XAU', // Gold (oz.) + 'XCD', // East Caribbean Dollar + 'XEU', // ECU + 'XOF', // West African CFA franc + 'XPD', // Palladium (oz.) + 'XPF', // CFP Franc + 'XPT', // Platinum (oz.) + 'YER', // Yemeni Rial + 'YUN', // Yugoslav Dinar + 'ZAR', // South African Rand + 'ZMK', // Zambian Kwacha + 'ZWD', // Zimbabwe Dollar ); return $currencies; } diff --git a/adyen_gateway/forms/html/adyen.html b/adyen_gateway/forms/html/adyen.html index f0898f3..5be3a02 100644 --- a/adyen_gateway/forms/html/adyen.html +++ b/adyen_gateway/forms/html/adyen.html @@ -70,7 +70,6 @@ </tbody> </table> </div> - <input type="hidden" name="gateway" value="payflowpro" id="gateway" /> <input type="hidden" name="returnto" value="Thank_You/en" /> <input type="hidden" value="0" name="PaypalRedirect" id="PaypalRedirect"> <input type="hidden" value="@amount" name="amount"> diff --git a/amazon_gateway/amazon.adapter.php b/amazon_gateway/amazon.adapter.php index d7d5d9b..f4b8d74 100644 --- a/amazon_gateway/amazon.adapter.php +++ b/amazon_gateway/amazon.adapter.php @@ -225,7 +225,8 @@ } } - function getCurrencies() { + static function getCurrencies() { + // See https://payments.amazon.com/sdui/sdui/about?nodeId=73479#feat_countries return array( 'USD', ); diff --git a/donationinterface.php b/donationinterface.php index b0e6b34..4aa5c21 100644 --- a/donationinterface.php +++ b/donationinterface.php @@ -434,6 +434,8 @@ $wgPaypalGatewayPriceFloor = 1.00; + $wgPaypalGatewayHtmlFormDir = $donationinterface_dir . 'paypal_gateway/forms/html'; + # $wgPaypalGatewayAccountInfo['example'] = array( # 'AccountEmail' => "", # ); @@ -1006,6 +1008,16 @@ $wgAjaxExportList[] = "fnPayflowProofofWork"; } +if ( $optionalParts['Adyen'] === true ){ + $wgExtensionMessagesFiles['AdyenGateway'] = $donationinterface_dir . 'adyen_gateway/adyen_gateway.i18n.php'; + $wgExtensionMessagesFiles['AdyenGatewayAlias'] = $donationinterface_dir . 'adyen_gateway/adyen_gateway.alias.php'; +} + +if ( $optionalParts['Paypal'] === true ){ + $wgExtensionMessagesFiles['PaypalGateway'] = $donationinterface_dir . 'paypal_gateway/paypal_gateway.i18n.php'; + $wgExtensionMessagesFiles['PaypalGatewayAlias'] = $donationinterface_dir . 'paypal_gateway/paypal_gateway.alias.php'; +} + /** * FUNCTIONS */ diff --git a/gateway_common/DataValidator.php b/gateway_common/DataValidator.php index b04d0c9..698af97 100644 --- a/gateway_common/DataValidator.php +++ b/gateway_common/DataValidator.php @@ -103,6 +103,7 @@ $error_token = 'emailAdd'; break; case 'amount' : + case 'currency_code' : case 'card_num': case 'card_type': case 'cvv': @@ -358,9 +359,12 @@ $instructions['non_empty']['amount'] = 'validate_not_empty'; $instructions['valid_type']['amount'] = 'validate_numeric'; $instructions['non_empty']['currency_code'] = 'validate_not_empty'; - $instructions['valid_type']['currency_code'] = self::getValidationFunction( 'currency_code' ); + $instructions['valid_type']['currency_code'] = 'validate_alphanumeric'; $instructions['non_empty']['gateway'] = 'validate_not_empty'; $instructions['valid_type']['gateway'] = self::getValidationFunction( 'gateway' ); + break; + case 'validate_currency_code': + $check_type = 'calculated'; break; case 'validate_card_type': $check_type = 'calculated'; @@ -428,6 +432,9 @@ $result = $self::$function( $data[$field], $data['currency_code'], $data['gateway'] ); } //otherwise, just don't do the validation. The other stuff will be complaining already. break; + case 'validate_currency_code': + $result = $self::$function( $data[$field], $data['gateway'] ); + break; case 'validate_card_type': //the contingent field in this case isn't strictly required, so this is going to look funny. if ( array_key_exists( 'card_number', $instructions['valid_type'] ) && $instructions['valid_type']['card_number'] === true ){ @@ -438,7 +445,7 @@ } break; default: - $result = self::$function( $data[$field] ); + $result = $self::$function( $data[$field] ); } $instructions['calculated'][$field] = $result; @@ -490,22 +497,18 @@ switch ( $field ){ case 'email': return 'validate_email'; - break; case 'amount': //we only have to do the one: It will have been normalized by now. return 'validate_amount'; //this one is interesting. Needs two params. - break; case 'card_num': return 'validate_credit_card'; - break; case 'card_type': return 'validate_card_type'; - break; case 'gateway': return 'validate_gateway'; - break; case 'country': return 'validate_country_allowed'; - break; + case 'currency_code': + return 'validate_currency_code'; } if ( in_array( $field, self::getNumericFields() ) ){ @@ -567,7 +570,22 @@ return true; } - + + protected static function validate_currency_code( $value, $gateway ) { + if ( !$value ) { + return false; + } + + $gateway_class = self::getGatewayClass($gateway); + if ( !$gateway_class ){ + return false; + } + + // FIXME: we should be checking currencies using the live gateway + // object, the result is often dependent on payment method/submethod, + // country, and so on. + return in_array( $value, $gateway_class::getCurrencies() ); + } /** * validate_card_type diff --git a/gateway_common/gateway.adapter.php b/gateway_common/gateway.adapter.php index f69959f..0764057 100644 --- a/gateway_common/gateway.adapter.php +++ b/gateway_common/gateway.adapter.php @@ -99,7 +99,7 @@ */ function defineReturnValueMap(); - function getCurrencies(); + static function getCurrencies(); } /** diff --git a/gateway_forms/rapidhtml/RapidHtmlResources.php b/gateway_forms/rapidhtml/RapidHtmlResources.php index 7f2388a..646875a 100644 --- a/gateway_forms/rapidhtml/RapidHtmlResources.php +++ b/gateway_forms/rapidhtml/RapidHtmlResources.php @@ -9,6 +9,7 @@ $wgPayflowRapidHtmlRemoteExtPath = 'DonationInterface/payflowpro_gateway/forms'; $wgGlobalCollectRapidHtmlRemoteExtPath = 'DonationInterface/globalcollect_gateway/forms'; $wgAdyenRapidHtmlRemoteExtPath = 'DonationInterface/adyen_gateway/forms'; +$wgPaypalRapidHtmlRemoteExtPath = 'DonationInterface/paypal_gateway/forms'; /** * LIGHTBOX @@ -273,3 +274,9 @@ 'localBasePath' => dirname( __FILE__ ).'/../../adyen_gateway/forms', 'remoteExtPath' => $wgAdyenRapidHtmlRemoteExtPath, ); + +$wgResourceModules[ 'paypal.js' ] = array( + 'scripts' => 'js/paypal.js', + 'localBasePath' => dirname( __FILE__ ).'/../../paypal_gateway/forms', + 'remoteExtPath' => $wgPaypalRapidHtmlRemoteExtPath, +); diff --git a/globalcollect_gateway/globalcollect.adapter.php b/globalcollect_gateway/globalcollect.adapter.php index e380842..3ff4403 100644 --- a/globalcollect_gateway/globalcollect.adapter.php +++ b/globalcollect_gateway/globalcollect.adapter.php @@ -1644,7 +1644,7 @@ * Gets all the currency codes appropriate for this gateway * @return array of currency codes */ - function getCurrencies() { + static function getCurrencies() { // If you update this list, also update the list in the exchange_rates drupal module. $currencies = array( 'AED', // UAE dirham @@ -2241,7 +2241,6 @@ } protected function stage_fiscal_number( $type = 'request' ) { - $this->log("XXX"); if ( $type != 'request' ){ return; //nothing to do here. } diff --git a/payflowpro_gateway/payflowpro.adapter.php b/payflowpro_gateway/payflowpro.adapter.php index 8a78118..86a60a4 100644 --- a/payflowpro_gateway/payflowpro.adapter.php +++ b/payflowpro_gateway/payflowpro.adapter.php @@ -206,7 +206,7 @@ * Gets all the currency codes appropriate for this gateway * @return array of currency codes */ - function getCurrencies() { + static function getCurrencies() { $currencies = array( 'USD', // U.S. Dollar 'GBP', // British Pound diff --git a/paypal_gateway/forms/html/_donation-amount/ARS.html b/paypal_gateway/forms/html/_donation-amount/ARS.html new file mode 100644 index 0000000..f7130d5 --- /dev/null +++ b/paypal_gateway/forms/html/_donation-amount/ARS.html @@ -0,0 +1 @@ +$@amount \ No newline at end of file diff --git a/paypal_gateway/forms/html/_donation-amount/CLP.html b/paypal_gateway/forms/html/_donation-amount/CLP.html new file mode 100644 index 0000000..f7130d5 --- /dev/null +++ b/paypal_gateway/forms/html/_donation-amount/CLP.html @@ -0,0 +1 @@ +$@amount \ No newline at end of file diff --git a/paypal_gateway/forms/html/_donation-amount/EUR.html b/paypal_gateway/forms/html/_donation-amount/EUR.html new file mode 100644 index 0000000..4c21e5c --- /dev/null +++ b/paypal_gateway/forms/html/_donation-amount/EUR.html @@ -0,0 +1 @@ +€@amount \ No newline at end of file diff --git a/paypal_gateway/forms/html/_donation-amount/GBP.html b/paypal_gateway/forms/html/_donation-amount/GBP.html new file mode 100644 index 0000000..7e982e0 --- /dev/null +++ b/paypal_gateway/forms/html/_donation-amount/GBP.html @@ -0,0 +1 @@ +£@amount \ No newline at end of file diff --git a/paypal_gateway/forms/html/_donation-amount/MXP.html b/paypal_gateway/forms/html/_donation-amount/MXP.html new file mode 100644 index 0000000..f7130d5 --- /dev/null +++ b/paypal_gateway/forms/html/_donation-amount/MXP.html @@ -0,0 +1 @@ +$@amount \ No newline at end of file diff --git a/paypal_gateway/forms/html/_donation-amount/RUB.html b/paypal_gateway/forms/html/_donation-amount/RUB.html new file mode 100644 index 0000000..f932081 --- /dev/null +++ b/paypal_gateway/forms/html/_donation-amount/RUB.html @@ -0,0 +1 @@ +@amount рублей \ No newline at end of file diff --git a/paypal_gateway/forms/html/_donation-amount/USD.html b/paypal_gateway/forms/html/_donation-amount/USD.html new file mode 100644 index 0000000..f7130d5 --- /dev/null +++ b/paypal_gateway/forms/html/_donation-amount/USD.html @@ -0,0 +1 @@ +$@amount \ No newline at end of file diff --git a/paypal_gateway/forms/html/_donation-amount/default.html b/paypal_gateway/forms/html/_donation-amount/default.html new file mode 100644 index 0000000..25770c5 --- /dev/null +++ b/paypal_gateway/forms/html/_donation-amount/default.html @@ -0,0 +1 @@ +@amount @currency_code \ No newline at end of file diff --git a/paypal_gateway/forms/html/_personal-information/default.html b/paypal_gateway/forms/html/_personal-information/default.html new file mode 100644 index 0000000..51a3fd8 --- /dev/null +++ b/paypal_gateway/forms/html/_personal-information/default.html @@ -0,0 +1,24 @@ +<tr> + <td colspan="2"> + <h3 class="cc_header">%donate_interface-cc-form-header-personal%<img src="@script_path/extensions/DonationInterface/gateway_forms/includes/padlock.gif" style="vertical-align:baseline;margin-left:8px;"></h3> + </td> +</tr> +<tr> + <td colspan="2"> + <input class="halfwidth" name="fname" value="@fname" type="text" placeholder="%donate_interface-donor-fname%" id="fname"><input class="halfwidth leftmar" name="lname" value="@lname" type="text" placeholder="%donate_interface-donor-lname%" id="lname"> + </td> +</tr> +<tr> + <td colspan="2"> + <input class="fullwidth" name="emailAdd" value="@emailAdd" type="text" title="%donate_interface-donor-email%" placeholder="%donate_interface-donor-email%" id="emailAdd"> + </td> +</tr> +<tr> + <td colspan="2"> + <select class="txt" id="country" name="country" value="@country" placeholder="%donate_interface-country%"> + <option value="">%donate_interface-select-country%</option> + @select_country + </select> + </td> +</tr> + diff --git a/paypal_gateway/forms/html/paypal.html b/paypal_gateway/forms/html/paypal.html new file mode 100644 index 0000000..7c56c83 --- /dev/null +++ b/paypal_gateway/forms/html/paypal.html @@ -0,0 +1,103 @@ +<script type="text/javascript"> + mw.loader.load('paypal.js'); + // these must go through RapidHTML and thus are inline + var amountErrors = ['#general|escape','#retryMsg|escape','#amount|escape']; + var billingErrors = ['#fname|escape','#lname|escape','#country|escape','#emailAdd|escape']; + var paymentErrors = []; + var actionURL = "@action"; + var scriptPath = "@script_path"; +</script> + +<table width="100%" cellspacing="0" cellpadding="0" border="0"> + <tbody> + <tr> + <td id="appeal" valign="top"> + {{LanguageSwitch|2011FR/@appeal/text|@language}} + </td> + <td id="donate" valign="top"> + <div id="greenBackground" class=""> + <noscript> + <div id="noscript"> + <p id="noscript-msg">%donate_interface-noscript-msg%</p> + <p id="noscript-redirect-msg">%donate_interface-noscript-redirect-msg%</p> + <p id="noscript-redirect-link"> + <a href="https://wikimediafoundation.org/wiki/Special:LandingCheck?basic=true&landing_page=DonateNonJS&language=@language&uselang=@language&country=@country">https://wikimediafoundation.org/wiki/Special:LandingCheck?basic=true&landing_page=DonateNonJS&language=@language&uselang=@language&country=@country</a> + </p> + </div> + </noscript> + <p id="topError" class="creditcard-error-msg"></p> + + <form name="payment" method="post" action="@action"> + <div id="payflowpro_gateway-personal-info"> + <table id="payflow-table-donor"> + <tbody> + <tr> + <td colspan="2"> + <div id="step1header"> + <h3 class="amount_header">%donate_interface-amount-legend%: <span id="selected-amount"><input class="halfwidth" type="text" width="4" name="amount" value="@amount" /> @currency_code</span></h3> + </div> + </td> + </tr> + {% block personal-information country %} + <tr> + <td> + <div id="paymentContinue" style="margin-top: 10px;"> <input class="btn" id="paymentContinueBtn" type="button" value="%donate_interface-continue%" /></div> + </td> + </tr> + <tr> + <td> + <div id="payment" class="gainlayout" style="height: 0;text-align: center;"></div> + </td> + </tr> + <tr> + <td> + <div class="mw-donate-submessage" id="payflowpro_gateway-donate-submessage"> + <img src="@script_path/extensions/DonationInterface/gateway_forms/includes/padlock.gif" style="vertical-align:baseline;margin-right:4px;"> %donate_interface-donate-click% + </div> + </td> + </tr> + </tbody> + </table> + </div> + <input type="hidden" name="returnto" value="Thank_You/en" /> + <input type="hidden" value="0" name="PaypalRedirect" id="PaypalRedirect"> + <!-- This should be included in the personal_information templates --> + <!--<input type="hidden" value="@country" name="country" id="country" />--> + <input type="hidden" value="@currency_code" name="currency_code" /> + <input type="hidden" value="@utm_source" name="utm_source"/> + <input type="hidden" value="@utm_medium" name="utm_medium"/> + <input type="hidden" value="@utm_campaign" name="utm_campaign"/> + <input type="hidden" value="@language" name="language"/> + <input type="hidden" value="@referrer" name="referrer"/> + <input type="hidden" value="@comment" name="comment"/> + <input type="hidden" value="@comment-option" name="comment-option"/> + <input type="hidden" value="1" name="email-opt"/> + <input type="hidden" value="@token" name="token"/> + <input type="hidden" value="@order_id" name="order_id"/> + <input type="hidden" value="@numAttempt" name="numAttempt"/> + <input type="hidden" value="@contribution_tracking_id" name="contribution_tracking_id"/> + <input type="hidden" value="@data_hash" name="data_hash"/> + <input type="hidden" value="@owa_session" name="owa_session"/> + <input type="hidden" value="@owa_ref" name="owa_ref"/> + <input type="hidden" value="@gateway" name="gateway" /> + <input type="hidden" value="1" name="redirect"/> + </form> + </div> + <p id="informationsharing">%donate_interface-informationsharing|url%</p> + <table> + <tr> + <td> + <ul id="moreinfolinks"> + <li><a href="https://wikimediafoundation.org/wiki/Special:LandingCheck?landing_page=Problems_donating&basic=true&country=@country&language=@language&uselang=@language}}">%donate_interface-problemsdonating%</a></li> + <li><a href="https://wikimediafoundation.org/wiki/Special:LandingCheck?basic=true&landing_page=Ways_to_Give&language=@language&uselang=@language&country=@country">%donate_interface-otherways-short%</a></li> + <li><a href="https://wikimediafoundation.org/wiki/Special:LandingCheck?basic=true&landing_page=FAQ&language=@language&uselang=@language&country=@country">%donate_interface-faqs%</a></li> + <li><a href="https://wikimediafoundation.org/wiki/Special:LandingCheck?basic=true&landing_page=Tax_Deductibility&language=@language&uselang=@language&country=@country">%donate_interface-tax-info%</a></li> + </ul> + </td> + <td>@verisign_logo</td> + </tr> + </table> + </td> + </tr> + </tbody> +</table> diff --git a/paypal_gateway/forms/js/paypal.js b/paypal_gateway/forms/js/paypal.js new file mode 100644 index 0000000..bbeed4e --- /dev/null +++ b/paypal_gateway/forms/js/paypal.js @@ -0,0 +1,45 @@ + +$( document ).ready( function () { + + // check for RapidHtml errors and display, if any + var amountErrorString = ""; + var billingErrorString = ""; + var paymentErrorString = ""; + + // generate formatted errors to display + var temp = []; + for ( var e in amountErrors ) + if ( amountErrors[e] != "" ) + temp[temp.length] = amountErrors[e]; + amountErrorString = temp.join( "<br />" ); + + temp = []; + for ( var f in billingErrors ) + if ( billingErrors[f] != "" ) + temp[temp.length] = billingErrors[f]; + billingErrorString = temp.join( "<br />" ); + + temp = []; + for ( var g in paymentErrors ) + if ( paymentErrors[g] != "" ) + temp[temp.length] = paymentErrors[g]; + paymentErrorString = temp.join( "<br />" ); + + // show the errors + if ( amountErrorString != "" ) { + $( "#topError" ).html( amountErrorString ); + } else if ( billingErrorString != "" ) { + $( "#topError" ).html( billingErrorString ); + } else if ( paymentErrorString != "" ) { + $( "#topError" ).html( paymentErrorString ); + } + + $( "#paymentContinueBtn" ).live( "click", function() { + if ( validateAmount() && validate_form( document.payment ) ) { + document.payment.action = actionURL; + document.payment.submit(); + } + } ); + +} ); + diff --git a/paypal_gateway/paypal.adapter.php b/paypal_gateway/paypal.adapter.php index 1752fee..2b5bda6 100644 --- a/paypal_gateway/paypal.adapter.php +++ b/paypal_gateway/paypal.adapter.php @@ -145,7 +145,7 @@ } } - function getCurrencies() { + static function getCurrencies() { // see https://www.x.com/developers/paypal/documentation-tools/api/currency-codes return array( 'AUD', @@ -181,12 +181,18 @@ } } - protected function pre_process_donate() { - $validation_errors = DataValidator::validate( $this->getData_Unstaged_Escaped(), array( 'gateway', 'currency_code', 'amount' ) ); - if ( !empty( $validation_errors ) - || !in_array( $this->getData_Unstaged_Escaped( 'currency_code' ), $this->getCurrencies() ) ) - { - $this->setValidationAction( 'reject', TRUE ); + public function validatedOK() { + $result = parent::validatedOK(); + + if ( !$result ) { + $validation_errors = $this->getValidationErrors(); + if ( array_keys( $validation_errors ) === array( 'amount' ) + and (!$this->staged_data['amount'] or (float)$this->staged_data['amount'] == 0 ) ) { + // ignore empty amount error + $result = true; + } } + + return $result; } } diff --git a/paypal_gateway/paypal_gateway.body.php b/paypal_gateway/paypal_gateway.body.php index 4708423..560612a 100644 --- a/paypal_gateway/paypal_gateway.body.php +++ b/paypal_gateway/paypal_gateway.body.php @@ -60,7 +60,24 @@ $this->setHeaders(); + $redirect = false; if ( $this->getRequest()->getText( 'redirect', 0 ) ) { + $redirect = true; + } + if ( $this->validateForm() ) { + $form_errors = $this->adapter->getValidationErrors(); + if ( !array_diff( array( 'currency_code' ), array_keys( $form_errors ) ) ) { + // If the currency is invalid, fallback to USD and allow redirect. + $this->adapter->addData( array( + 'amount' => "0.00", + 'currency_code' => 'USD', + ) ); + $this->adapter->revalidate(); + } else { + $redirect = false; + } + } + if ( $redirect ) { if ( $this->getRequest()->getText( 'recurring', 0 ) ) { $result = $this->adapter->do_transaction( 'DonateRecurring' ); } else { @@ -70,11 +87,8 @@ if ( !empty( $result['redirect'] ) ) { $this->getOutput()->redirect( $result['redirect'] ); } - - if ( !empty( $result[ 'errors' ] ) ) { - //XXX not passing specific errors to the user. - $this->getOutput()->redirect( $this->adapter->getFailPage() ); - } } + + $this->displayForm(); } } -- To view, visit https://gerrit.wikimedia.org/r/51808 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ide392956212db511fbbd908ff94986d3ab861544 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: master Gerrit-Owner: Adamw <awi...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits