Awight has uploaded a new change for review. https://gerrit.wikimedia.org/r/287157
Change subject: PayPal Express Checkout: support locale well enough to get ja_JP ...................................................................... PayPal Express Checkout: support locale well enough to get ja_JP Bug: T131811 Change-Id: I29e4a91260a820a79963949af90a10fba092d4b4 --- M DonationInterface.php A gateway_common/IsoDate.php A paypal_gateway/express_checkout/PaypalExpressLocale.php M paypal_gateway/express_checkout/config/transformers.yaml 4 files changed, 46 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/57/287157/1 diff --git a/DonationInterface.php b/DonationInterface.php index a7f86a8..d26e186 100644 --- a/DonationInterface.php +++ b/DonationInterface.php @@ -59,6 +59,7 @@ $wgAutoloadClasses['GatewayAdapter'] = __DIR__ . '/gateway_common/gateway.adapter.php'; $wgAutoloadClasses['GatewayPage'] = __DIR__ . '/gateway_common/GatewayPage.php'; $wgAutoloadClasses['GatewayType'] = __DIR__ . '/gateway_common/GatewayType.php'; +$wgAutoloadClasses['IsoDate'] = __DIR__ . '/gateway_common/IsoDate.php'; $wgAutoloadClasses['DataValidator'] = __DIR__ . '/gateway_common/DataValidator.php'; $wgAutoloadClasses['LogPrefixProvider'] = __DIR__ . '/gateway_common/gateway.adapter.php'; $wgAutoloadClasses['MessageUtils'] = __DIR__ . '/gateway_common/MessageUtils.php'; @@ -119,6 +120,7 @@ $wgAutoloadClasses['PaypalExpressAdapter'] = __DIR__ . '/paypal_gateway/express_checkout/paypal_express.adapter.php'; $wgAutoloadClasses['PaypalExpressGateway'] = __DIR__ . '/paypal_gateway/express_checkout/paypal_express_gateway.body.php'; $wgAutoloadClasses['PaypalExpressGatewayResult'] = __DIR__ . '/paypal_gateway/express_checkout/paypal_express_resultswitcher.body.php'; +$wgAutoloadClasses['PaypalExpressLocale'] = __DIR__ . '/paypal_gateway/express_checkout/PaypalExpressLocale.php'; $wgAutoloadClasses['PaypalExpressReturnUrl'] = __DIR__ . '/paypal_gateway/express_checkout/PaypalExpressReturnUrl.php'; $wgAutoloadClasses['PaypalLegacyAdapter'] = __DIR__ . '/paypal_gateway/legacy/paypal_legacy.adapter.php'; $wgAutoloadClasses['PaypalLegacyGateway'] = __DIR__ . '/paypal_gateway/legacy/paypal_legacy_gateway.body.php'; diff --git a/gateway_common/IsoDate.php b/gateway_common/IsoDate.php new file mode 100644 index 0000000..a0ba2dc --- /dev/null +++ b/gateway_common/IsoDate.php @@ -0,0 +1,21 @@ +<?php + +class IsoDate + implements + StagingHelper, + UnstagingHelper +{ + public function stage( GatewayType $adapter, $normalized, &$staged_data ) { + // Print timestamp as ISO 8601 string. + if ( isset( $normalized['date'] ) ) { + $staged_data['date'] = date( DateTime::ISO8601, $normalized['date'] ); + } + } + + public function unstage( GatewayType $adapter, $stagedData, &$unstagedData ) { + // Parse ISO 8601 string to timestamp. + if ( isset( $stagedData['date'] ) ) { + $unstagedData = strtotime( $stagedData['date'] ); + } + } +} diff --git a/paypal_gateway/express_checkout/PaypalExpressLocale.php b/paypal_gateway/express_checkout/PaypalExpressLocale.php new file mode 100644 index 0000000..a1a2bc3 --- /dev/null +++ b/paypal_gateway/express_checkout/PaypalExpressLocale.php @@ -0,0 +1,21 @@ +<?php + +/** + * The supported locales are listed at + * https://developer.paypal.com/docs/classic/api/locale_codes/ , however, we + * might do as well simply sending language_country no matter what. PayPal + * will extract the country code from our locale code anyway. + * + * TODO: If this strategy is successful, then move to gateway_common as + * SimpleCountryLocale + */ +class PaypalExpressLocale + implements StagingHelper +{ + public function stage( GatewayType $adapter, $normalized, &$staged_data ) { + if ( isset( $normalized['language'] ) && isset( $normalized['country'] ) ) { + $parts = explode( '_', $normalized['language'] ); + $staged_data['language'] = "{$parts[0]}_{$normalized['country']}"; + } + } +} diff --git a/paypal_gateway/express_checkout/config/transformers.yaml b/paypal_gateway/express_checkout/config/transformers.yaml index 72d814b..66a25df 100644 --- a/paypal_gateway/express_checkout/config/transformers.yaml +++ b/paypal_gateway/express_checkout/config/transformers.yaml @@ -1 +1,3 @@ +- IsoDate +- PaypalExpressLocale - PaypalExpressReturnUrl -- To view, visit https://gerrit.wikimedia.org/r/287157 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I29e4a91260a820a79963949af90a10fba092d4b4 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