diff --git a/CHANGELOG.md b/CHANGELOG.md index 60550cb7d3..5e76b585f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,12 +40,13 @@ * Remove `GooglePayListener` and `GooglePayRequestPaymentCallback` * Add `GooglePayLauncher`, `GooglePayPaymentAuthRequest`, `GooglePayPaymentAuthRequestCallback`, `GooglePayPaymentAuthResult`, - `GooglePayTokenizeCallback` and `GooglePayLauncherCallback` + `GooglePayTokenizeCallback`, `GooglePayTokenizationParameters` and `GooglePayLauncherCallback` * Remove overload constructors, `setListener, and `onActivityResult` from `GooglePayClient` * Change `GooglePayClient#requestPayment` parameters and rename to `GooglePayClient#createPaymentAuthRequest` * Add `GooglePayClient#tokenize` * Remove `merchantId` from `GooglePayRequest` + * Change `GooglePayGetTokenizationParametersCallback` parameters * ThreeDSecure * Remove `ThreeDSecureListener` * Add `ThreeDSecureLauncher`, `ThreeDSecurePaymentAuthResult`, diff --git a/GooglePay/src/main/java/com/braintreepayments/api/GooglePayClient.java b/GooglePay/src/main/java/com/braintreepayments/api/GooglePayClient.java index b9121d16a2..b5c488ac09 100644 --- a/GooglePay/src/main/java/com/braintreepayments/api/GooglePayClient.java +++ b/GooglePay/src/main/java/com/braintreepayments/api/GooglePayClient.java @@ -158,13 +158,12 @@ public void isReadyToPay(@NonNull final FragmentActivity activity, public void getTokenizationParameters( @NonNull final GooglePayGetTokenizationParametersCallback callback) { braintreeClient.getConfiguration((configuration, e) -> { - if (configuration == null) { - callback.onResult(null, null); + if (configuration == null && e != null) { + callback.onTokenizationParametersResult(new GooglePayTokenizationParameters.Failure(e)); return; } - callback.onResult( - getTokenizationParameters(configuration, braintreeClient.getAuthorization()), - getAllowedCardNetworks(configuration)); + callback.onTokenizationParametersResult(new GooglePayTokenizationParameters.Success( + getTokenizationParameters(configuration, braintreeClient.getAuthorization()), getAllowedCardNetworks(configuration))); }); } diff --git a/GooglePay/src/main/java/com/braintreepayments/api/GooglePayGetTokenizationParametersCallback.java b/GooglePay/src/main/java/com/braintreepayments/api/GooglePayGetTokenizationParametersCallback.java index 40cc1e18e9..38133ef523 100644 --- a/GooglePay/src/main/java/com/braintreepayments/api/GooglePayGetTokenizationParametersCallback.java +++ b/GooglePay/src/main/java/com/braintreepayments/api/GooglePayGetTokenizationParametersCallback.java @@ -1,7 +1,5 @@ package com.braintreepayments.api; -import androidx.annotation.Nullable; - import com.google.android.gms.wallet.PaymentMethodTokenizationParameters; import java.util.Collection; @@ -17,17 +15,17 @@ public interface GooglePayGetTokenizationParametersCallback { * Wallet or Google Pay integrations, or when full control over the * {@link com.google.android.gms.wallet.MaskedWalletRequest} and * {@link com.google.android.gms.wallet.FullWalletRequest} is required. - * + *

* {@link PaymentMethodTokenizationParameters} should be supplied to the * {@link com.google.android.gms.wallet.MaskedWalletRequest} via - * {@link com.google.android.gms.wallet.MaskedWalletRequest.Builder#setPaymentMethodTokenizationParameters(PaymentMethodTokenizationParameters)} + * {@link + * com.google.android.gms.wallet.MaskedWalletRequest.Builder#setPaymentMethodTokenizationParameters(PaymentMethodTokenizationParameters)} * and {@link Collection} allowedCardNetworks should be supplied to the * {@link com.google.android.gms.wallet.MaskedWalletRequest} via - * {@link com.google.android.gms.wallet.MaskedWalletRequest.Builder#addAllowedCardNetworks(Collection)}. + * {@link + * com.google.android.gms.wallet.MaskedWalletRequest.Builder#addAllowedCardNetworks(Collection)}. * - * @param parameters {@link PaymentMethodTokenizationParameters} - * @param allowedCardNetworks {@link Collection} of card networks supported by the current - * Braintree merchant account. + * @param tokenizationParameters {@link GooglePayTokenizationParameters} */ - void onResult(@Nullable PaymentMethodTokenizationParameters parameters, @Nullable Collection allowedCardNetworks); + void onTokenizationParametersResult(GooglePayTokenizationParameters tokenizationParameters); } \ No newline at end of file diff --git a/GooglePay/src/main/java/com/braintreepayments/api/GooglePayTokenizationParameters.kt b/GooglePay/src/main/java/com/braintreepayments/api/GooglePayTokenizationParameters.kt new file mode 100644 index 0000000000..fd0d8eacd0 --- /dev/null +++ b/GooglePay/src/main/java/com/braintreepayments/api/GooglePayTokenizationParameters.kt @@ -0,0 +1,20 @@ +package com.braintreepayments.api + +import com.google.android.gms.wallet.PaymentMethodTokenizationParameters + +/** + * A request used to launch the Venmo app for continuation of the Venmo payment flow. + */ +sealed class GooglePayTokenizationParameters { + + /** + * The request was successfully created and is ready to be launched by [VenmoLauncher] + */ + class Success(val parameters: PaymentMethodTokenizationParameters, val allowedCardNetworks: + Collection) : GooglePayTokenizationParameters() + + /** + * There was an [error] creating the request + */ + class Failure(val error: Exception) : GooglePayTokenizationParameters() +} diff --git a/GooglePay/src/test/java/com/braintreepayments/api/GooglePayClientUnitTest.java b/GooglePay/src/test/java/com/braintreepayments/api/GooglePayClientUnitTest.java index df4f64376e..4e9ad809c9 100644 --- a/GooglePay/src/test/java/com/braintreepayments/api/GooglePayClientUnitTest.java +++ b/GooglePay/src/test/java/com/braintreepayments/api/GooglePayClientUnitTest.java @@ -2,6 +2,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -1247,13 +1248,11 @@ public void getTokenizationParameters_forwardsParametersAndAllowedCardsToCallbac new MockGooglePayInternalClientBuilder().build(); GooglePayClient sut = new GooglePayClient(braintreeClient, internalGooglePayClient); - GooglePayGetTokenizationParametersCallback getTokenizationParametersCallback = - mock(GooglePayGetTokenizationParametersCallback.class); - sut.getTokenizationParameters(getTokenizationParametersCallback); - - verify(getTokenizationParametersCallback).onResult( - any(PaymentMethodTokenizationParameters.class), - eq(sut.getAllowedCardNetworks(configuration))); + sut.getTokenizationParameters(tokenizationParameters -> { + assertTrue(tokenizationParameters instanceof GooglePayTokenizationParameters.Success); + assertNotNull(((GooglePayTokenizationParameters.Success) tokenizationParameters).getParameters()); + assertEquals(sut.getAllowedCardNetworks(configuration), ((GooglePayTokenizationParameters.Success) tokenizationParameters).getAllowedCardNetworks()); + }); } // endregion