Skip to content

Commit

Permalink
Update Google Pay
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahkoop committed Dec 14, 2023
1 parent bfb7b59 commit baa70a7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
});

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.braintreepayments.api;

import androidx.annotation.Nullable;

import com.google.android.gms.wallet.PaymentMethodTokenizationParameters;

import java.util.Collection;
Expand All @@ -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.
*
* <p>
* {@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<Integer>} 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<Integer>} of card networks supported by the current
* Braintree merchant account.
* @param tokenizationParameters {@link GooglePayTokenizationParameters}
*/
void onResult(@Nullable PaymentMethodTokenizationParameters parameters, @Nullable Collection<Integer> allowedCardNetworks);
void onTokenizationParametersResult(GooglePayTokenizationParameters tokenizationParameters);
}
Original file line number Diff line number Diff line change
@@ -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<Integer>) : GooglePayTokenizationParameters()

/**
* There was an [error] creating the request
*/
class Failure(val error: Exception) : GooglePayTokenizationParameters()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit baa70a7

Please sign in to comment.