Skip to content

Commit

Permalink
Google Pay Public Methods Single Result (#862)
Browse files Browse the repository at this point in the history
* Update Google Pay

* Update CHANGELOG

* Fix spacing
  • Loading branch information
sarahkoop authored Dec 18, 2023
1 parent 75c09ae commit 5633f12
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,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,21 @@
package com.braintreepayments.api

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

/**
* A request used to get Braintree specific tokenization parameters for a Google Pay
*/
sealed class GooglePayTokenizationParameters {

/**
* The request was successfully created
*/
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 5633f12

Please sign in to comment.