From 39f8bf5a92af247bf6c6eccc66d4552a56b5d381 Mon Sep 17 00:00:00 2001 From: Michael Shafrir Date: Thu, 7 May 2020 22:21:41 -0400 Subject: [PATCH] Capitalize currency code in GooglePayJsonFactory --- .../com/stripe/android/GooglePayJsonFactory.kt | 4 ++-- .../stripe/android/GooglePayJsonFactoryTest.kt | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/stripe/src/main/java/com/stripe/android/GooglePayJsonFactory.kt b/stripe/src/main/java/com/stripe/android/GooglePayJsonFactory.kt index 856c15eea3b..bafb5c22716 100644 --- a/stripe/src/main/java/com/stripe/android/GooglePayJsonFactory.kt +++ b/stripe/src/main/java/com/stripe/android/GooglePayJsonFactory.kt @@ -129,7 +129,7 @@ class GooglePayJsonFactory constructor( transactionInfo: TransactionInfo ): JSONObject { return JSONObject() - .put("currencyCode", transactionInfo.currencyCode) + .put("currencyCode", transactionInfo.currencyCode.toUpperCase(Locale.ROOT)) .put("totalPriceStatus", transactionInfo.totalPriceStatus.code) .apply { transactionInfo.countryCode?.let { @@ -381,7 +381,7 @@ class GooglePayJsonFactory constructor( internal val merchantName: String? = null ) : Parcelable - companion object { + private companion object { private const val API_VERSION = 2 private const val API_VERSION_MINOR = 0 diff --git a/stripe/src/test/java/com/stripe/android/GooglePayJsonFactoryTest.kt b/stripe/src/test/java/com/stripe/android/GooglePayJsonFactoryTest.kt index 7d2fc387b55..99602df5f93 100644 --- a/stripe/src/test/java/com/stripe/android/GooglePayJsonFactoryTest.kt +++ b/stripe/src/test/java/com/stripe/android/GooglePayJsonFactoryTest.kt @@ -175,6 +175,21 @@ class GooglePayJsonFactoryTest { .isEqualTo("US") } + @Test + fun currencyCode_shouldBeCapitalized() { + val createPaymentDataRequestJson = factory.createPaymentDataRequest( + transactionInfo = GooglePayJsonFactory.TransactionInfo( + currencyCode = "usd", + totalPriceStatus = GooglePayJsonFactory.TransactionInfo.TotalPriceStatus.Final + ) + ) + val currencyCode = createPaymentDataRequestJson + .getJSONObject("transactionInfo") + .getString("currencyCode") + assertThat(currencyCode) + .isEqualTo("USD") + } + @Test fun shippingAddressAllowedCountryCodes_shouldBeCapitalized() { val createPaymentDataRequestJson = factory.createPaymentDataRequest(