From 221c8b70b14e90c84ebdb7e90e61795e6dc5a202 Mon Sep 17 00:00:00 2001 From: Sara Vasquez Date: Tue, 20 Oct 2026 14:14:03 -0700 Subject: [PATCH] feat: add transactionId support to GooglePayRequest Google requires merchants to pass a transactionId in TransactionInfo for reconciliation during promotional campaigns, but the SDK had no way to set it. Adds an optional transactionId property that is serialized into the transactionInfo JSON sent to the Google Pay API. Co-Authored-By: Claude Sonnet 5 --- CHANGELOG.md | 1 + .../braintreepayments/api/googlepay/GooglePayClientTest.kt | 4 +++- .../braintreepayments/api/googlepay/GooglePayRequestTest.kt | 5 ++++- .../com/braintreepayments/api/googlepay/GooglePayRequest.kt | 6 ++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd93cf3a21..1aa671b8b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * GooglePay * Add optional `resultKey` parameter to `GooglePayLauncher` constructors, allowing a unique registration key per launcher instance + * Add optional `transactionId` property to `GooglePayRequest` to pass a merchant-defined transaction identifier to Google Pay's `TransactionInfo` * ThreeDSecure * Add optional `resultKey` parameter to `ThreeDSecureLauncher` constructors, allowing a unique registration key per launcher instance * SEPADirectDebit diff --git a/GooglePay/src/androidTest/java/com/braintreepayments/api/googlepay/GooglePayClientTest.kt b/GooglePay/src/androidTest/java/com/braintreepayments/api/googlepay/GooglePayClientTest.kt index 39bded18e7..4320a0ea2c 100644 --- a/GooglePay/src/androidTest/java/com/braintreepayments/api/googlepay/GooglePayClientTest.kt +++ b/GooglePay/src/androidTest/java/com/braintreepayments/api/googlepay/GooglePayClientTest.kt @@ -249,7 +249,8 @@ class GooglePayClientTest { totalPrice = "25.50", totalPriceStatus = GooglePayTotalPriceStatus.TOTAL_PRICE_STATUS_ESTIMATED, countryCode = "DE", - googleMerchantName = "Test Merchant" + googleMerchantName = "Test Merchant", + transactionId = "transaction-id-123" ) val countDownLatch = CountDownLatch(1) @@ -263,6 +264,7 @@ class GooglePayClientTest { val transactionInfo = paymentDataRequestJson.getJSONObject("transactionInfo") assertEquals("EUR", transactionInfo.getString("currencyCode")) assertEquals("25.50", transactionInfo.getString("totalPrice")) + assertEquals("transaction-id-123", transactionInfo.getString("transactionId")) assertEquals("ESTIMATED", transactionInfo.getString("totalPriceStatus")) assertEquals("DE", transactionInfo.getString("countryCode")) diff --git a/GooglePay/src/androidTest/java/com/braintreepayments/api/googlepay/GooglePayRequestTest.kt b/GooglePay/src/androidTest/java/com/braintreepayments/api/googlepay/GooglePayRequestTest.kt index 08928c06bd..21efa22ad3 100644 --- a/GooglePay/src/androidTest/java/com/braintreepayments/api/googlepay/GooglePayRequestTest.kt +++ b/GooglePay/src/androidTest/java/com/braintreepayments/api/googlepay/GooglePayRequestTest.kt @@ -53,7 +53,8 @@ class GooglePayRequestTest { totalPriceLabel = "Total", allowCreditCards = false, displayItems = displayItems, - checkoutOption = GooglePayCheckoutOption.COMPLETE_IMMEDIATE_PURCHASE + checkoutOption = GooglePayCheckoutOption.COMPLETE_IMMEDIATE_PURCHASE, + transactionId = "transaction-id-123" ) request.setEnvironment("production") @@ -83,6 +84,7 @@ class GooglePayRequestTest { assertEquals("Subtotal", parceled.displayItems[0].label) assertEquals("Tax", parceled.displayItems[1].label) assertEquals(GooglePayCheckoutOption.COMPLETE_IMMEDIATE_PURCHASE, parceled.checkoutOption) + assertEquals("transaction-id-123", parceled.transactionId) assertEquals("PRODUCTION", parceled.getEnvironment()) parcel.recycle() @@ -119,6 +121,7 @@ class GooglePayRequestTest { assertTrue(parceled.allowCreditCards) assertTrue(parceled.displayItems.isEmpty()) assertEquals(GooglePayCheckoutOption.DEFAULT, parceled.checkoutOption) + assertNull(parceled.transactionId) assertNull(parceled.getEnvironment()) parcel.recycle() diff --git a/GooglePay/src/main/java/com/braintreepayments/api/googlepay/GooglePayRequest.kt b/GooglePay/src/main/java/com/braintreepayments/api/googlepay/GooglePayRequest.kt index 71c7620e16..2c0aee6caf 100644 --- a/GooglePay/src/main/java/com/braintreepayments/api/googlepay/GooglePayRequest.kt +++ b/GooglePay/src/main/java/com/braintreepayments/api/googlepay/GooglePayRequest.kt @@ -40,6 +40,10 @@ import java.util.Locale * @property displayItems Optional list of cart items shown in the payment sheet * (e.g. subtotals, sales taxes, shipping charges, discounts etc.). If you pass non-empty list of display items * be sure to also set the value for [totalPriceLabel]. + * @property transactionId Optional. A unique ID that identifies a transaction attempt. Merchants + * may use an existing ID or generate a specific one for Google Pay transactions. This field is + * optional, but merchants are strongly encouraged to add it for the best troubleshooting + * experience with Google. */ @Suppress("TooManyFunctions") @Parcelize @@ -61,6 +65,7 @@ class GooglePayRequest @JvmOverloads constructor( var allowCreditCards: Boolean = true, var displayItems: MutableList = ArrayList(), var checkoutOption: GooglePayCheckoutOption? = GooglePayCheckoutOption.DEFAULT, + var transactionId: String? = null, private var environment: String? = null, private val allowedPaymentMethods: MutableMap = HashMap(), private val tokenizationSpecifications: MutableMap = HashMap(), @@ -155,6 +160,7 @@ class GooglePayRequest @JvmOverloads constructor( } transactionInfoJson.putOpt("totalPriceLabel", totalPriceLabel) transactionInfoJson.putOpt("checkoutOption", checkoutOption?.stringValue) + transactionInfoJson.putOpt("transactionId", transactionId) for ((key, value) in this.allowedPaymentMethods) { try {