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

Google pay single result #842

Merged
merged 25 commits into from
Dec 18, 2023
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c8f27df
Add GooglePayResult
sarahkoop Dec 5, 2023
353524b
Implement GooglePayResult
sarahkoop Dec 5, 2023
832c75e
Fix unit tests for tokenize
sarahkoop Dec 5, 2023
d9bc436
Add GooglePayIsReadyToPayResult
sarahkoop Dec 5, 2023
fdda053
Implement ready to pay result
sarahkoop Dec 5, 2023
912cb3f
Fix demo
sarahkoop Dec 5, 2023
20827d0
Rename payment auth request
sarahkoop Dec 5, 2023
3101608
Add GooglePayPaymentAuthRequest
sarahkoop Dec 5, 2023
ac1c9d2
Implement GooglePayPaymentAuthRequest result
sarahkoop Dec 5, 2023
a4c56fe
Fix unit tests
sarahkoop Dec 5, 2023
9746f27
Fix demo app
sarahkoop Dec 5, 2023
c94af04
Fix demo integration
sarahkoop Dec 5, 2023
a52e641
Update CHANGELOG and migration guide
sarahkoop Dec 5, 2023
45994f0
Add ready to pay to migration guide
sarahkoop Dec 5, 2023
9a1699c
Merge branch 'v5' into google_pay_single_result
sarahkoop Dec 7, 2023
110ba31
Update GooglePay/src/main/java/com/braintreepayments/api/GooglePayCli…
sarahkoop Dec 7, 2023
f5e5c19
Convert error to cause
sarahkoop Dec 7, 2023
a5525b6
Revert error to cause changes
sarahkoop Dec 12, 2023
8b834c0
Update GooglePay/src/main/java/com/braintreepayments/api/GooglePayCli…
sarahkoop Dec 14, 2023
ab9e6f2
Update GooglePay/src/main/java/com/braintreepayments/api/GooglePayCli…
sarahkoop Dec 14, 2023
179f897
Fix spacing
sarahkoop Dec 14, 2023
db4037c
Merge branch 'google_pay_single_result' of https://github.com/braintr…
sarahkoop Dec 14, 2023
77e1a97
Update v5_MIGRATION_GUIDE.md
sarahkoop Dec 18, 2023
7f8e8af
Update v5_MIGRATION_GUIDE.md
sarahkoop Dec 18, 2023
397a941
Merge branch 'v5' into google_pay_single_result
sarahkoop Dec 18, 2023
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
Prev Previous commit
Next Next commit
Implement GooglePayPaymentAuthRequest result
sarahkoop committed Dec 5, 2023
commit ac1c9d2e92a2e35f6d14a4242a58c6b11408a818
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ public void launchGooglePay(View v) {
.build());

googlePayClient.createPaymentAuthRequest(googlePayRequest,
(paymentAuthRequest, error) -> googlePayLauncher.launch(paymentAuthRequest));
(paymentAuthRequest) -> googlePayLauncher.launch(paymentAuthRequest));
}

private void handleGooglePayActivityResult(PaymentMethodNonce paymentMethodNonce) {
Original file line number Diff line number Diff line change
@@ -181,39 +181,38 @@ public void createPaymentAuthRequest(@NonNull final GooglePayRequest request,
braintreeClient.sendAnalyticsEvent("google-payment.selected");

if (!validateManifest()) {
callback.onResult(null, new BraintreeException(
"GooglePayActivity was " + "not found in the " + "Android " +
"manifest, or did not have a theme of R.style.bt_transparent_activity"));
callback.onGooglePayPaymentAuthRequest(new GooglePayPaymentAuthRequest.Failure(new BraintreeException(
"GooglePayActivity was not found in the Android " +
"manifest, or did not have a theme of R.style.bt_transparent_activity")));
Copy link
Contributor

Choose a reason for hiding this comment

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

this is oddly specific heh. No action, just commenting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah... it is getting pretty verbose open to alternative callback naming! The previous pattern was always naming it onResult which is a little confusing when the result we are returning is actually a request object

braintreeClient.sendAnalyticsEvent("google-payment.failed");
return;
}

//noinspection ConstantConditions
if (request == null) {
callback.onResult(null, new BraintreeException(
"Cannot pass null " + "GooglePayRequest to " + "requestPayment"));
callback.onGooglePayPaymentAuthRequest(new GooglePayPaymentAuthRequest.Failure(new BraintreeException(
"Cannot pass null GooglePayRequest to requestPayment")));
braintreeClient.sendAnalyticsEvent("google-payment.failed");
return;
}

if (request.getTransactionInfo() == null) {
callback.onResult(null, new BraintreeException(
"Cannot pass null " + "TransactionInfo to" + " requestPayment"));
callback.onGooglePayPaymentAuthRequest(new GooglePayPaymentAuthRequest.Failure(new BraintreeException(
"Cannot pass null TransactionInfo to requestPayment")));
braintreeClient.sendAnalyticsEvent("google-payment.failed");
return;
}

braintreeClient.getConfiguration((configuration, configError) -> {
if (configuration == null) {
callback.onResult(null, configError);
if (configuration == null && configError != null) {
callback.onGooglePayPaymentAuthRequest(new GooglePayPaymentAuthRequest.Failure(configError));
return;
}

if (!configuration.isGooglePayEnabled()) {
callback.onResult(null, new BraintreeException(
"Google Pay " +
"is not enabled for your Braintree account," +
" or Google Play Services are not configured correctly."));
callback.onGooglePayPaymentAuthRequest(new GooglePayPaymentAuthRequest.Failure(new BraintreeException(
"Google Pay is not enabled for your Braintree account," +
" or Google Play Services are not configured correctly.")));
return;
}

@@ -223,10 +222,10 @@ public void createPaymentAuthRequest(@NonNull final GooglePayRequest request,
PaymentDataRequest paymentDataRequest =
PaymentDataRequest.fromJson(request.toJson());

GooglePayPaymentAuthRequestParams intent =
GooglePayPaymentAuthRequestParams params =
new GooglePayPaymentAuthRequestParams(getGooglePayEnvironment(configuration),
paymentDataRequest);
callback.onResult(intent, null);
callback.onGooglePayPaymentAuthRequest(new GooglePayPaymentAuthRequest.ReadyToLaunch(params));

});

Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.braintreepayments.api;

import androidx.annotation.Nullable;

/**
* Callback to handle result from
* {@link GooglePayClient#createPaymentAuthRequest(GooglePayRequest, GooglePayPaymentAuthRequestCallback)}
*/
public interface GooglePayPaymentAuthRequestCallback {

void onResult(@Nullable GooglePayPaymentAuthRequestParams paymentAuthRequest,
@Nullable Exception error);
void onGooglePayPaymentAuthRequest(GooglePayPaymentAuthRequest paymentAuthRequest);
}
Original file line number Diff line number Diff line change
@@ -228,7 +228,7 @@ public void createPaymentAuthRequest_callsBackIntentData() throws JSONException

ArgumentCaptor<GooglePayPaymentAuthRequestParams> captor = ArgumentCaptor.forClass(
GooglePayPaymentAuthRequestParams.class);
verify(intentDataCallback).onResult(captor.capture(), isNull());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(captor.capture());

GooglePayPaymentAuthRequestParams intent = captor.getValue();

@@ -350,7 +350,7 @@ public void createPaymentAuthRequest_includesATokenizationKeyWhenPresent() throw

ArgumentCaptor<GooglePayPaymentAuthRequestParams> captor = ArgumentCaptor.forClass(
GooglePayPaymentAuthRequestParams.class);
verify(intentDataCallback).onResult(captor.capture(), isNull());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(captor.capture());
GooglePayPaymentAuthRequestParams intent = captor.getValue();

PaymentDataRequest paymentDataRequest = intent.getPaymentDataRequest();
@@ -398,7 +398,7 @@ public void createPaymentAuthRequest_doesNotIncludeATokenizationKeyWhenNotPresen

ArgumentCaptor<GooglePayPaymentAuthRequestParams> captor = ArgumentCaptor.forClass(
GooglePayPaymentAuthRequestParams.class);
verify(intentDataCallback).onResult(captor.capture(), isNull());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(captor.capture());
GooglePayPaymentAuthRequestParams intent = captor.getValue();

PaymentDataRequest paymentDataRequest = intent.getPaymentDataRequest();
@@ -497,7 +497,7 @@ public void createPaymentAuthRequest_whenMerchantNotConfigured_returnsExceptionT

ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(
Exception.class);
verify(intentDataCallback).onResult(isNull(), captor.capture());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(isNull());

assertTrue(captor.getValue() instanceof BraintreeException);
assertEquals(
@@ -531,7 +531,7 @@ public void createPaymentAuthRequest_whenSandbox_setsTestEnvironment() throws JS

ArgumentCaptor<GooglePayPaymentAuthRequestParams> captor = ArgumentCaptor.forClass(
GooglePayPaymentAuthRequestParams.class);
verify(intentDataCallback).onResult(captor.capture(), isNull());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(captor.capture());
GooglePayPaymentAuthRequestParams intent = captor.getValue();

PaymentDataRequest paymentDataRequest = intent.getPaymentDataRequest();
@@ -567,7 +567,7 @@ public void createPaymentAuthRequest_whenProduction_setsProductionEnvironment()

ArgumentCaptor<GooglePayPaymentAuthRequestParams> captor = ArgumentCaptor.forClass(
GooglePayPaymentAuthRequestParams.class);
verify(intentDataCallback).onResult(captor.capture(), isNull());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(captor.capture());
GooglePayPaymentAuthRequestParams intent = captor.getValue();

PaymentDataRequest paymentDataRequest = intent.getPaymentDataRequest();
@@ -606,7 +606,7 @@ public void createPaymentAuthRequest_withGoogleMerchantName_sendGoogleMerchantNa

ArgumentCaptor<GooglePayPaymentAuthRequestParams> captor = ArgumentCaptor.forClass(
GooglePayPaymentAuthRequestParams.class);
verify(intentDataCallback).onResult(captor.capture(), isNull());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(captor.capture());
GooglePayPaymentAuthRequestParams intent = captor.getValue();

PaymentDataRequest paymentDataRequest = intent.getPaymentDataRequest();
@@ -647,7 +647,7 @@ public void createPaymentAuthRequest_whenGooglePayCanProcessPayPal_tokenizationP

ArgumentCaptor<GooglePayPaymentAuthRequestParams> captor = ArgumentCaptor.forClass(
GooglePayPaymentAuthRequestParams.class);
verify(intentDataCallback).onResult(captor.capture(), isNull());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(captor.capture());
GooglePayPaymentAuthRequestParams intent = captor.getValue();

PaymentDataRequest paymentDataRequest = intent.getPaymentDataRequest();
@@ -693,7 +693,7 @@ public void createPaymentAuthRequest_whenPayPalDisabledByRequest_tokenizationPro

ArgumentCaptor<GooglePayPaymentAuthRequestParams> captor = ArgumentCaptor.forClass(
GooglePayPaymentAuthRequestParams.class);
verify(intentDataCallback).onResult(captor.capture(), isNull());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(captor.capture());
GooglePayPaymentAuthRequestParams intent = captor.getValue();

PaymentDataRequest paymentDataRequest = intent.getPaymentDataRequest();
@@ -739,7 +739,7 @@ public void createPaymentAuthRequest_whenPayPalDisabledInConfigurationAndGoogleP

ArgumentCaptor<GooglePayPaymentAuthRequestParams> captor = ArgumentCaptor.forClass(
GooglePayPaymentAuthRequestParams.class);
verify(intentDataCallback).onResult(captor.capture(), isNull());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(captor.capture());
GooglePayPaymentAuthRequestParams intent = captor.getValue();

PaymentDataRequest paymentDataRequest = intent.getPaymentDataRequest();
@@ -786,7 +786,7 @@ public void createPaymentAuthRequest_usesGooglePayConfigurationClientId() throws

ArgumentCaptor<GooglePayPaymentAuthRequestParams> captor = ArgumentCaptor.forClass(
GooglePayPaymentAuthRequestParams.class);
verify(intentDataCallback).onResult(captor.capture(), isNull());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(captor.capture());
GooglePayPaymentAuthRequestParams intent = captor.getValue();

PaymentDataRequest paymentDataRequest = intent.getPaymentDataRequest();
@@ -840,7 +840,7 @@ public void createPaymentAuthRequest_whenGooglePayConfigurationLacksClientId_tok

ArgumentCaptor<GooglePayPaymentAuthRequestParams> captor = ArgumentCaptor.forClass(
GooglePayPaymentAuthRequestParams.class);
verify(intentDataCallback).onResult(captor.capture(), isNull());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(captor.capture());
GooglePayPaymentAuthRequestParams intent = captor.getValue();

PaymentDataRequest paymentDataRequest = intent.getPaymentDataRequest();
@@ -886,7 +886,7 @@ public void createPaymentAuthRequest_whenConfigurationContainsElo_addsEloAndEloD

ArgumentCaptor<GooglePayPaymentAuthRequestParams> captor = ArgumentCaptor.forClass(
GooglePayPaymentAuthRequestParams.class);
verify(intentDataCallback).onResult(captor.capture(), isNull());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(captor.capture());
GooglePayPaymentAuthRequestParams intent = captor.getValue();

PaymentDataRequest paymentDataRequest = intent.getPaymentDataRequest();
@@ -929,7 +929,7 @@ public void createPaymentAuthRequest_whenRequestIsNull_forwardsExceptionToListen

ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(
Exception.class);
verify(intentDataCallback).onResult(isNull(), captor.capture());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(isNull());

Exception exception = captor.getValue();
assertTrue(exception instanceof BraintreeException);
@@ -962,7 +962,7 @@ public void createPaymentAuthRequest_whenManifestInvalid_forwardsExceptionToList

ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(
Exception.class);
verify(intentDataCallback).onResult(isNull(), captor.capture());
verify(intentDataCallback).onGooglePayPaymentAuthRequest(isNull());

Exception exception = captor.getValue();
assertTrue(exception instanceof BraintreeException);