From 039571a923b4d1f749344681e29fa594da495f5d Mon Sep 17 00:00:00 2001 From: Sammy Cannillo Date: Tue, 31 Oct 2023 14:18:16 -0500 Subject: [PATCH] Cleanup --- .../demo/SEPADirectDebitFragment.java | 5 --- .../SEPADirectDebitBrowserSwitchResult.java | 9 +++- ...irectDebitBrowserSwitchResultCallback.java | 2 +- .../api/SEPADirectDebitClient.java | 6 ++- .../api/SEPADirectDebitLifecycleObserver.java | 42 ------------------- .../api/SEPADirectDebitListener.java | 21 ---------- .../api/SEPADirectDebitResponse.java | 8 ++++ .../api/SEPADirectDebitTokenizeCallback.java | 1 - v5_MIGRATION_GUIDE.md | 1 - 9 files changed, 20 insertions(+), 75 deletions(-) delete mode 100644 SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitLifecycleObserver.java delete mode 100644 SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitListener.java diff --git a/Demo/src/main/java/com/braintreepayments/demo/SEPADirectDebitFragment.java b/Demo/src/main/java/com/braintreepayments/demo/SEPADirectDebitFragment.java index 60b8096741..e4eebd6e45 100644 --- a/Demo/src/main/java/com/braintreepayments/demo/SEPADirectDebitFragment.java +++ b/Demo/src/main/java/com/braintreepayments/demo/SEPADirectDebitFragment.java @@ -7,22 +7,17 @@ import android.widget.Button; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.navigation.fragment.NavHostFragment; import com.braintreepayments.api.BraintreeClient; import com.braintreepayments.api.PostalAddress; import com.braintreepayments.api.SEPADirectDebitBrowserSwitchResult; -import com.braintreepayments.api.SEPADirectDebitBrowserSwitchResultCallback; import com.braintreepayments.api.SEPADirectDebitClient; -import com.braintreepayments.api.SEPADirectDebitFlowStartedCallback; import com.braintreepayments.api.SEPADirectDebitLauncher; import com.braintreepayments.api.SEPADirectDebitLauncherCallback; -import com.braintreepayments.api.SEPADirectDebitListener; import com.braintreepayments.api.SEPADirectDebitMandateType; import com.braintreepayments.api.SEPADirectDebitNonce; import com.braintreepayments.api.SEPADirectDebitRequest; -import com.braintreepayments.api.SEPADirectDebitResponse; import java.util.UUID; diff --git a/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitBrowserSwitchResult.java b/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitBrowserSwitchResult.java index 51dc0c689c..c7872ef69c 100644 --- a/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitBrowserSwitchResult.java +++ b/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitBrowserSwitchResult.java @@ -1,6 +1,11 @@ package com.braintreepayments.api; -// TODO: - Docstring +/** + * Result received from the SEPA mandate web flow through {@link SEPADirectDebitBrowserSwitchResultCallback}. + * This result should be passed to + * {@link SEPADirectDebitClient#onBrowserSwitchResult(SEPADirectDebitBrowserSwitchResult, SEPADirectDebitBrowserSwitchResultCallback)} )} + * to complete the SEPA mandate flow. + */ public class SEPADirectDebitBrowserSwitchResult { private BrowserSwitchResult browserSwitchResult; @@ -21,4 +26,4 @@ BrowserSwitchResult getBrowserSwitchResult() { Exception getError() { return error; } -} \ No newline at end of file +} diff --git a/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitBrowserSwitchResultCallback.java b/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitBrowserSwitchResultCallback.java index 71bbbde72f..e56a65a48d 100644 --- a/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitBrowserSwitchResultCallback.java +++ b/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitBrowserSwitchResultCallback.java @@ -10,7 +10,7 @@ public interface SEPADirectDebitBrowserSwitchResultCallback { /** * @param sepaDirectDebitNonce {@link SEPADirectDebitNonce} - * @param error an exception that occurred while processing a PayPal result + * @param error an exception that occurred while processing a PayPal result */ void onResult(@Nullable SEPADirectDebitNonce sepaDirectDebitNonce, @Nullable Exception error); } diff --git a/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitClient.java b/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitClient.java index 4b92eb3ae0..4abb1b6042 100644 --- a/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitClient.java +++ b/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitClient.java @@ -65,7 +65,8 @@ public void tokenize(@NonNull final FragmentActivity activity, braintreeClient.sendAnalyticsEvent( "sepa-direct-debit.create-mandate.success"); try { - SEPADirectDebitResponse sepaDirectDebitResponse = new SEPADirectDebitResponse(buildBrowserSwitchOptions(result), null); + SEPADirectDebitResponse sepaDirectDebitResponse = + new SEPADirectDebitResponse(buildBrowserSwitchOptions(result), null); callback.onResult(sepaDirectDebitResponse, null); } catch (JSONException exception) { braintreeClient.sendAnalyticsEvent( @@ -85,7 +86,8 @@ public void tokenize(@NonNull final FragmentActivity activity, if (sepaDirectDebitNonce != null) { braintreeClient.sendAnalyticsEvent( "sepa-direct-debit.tokenize.success"); - SEPADirectDebitResponse sepaDirectDebitResponse = new SEPADirectDebitResponse(null, sepaDirectDebitNonce); + SEPADirectDebitResponse sepaDirectDebitResponse = + new SEPADirectDebitResponse(null, sepaDirectDebitNonce); callback.onResult(sepaDirectDebitResponse, null); } else if (tokenizeError != null) { braintreeClient.sendAnalyticsEvent( diff --git a/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitLifecycleObserver.java b/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitLifecycleObserver.java deleted file mode 100644 index ff3c14b74c..0000000000 --- a/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitLifecycleObserver.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.braintreepayments.api; - - -import static androidx.lifecycle.Lifecycle.Event.ON_RESUME; - -import androidx.annotation.NonNull; -import androidx.annotation.VisibleForTesting; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentActivity; -import androidx.lifecycle.Lifecycle; -import androidx.lifecycle.LifecycleEventObserver; -import androidx.lifecycle.LifecycleOwner; - -// NEXT_MAJOR_VERSION: Update to implement DefaultLifeCycleObserver when Java 7 support is explicitly dropped. -//class SEPADirectDebitLifecycleObserver implements LifecycleEventObserver { -// -// @VisibleForTesting -// SEPADirectDebitClient sepaDirectDebitClient; -// -// SEPADirectDebitLifecycleObserver(@NonNull SEPADirectDebitClient sepaDirectDebitClient) { -// this.sepaDirectDebitClient = sepaDirectDebitClient; -// } -// -// @Override -// public void onStateChanged(@NonNull LifecycleOwner lifecycleOwner, @NonNull Lifecycle.Event event) { -// if (event == ON_RESUME) { -// FragmentActivity activity = null; -// if (lifecycleOwner instanceof FragmentActivity) { -// activity = (FragmentActivity) lifecycleOwner; -// } else if (lifecycleOwner instanceof Fragment) { -// activity = ((Fragment) lifecycleOwner).getActivity(); -// } -// -// if (activity != null) { -// BrowserSwitchResult pendingResult = sepaDirectDebitClient.getBrowserSwitchResult(activity); -// if (pendingResult != null && pendingResult.getRequestCode() == BraintreeRequestCodes.SEPA_DEBIT) { -// sepaDirectDebitClient.onBrowserSwitchResult(activity); -// } -// } -// } -// } -//} diff --git a/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitListener.java b/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitListener.java deleted file mode 100644 index c44180c6f8..0000000000 --- a/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitListener.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.braintreepayments.api; - -import androidx.annotation.NonNull; - -/** - * Implement this interface to receive SEPA Direct Debit result notifications. - */ -public interface SEPADirectDebitListener { - - /** - * Called when SEPA Direct Debit tokenization is complete without error. - * @param sepaDirectDebitNonce SEPA Direct Debit tokenization result - */ - void onSEPADirectDebitSuccess(@NonNull SEPADirectDebitNonce sepaDirectDebitNonce); - - /** - * Called when SEPA Direct Debit tokenization has failed with an error. - * @param error explains reason for SEPA Direct Debit failure. - */ - void onSEPADirectDebitFailure(@NonNull Exception error); -} diff --git a/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitResponse.java b/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitResponse.java index 9938f648c1..41d3ccfbf0 100644 --- a/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitResponse.java +++ b/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitResponse.java @@ -2,6 +2,14 @@ import androidx.fragment.app.FragmentActivity; +/** + * Returned via the {@link SEPADirectDebitFlowStartedCallback} after calling + * {@link SEPADirectDebitClient#tokenize(FragmentActivity, SEPADirectDebitRequest, SEPADirectDebitFlowStartedCallback)}. + * + * Inspect the {@link SEPADirectDebitNonce} property to determine if tokenization is complete, or + * if you must continue the SEPA mandate web flow via + * {@link SEPADirectDebitLauncher#launch(FragmentActivity, SEPADirectDebitResponse)} + */ public class SEPADirectDebitResponse { private BrowserSwitchOptions browserSwitchOptions; diff --git a/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitTokenizeCallback.java b/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitTokenizeCallback.java index 79b285d492..7ce2072a16 100644 --- a/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitTokenizeCallback.java +++ b/SEPADirectDebit/src/main/java/com/braintreepayments/api/SEPADirectDebitTokenizeCallback.java @@ -5,5 +5,4 @@ interface SEPADirectDebitTokenizeCallback { void onResult(@Nullable SEPADirectDebitNonce sepaDirectDebitNonce, @Nullable Exception error); - } diff --git a/v5_MIGRATION_GUIDE.md b/v5_MIGRATION_GUIDE.md index 0af26aef22..1c0b241e27 100644 --- a/v5_MIGRATION_GUIDE.md +++ b/v5_MIGRATION_GUIDE.md @@ -397,7 +397,6 @@ class MyActivity : FragmentActivity() { + intent) } - fun initializeClients() { braintreClient = BraintreeClient(context, "TOKENIZATION_KEY_OR_CLIENT_TOKEN") - sepaDirectDebitClient = SEPADirectDebitClient(this, braintreeClient)