Awight has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/277985

Change subject: Encapsulate PayPal staging logic
......................................................................

Encapsulate PayPal staging logic

Bug: T130075
Change-Id: If06ca1b8a59195000116c5ccba51d8ba7b35f5f0
---
M DonationInterface.php
A paypal_gateway/CleanupRecurringLength.php
A paypal_gateway/PayPalLocale.php
M paypal_gateway/paypal.adapter.php
4 files changed, 73 insertions(+), 62 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface 
refs/changes/85/277985/1

diff --git a/DonationInterface.php b/DonationInterface.php
index 1b57331..0bd7bde 100644
--- a/DonationInterface.php
+++ b/DonationInterface.php
@@ -110,8 +110,10 @@
 $wgAutoloadClasses['AstroPayMethodCodec'] = __DIR__ . 
'/astropay_gateway/AstroPayMethodCodec.php';
 
 // Paypal
+$wgAutoloadClasses['CleanupRecurringLength'] = __DIR__ . 
'/paypal_gateway/CleanupRecurringLength.php';
 $wgAutoloadClasses['PaypalGateway'] = __DIR__ . 
'/paypal_gateway/paypal_gateway.body.php';
 $wgAutoloadClasses['PaypalAdapter'] = __DIR__ . 
'/paypal_gateway/paypal.adapter.php';
+$wgAutoloadClasses['PayPalLocale'] = __DIR__ . 
'/paypal_gateway/PayPalLocale.php';
 
 // Worldpay
 $wgAutoloadClasses['WorldpayGateway'] = __DIR__ . 
'/worldpay_gateway/worldpay_gateway.body.php';
diff --git a/paypal_gateway/CleanupRecurringLength.php 
b/paypal_gateway/CleanupRecurringLength.php
new file mode 100644
index 0000000..646df0f
--- /dev/null
+++ b/paypal_gateway/CleanupRecurringLength.php
@@ -0,0 +1,12 @@
+<?php
+
+/**
+ * Silly helper to remove field when empty.
+ */
+class CleanupRecurringLength implements StagingHelper {
+       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
+               if ( empty( $unstagedData['recurring_length'] ) ) {
+                       unset( $stagedData['recurring_length'] );
+               }
+       }
+}
diff --git a/paypal_gateway/PayPalLocale.php b/paypal_gateway/PayPalLocale.php
new file mode 100644
index 0000000..3244de4
--- /dev/null
+++ b/paypal_gateway/PayPalLocale.php
@@ -0,0 +1,55 @@
+<?php
+
+class PayPalLocale implements StagingHelper {
+       public function stage( GatewayType $adapter, $unstagedData, 
&$stagedData ) {
+               // FIXME: Document the upstream source for this reference data.
+               $supported_countries = array(
+                       'AU',
+                       'AT',
+                       'BE',
+                       'BR',
+                       'CA',
+                       'CH',
+                       'CN',
+                       'DE',
+                       'ES',
+                       'GB',
+                       'FR',
+                       'IT',
+                       'NL',
+                       'PL',
+                       'PT',
+                       'RU',
+                       'US',
+               );
+               $supported_full_locales = array(
+                       'da_DK',
+                       'he_IL',
+                       'id_ID',
+                       'jp_JP',
+                       'no_NO',
+                       'pt_BR',
+                       'ru_RU',
+                       'sv_SE',
+                       'th_TH',
+                       'tr_TR',
+                       'zh_CN',
+                       'zh_HK',
+                       'zh_TW',
+               );
+
+               if ( in_array( $unstagedData['country'], $supported_countries ) 
) {
+                       $stagedData['locale'] = $unstagedData['country'];
+               }
+
+               $fallbacks = Language::getFallbacksFor( strtolower( 
$unstagedData['language'] ) );
+               array_unshift( $fallbacks, strtolower( 
$unstagedData['language'] ) );
+               foreach ( $fallbacks as $lang ) {
+                       $locale = "{$lang}_{$unstagedData['country']}";
+                       if ( in_array( $locale, $supported_full_locales ) ) {
+                               $stagedData['locale'] = $locale;
+                               return;
+                       }
+               }
+       }
+}
diff --git a/paypal_gateway/paypal.adapter.php 
b/paypal_gateway/paypal.adapter.php
index 4d8fd3a..5762a9a 100644
--- a/paypal_gateway/paypal.adapter.php
+++ b/paypal_gateway/paypal.adapter.php
@@ -185,7 +185,10 @@
        }
 
        public function defineDataTransformers() {
-               $this->data_transformers = parent::getCoreDataTransformers();
+               $this->data_transformers = array_merge( 
parent::getCoreDataTransformers(), array(
+                       new CleanupRecurringLength(),
+                       new PayPalLocale(),
+               ) );
        }
 
        public function doPayment() {
@@ -258,66 +261,5 @@
                        // 'TRY', // in-country only
                        'USD',
                );
-       }
-
-       protected function stage_recurring_length() {
-               if (
-                       array_key_exists(
-                               'recurring_length', $this->staged_data
-                       ) && !$this->staged_data['recurring_length']
-               ) {
-                       unset( $this->staged_data['recurring_length'] );
-               }
-       }
-
-       protected function stage_locale() {
-               $supported_countries = array(
-                       'AU',
-                       'AT',
-                       'BE',
-                       'BR',
-                       'CA',
-                       'CH',
-                       'CN',
-                       'DE',
-                       'ES',
-                       'GB',
-                       'FR',
-                       'IT',
-                       'NL',
-                       'PL',
-                       'PT',
-                       'RU',
-                       'US',
-               );
-               $supported_full_locales = array(
-                       'da_DK',
-                       'he_IL',
-                       'id_ID',
-                       'jp_JP',
-                       'no_NO',
-                       'pt_BR',
-                       'ru_RU',
-                       'sv_SE',
-                       'th_TH',
-                       'tr_TR',
-                       'zh_CN',
-                       'zh_HK',
-                       'zh_TW',
-               );
-
-               if ( in_array( $this->unstaged_data['country'], 
$supported_countries ) ) {
-                       $this->staged_data['locale'] = 
$this->unstaged_data['country'];
-               }
-
-               $fallbacks = Language::getFallbacksFor( strtolower( 
$this->unstaged_data['language'] ) );
-               array_unshift( $fallbacks, strtolower( 
$this->unstaged_data['language'] ) );
-               foreach ( $fallbacks as $lang ) {
-                       $locale = "{$lang}_{$this->unstaged_data['country']}";
-                       if ( in_array( $locale, $supported_full_locales ) ) {
-                               $this->staged_data['locale'] = $locale;
-                               return;
-                       }
-               }
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/277985
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If06ca1b8a59195000116c5ccba51d8ba7b35f5f0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to