From 256e7c5ba751a886f4125fa9b173daa671738034 Mon Sep 17 00:00:00 2001 From: Sarah Koop Date: Thu, 19 Oct 2023 11:40:20 -0500 Subject: [PATCH 1/4] Upgrade to latest play services version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4e1b378c57..e98424a812 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ buildscript { "androidxTest" : "1.4.0", // NEXT MAJOR VERSION: Use a single up-to-date room version once we remove Java 7 support in favor of Java 11 "room" : roomVersion, - "playServices" : "19.1.0", + "playServices" : "19.2.1", "javaSourceCompatibility": sdkTargetJavaVersion, "javaTargetCompatibility": sdkTargetJavaVersion, ] From 974c1ec09dc15fed01b05cdf4e84fdc3b9fa1274 Mon Sep 17 00:00:00 2001 From: Sarah Koop Date: Thu, 19 Oct 2023 14:43:15 -0500 Subject: [PATCH 2/4] Update settings --- Demo/src/main/java/com/braintreepayments/demo/Settings.java | 2 +- .../main/java/com/braintreepayments/api/GooglePayRequest.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Demo/src/main/java/com/braintreepayments/demo/Settings.java b/Demo/src/main/java/com/braintreepayments/demo/Settings.java index 36423b06fc..e3511c4070 100644 --- a/Demo/src/main/java/com/braintreepayments/demo/Settings.java +++ b/Demo/src/main/java/com/braintreepayments/demo/Settings.java @@ -148,7 +148,7 @@ public static boolean isGooglePayEmailRequired(Context context) { } public static String getGooglePayCurrency(Context context) { - return getPreferences(context).getString("google_pay_currency", "USD"); + return getPreferences(context).getString("google_pay_currency", "EUR"); } public static String getGooglePayMerchantId(Context context) { diff --git a/GooglePay/src/main/java/com/braintreepayments/api/GooglePayRequest.java b/GooglePay/src/main/java/com/braintreepayments/api/GooglePayRequest.java index b8ab434ef0..ddd09c6411 100644 --- a/GooglePay/src/main/java/com/braintreepayments/api/GooglePayRequest.java +++ b/GooglePay/src/main/java/com/braintreepayments/api/GooglePayRequest.java @@ -47,6 +47,8 @@ public class GooglePayRequest implements Parcelable { private String googleMerchantName; private String countryCode; + private String + public GooglePayRequest() { } From 9940b19dbf79dba594f673ae1fa02e16c20a4e9a Mon Sep 17 00:00:00 2001 From: Sarah Koop Date: Thu, 19 Oct 2023 15:48:31 -0500 Subject: [PATCH 3/4] Add CHANGELOG and major version notes --- CHANGELOG.md | 5 ++++ .../demo/GooglePayFragment.java | 7 +---- .../api/GooglePayRequest.java | 27 +++++++++++++++++-- .../api/GooglePayRequestUnitTest.java | 6 +++++ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40a316830a..3a7ea43ee0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Braintree Android SDK Release Notes +## unreleased +* GooglePay + * Bump `play-services-wallet` version to `19.1.0` + * Add `totalPriceLabel` to `GooglePayRequest` + ## 4.39.0 (2023-10-16) * BraintreeCore diff --git a/Demo/src/main/java/com/braintreepayments/demo/GooglePayFragment.java b/Demo/src/main/java/com/braintreepayments/demo/GooglePayFragment.java index 6a895326f8..a245087fd6 100644 --- a/Demo/src/main/java/com/braintreepayments/demo/GooglePayFragment.java +++ b/Demo/src/main/java/com/braintreepayments/demo/GooglePayFragment.java @@ -20,7 +20,6 @@ import com.braintreepayments.api.GooglePayClient; import com.braintreepayments.api.GooglePayRequest; import com.google.android.gms.wallet.ShippingAddressRequirements; -import com.google.android.gms.wallet.TransactionInfo; import com.google.android.gms.wallet.WalletConstants; public class GooglePayFragment extends BaseFragment implements GooglePayListener { @@ -86,11 +85,7 @@ public void launchGooglePay(View v) { activity.setProgressBarIndeterminateVisibility(true); GooglePayRequest googlePayRequest = new GooglePayRequest(); - googlePayRequest.setTransactionInfo(TransactionInfo.newBuilder() - .setCurrencyCode(Settings.getGooglePayCurrency(activity)) - .setTotalPrice("1.00") - .setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL) - .build()); + googlePayRequest.setTotalPriceLabel("Braintree Demo Payment"); googlePayRequest.setAllowPrepaidCards(Settings.areGooglePayPrepaidCardsAllowed(activity)); googlePayRequest.setBillingAddressFormat(WalletConstants.BILLING_ADDRESS_FORMAT_FULL); googlePayRequest.setBillingAddressRequired(Settings.isGooglePayBillingAddressRequired(activity)); diff --git a/GooglePay/src/main/java/com/braintreepayments/api/GooglePayRequest.java b/GooglePay/src/main/java/com/braintreepayments/api/GooglePayRequest.java index ddd09c6411..e7b5627c7a 100644 --- a/GooglePay/src/main/java/com/braintreepayments/api/GooglePayRequest.java +++ b/GooglePay/src/main/java/com/braintreepayments/api/GooglePayRequest.java @@ -25,12 +25,16 @@ */ public class GooglePayRequest implements Parcelable { + // NEXT_MAJOR_VERSION: allow merchants to set transaction info params individually and build + // JSON object under the hood private TransactionInfo transactionInfo; private boolean emailRequired; private boolean phoneNumberRequired; private boolean billingAddressRequired; private int billingAddressFormat; private boolean shippingAddressRequired; + // NEXT_MAJOR_VERSION: allow merchants to set shipping address requirements params individually + // and build JSON object under the hood private ShippingAddressRequirements shippingAddressRequirements; private boolean allowPrepaidCards; private boolean payPalEnabled = true; @@ -46,8 +50,7 @@ public class GooglePayRequest implements Parcelable { private String googleMerchantId; private String googleMerchantName; private String countryCode; - - private String + private String totalPriceLabel; public GooglePayRequest() { } @@ -224,6 +227,15 @@ public void setAllowCreditCards(boolean allowCreditCards) { this.allowCreditCards = allowCreditCards; } + /** + * Optional + * + * @param totalPriceLabel Custom label for the total price within the display items + */ + public void setTotalPriceLabel(@Nullable String totalPriceLabel) { + this.totalPriceLabel = totalPriceLabel; + } + /** * Assemble all declared parts of a GooglePayRequest to a JSON string * for use in making requests against Google @@ -263,6 +275,10 @@ public String toJson() { transactionInfoJson.put("countryCode", countryCode); } + if (totalPriceLabel != null) { + transactionInfoJson.put("totalPriceLabel", totalPriceLabel); + } + } catch (JSONException ignored) { } @@ -493,6 +509,11 @@ public boolean isCreditCardsAllowed() { return allowCreditCards; } + @Nullable + public String getTotalPriceLabel() { + return totalPriceLabel; + } + @Override public int describeContents() { return 0; @@ -514,6 +535,7 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeString(googleMerchantName); dest.writeString(countryCode); dest.writeByte((byte) (allowCreditCards ? 1 : 0)); + dest.writeString(totalPriceLabel); } GooglePayRequest(Parcel in) { @@ -531,6 +553,7 @@ public void writeToParcel(Parcel dest, int flags) { googleMerchantName = in.readString(); countryCode = in.readString(); allowCreditCards = in.readByte() != 0; + totalPriceLabel = in.readString(); } public static final Creator CREATOR = new Creator() { diff --git a/GooglePay/src/test/java/com/braintreepayments/api/GooglePayRequestUnitTest.java b/GooglePay/src/test/java/com/braintreepayments/api/GooglePayRequestUnitTest.java index c869407c34..75a990f942 100644 --- a/GooglePay/src/test/java/com/braintreepayments/api/GooglePayRequestUnitTest.java +++ b/GooglePay/src/test/java/com/braintreepayments/api/GooglePayRequestUnitTest.java @@ -34,6 +34,7 @@ public void returnsAllValues() { .build(); GooglePayRequest request = new GooglePayRequest(); + request.setTotalPriceLabel("test"); request.setAllowPrepaidCards(true); request.setBillingAddressFormat(WalletConstants.BILLING_ADDRESS_FORMAT_FULL); request.setBillingAddressRequired(true); @@ -57,6 +58,7 @@ public void returnsAllValues() { assertEquals("PRODUCTION", request.getEnvironment()); assertEquals("google-merchant-id", request.getGoogleMerchantId()); assertEquals("google-merchant-name", request.getGoogleMerchantName()); + assertEquals("test", request.getTotalPriceLabel()); } @Test @@ -89,6 +91,7 @@ public void parcelsCorrectly() { .build(); request.setTransactionInfo(info); + request.setTotalPriceLabel("test"); request.setEmailRequired(true); request.setPhoneNumberRequired(true); request.setShippingAddressRequired(true); @@ -112,6 +115,7 @@ public void parcelsCorrectly() { assertEquals("USD", parceled.getTransactionInfo().getCurrencyCode()); assertEquals("10", parceled.getTransactionInfo().getTotalPrice()); assertEquals(WalletConstants.TOTAL_PRICE_STATUS_FINAL, parceled.getTransactionInfo().getTotalPriceStatus()); + assertEquals("test", parceled.getTotalPriceLabel()); assertTrue(parceled.isEmailRequired()); assertTrue(parceled.isPhoneNumberRequired()); assertTrue(parceled.isShippingAddressRequired()); @@ -160,6 +164,7 @@ public void parcelsCorrectly_allFieldsPopulated_null() { assertNull(parceled.getEnvironment()); assertNull(parceled.getGoogleMerchantId()); assertNull(parceled.getGoogleMerchantName()); + assertNull(parceled.getTotalPriceLabel()); } @Test @@ -220,6 +225,7 @@ public void generatesToJsonRequest() throws JSONException { request.setTokenizationSpecificationForType("CARD", tokenizationSpecificationParams); request.setAllowedPaymentMethod("PAYPAL", paypalAllowedPaymentMethodParams); request.setTokenizationSpecificationForType("PAYPAL", tokenizationSpecificationParams); + request.setTotalPriceLabel("Test Label"); request.setEnvironment("production"); request.setGoogleMerchantId("GOOGLE_MERCHANT_ID"); From d067e0d814f0f3efc6acad59b3fd11a6613bbf6a Mon Sep 17 00:00:00 2001 From: Sarah Koop Date: Thu, 19 Oct 2023 15:51:28 -0500 Subject: [PATCH 4/4] Fix typos --- CHANGELOG.md | 2 +- .../java/com/braintreepayments/demo/GooglePayFragment.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a7ea43ee0..312bcb292c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## unreleased * GooglePay - * Bump `play-services-wallet` version to `19.1.0` + * Bump `play-services-wallet` version to `19.2.1` * Add `totalPriceLabel` to `GooglePayRequest` ## 4.39.0 (2023-10-16) diff --git a/Demo/src/main/java/com/braintreepayments/demo/GooglePayFragment.java b/Demo/src/main/java/com/braintreepayments/demo/GooglePayFragment.java index a245087fd6..29396045fb 100644 --- a/Demo/src/main/java/com/braintreepayments/demo/GooglePayFragment.java +++ b/Demo/src/main/java/com/braintreepayments/demo/GooglePayFragment.java @@ -20,6 +20,7 @@ import com.braintreepayments.api.GooglePayClient; import com.braintreepayments.api.GooglePayRequest; import com.google.android.gms.wallet.ShippingAddressRequirements; +import com.google.android.gms.wallet.TransactionInfo; import com.google.android.gms.wallet.WalletConstants; public class GooglePayFragment extends BaseFragment implements GooglePayListener { @@ -85,6 +86,11 @@ public void launchGooglePay(View v) { activity.setProgressBarIndeterminateVisibility(true); GooglePayRequest googlePayRequest = new GooglePayRequest(); + googlePayRequest.setTransactionInfo(TransactionInfo.newBuilder() + .setCurrencyCode(Settings.getGooglePayCurrency(activity)) + .setTotalPrice("1.00") + .setTotalPriceStatus(WalletConstants.TOTAL_PRICE_STATUS_FINAL) + .build()); googlePayRequest.setTotalPriceLabel("Braintree Demo Payment"); googlePayRequest.setAllowPrepaidCards(Settings.areGooglePayPrepaidCardsAllowed(activity)); googlePayRequest.setBillingAddressFormat(WalletConstants.BILLING_ADDRESS_FORMAT_FULL);