XenoRyet has uploaded a new change for review. https://gerrit.wikimedia.org/r/297106
Change subject: Fix Handling of Curriencies Without Minor Units. ...................................................................... Fix Handling of Curriencies Without Minor Units. Adyen documentation specifies that amounts in currencies lacking minor units are to be passed as-is, rather than being converted to minor units as happens with other currencies. Example: USD 10.50 converts to 1050, JPY 150 should remain 150. Bug: T137607 Change-Id: I081cafb728fb50e6056a37e532a096587debc2a9 --- A adyen_gateway/AmountInMinorUnits.php M adyen_gateway/config/transformers.yaml M extension.json 3 files changed, 39 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/06/297106/1 diff --git a/adyen_gateway/AmountInMinorUnits.php b/adyen_gateway/AmountInMinorUnits.php new file mode 100644 index 0000000..2e2c6bf --- /dev/null +++ b/adyen_gateway/AmountInMinorUnits.php @@ -0,0 +1,37 @@ +<?php + +/** + * Stage: amount + * + * Adyen requires amounts to be passed as an integer representing the value + * in minor units for that currency. Currencies that lack a minor unit + * (such as JPY) are simply passed as is. + * For example: USD 10.50 would be changed to 1050, JPY 150 would be passed as 150. + */ +class AmountInMinorUnits implements StagingHelper, UnstagingHelper { + public function stage( GatewayType $adapter, $normalized, &$stagedData ) { + if ( empty( $normalized['amount'] ) || empty( $normalized['currency_code'] ) ) { + //can't do anything with amounts at all. Just go home. + unset( $stagedData['amount'] ); + return; + } + + $amount = $normalized['amount']; + if ( DataValidator::is_fractional_currency( $normalized['currency_code'] ) ) { + $stagedData['amount'] = $amount * 100; + } else { + $amount = floor( $amount ); + $stagedData['amount'] = $amount; + } + + } + + public function unstage( GatewayType $adapter, $stagedData, &$unstagedData ) { + if ( DataValidator::is_fractional_currency( $stagedData['currency_code'] ) ) { + $unstagedData['amount'] = $stagedData['amount'] / 100; + } else { + $unstagedData['amount'] = $stagedData['amount']; + } + + } +} \ No newline at end of file diff --git a/adyen_gateway/config/transformers.yaml b/adyen_gateway/config/transformers.yaml index 5077cf7..d6fb781 100644 --- a/adyen_gateway/config/transformers.yaml +++ b/adyen_gateway/config/transformers.yaml @@ -1,8 +1,8 @@ # Core - DonorEmail -- AmountInCents - StreetAddress # Adyen-specific +- AmountInMinorUnits - FullNameWithExceptions - DonorLocale - RiskScore diff --git a/extension.json b/extension.json index b009525..6d2c3c2 100644 --- a/extension.json +++ b/extension.json @@ -129,6 +129,7 @@ "AdyenAdapter": "adyen_gateway/adyen.adapter.php", "FullNameWithExceptions": "adyen_gateway/FullNameWithExceptions.php", "RiskScore": "adyen_gateway/RiskScore.php", + "AmountInMinorUnits": "adyen_gateway/AmountInMinorUnits.php", "AstroPayGateway": "astropay_gateway/astropay_gateway.body.php", "AstroPayGatewayResult": "astropay_gateway/astropay_resultswitcher.body.php", "AstroPayAdapter": "astropay_gateway/astropay.adapter.php", -- To view, visit https://gerrit.wikimedia.org/r/297106 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I081cafb728fb50e6056a37e532a096587debc2a9 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: master Gerrit-Owner: XenoRyet <dkozlow...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits