Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Google Pay Version and add totalPriceLabel #809

Merged
merged 4 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Braintree Android SDK Release Notes

## unreleased
* GooglePay
* Bump `play-services-wallet` version to `19.2.1`
* Add `totalPriceLabel` to `GooglePayRequest`

## 4.39.0 (2023-10-16)

* BraintreeCore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void launchGooglePay(View v) {
.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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General q, is there a reason we want to set this to EUR for the demo vs USD?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was working to resolve this long-standing merchant request #321 but in testing discovered that the total price label seems to be visible depending on currency code. I reached out to Google Pay integration support to confirm which countries/currencies it should be visible for, so we can provide a definitive answer. For now, I figured it was better for demo if the label is visible, so I changed it to EUR as default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, interesting that it's only available for certain currency codes. That makes sense though - thanks for the explanation!

}

public static String getGooglePayMerchantId(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,6 +50,7 @@ public class GooglePayRequest implements Parcelable {
private String googleMerchantId;
private String googleMerchantName;
private String countryCode;
private String totalPriceLabel;

public GooglePayRequest() {
}
Expand Down Expand Up @@ -222,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
Expand Down Expand Up @@ -261,6 +275,10 @@ public String toJson() {
transactionInfoJson.put("countryCode", countryCode);
}

if (totalPriceLabel != null) {
transactionInfoJson.put("totalPriceLabel", totalPriceLabel);
}

} catch (JSONException ignored) {
}

Expand Down Expand Up @@ -491,6 +509,11 @@ public boolean isCreditCardsAllowed() {
return allowCreditCards;
}

@Nullable
public String getTotalPriceLabel() {
return totalPriceLabel;
}

@Override
public int describeContents() {
return 0;
Expand All @@ -512,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) {
Expand All @@ -529,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<GooglePayRequest> CREATOR = new Creator<GooglePayRequest>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -89,6 +91,7 @@ public void parcelsCorrectly() {
.build();

request.setTransactionInfo(info);
request.setTotalPriceLabel("test");
request.setEmailRequired(true);
request.setPhoneNumberRequired(true);
request.setShippingAddressRequired(true);
Expand All @@ -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());
Expand Down Expand Up @@ -160,6 +164,7 @@ public void parcelsCorrectly_allFieldsPopulated_null() {
assertNull(parceled.getEnvironment());
assertNull(parceled.getGoogleMerchantId());
assertNull(parceled.getGoogleMerchantName());
assertNull(parceled.getTotalPriceLabel());
}

@Test
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
Expand Down
Loading