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

PayPal Launcher API #807

Merged
merged 45 commits into from
Oct 25, 2023
Merged

PayPal Launcher API #807

merged 45 commits into from
Oct 25, 2023

Conversation

sarahkoop
Copy link
Contributor

Summary of changes

  • Add PayPal launcher API (this is slightly different than the previous two launcher API PRs because this is a web based flow rather than an activity based flow)
  • Note: Method/callback/result object names have not been updated to keep this PR diff smaller while we determine the best naming convention to follow throughout modules

Checklist

  • Added a changelog entry

Authors

@sarahkoop sarahkoop requested a review from a team as a code owner October 13, 2023 20:12
* @throws BrowserSwitchException if there is an error launching the PayPal web flow
*/
public void launch(@NonNull FragmentActivity activity, @NonNull PayPalResponse payPalResponse)
throws BrowserSwitchException {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this throw or how should this exception be handled? The Activity result based launch methods (Google Pay, Venmo) don't throw or callback any exception, so I opted to throw to keep the launch parameters cleaner. This does mean a try/catch block in the merchant code (see migration guide example). Other alternative would be to callback an error in this method, or give the PayPalLauncher a callback in the constructor to handle results (this would align with the Activity based launchers)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah we should design it to have the same API as the Activity launchers if possible. It'd be awesome if we're able to offer a familiar DX for onboarding each Activity and Browser-based payment flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok updated this so that the launcher constructor takes a callback as a parameter (to align with Activity Result flows) and if there's an error in the launch method, that error will be delivered to the callback from the constructor.

*/
public BrowserSwitchResult deliverResult(@NonNull Context context, @NonNull Intent intent) {
BrowserSwitchResult result = browserSwitchClient.parseResult(context, PAYPAL, intent);
browserSwitchClient.clearActiveRequests(context);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sshropshire Can clearActiveRequests be called under the hood here or do we need to give the merchants an accessor to call this themselves after handling the result?

Copy link
Contributor

Choose a reason for hiding this comment

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

For this one I'm 50/50. We could call it for merchants, but run the risk of using too much abstraction. I'm in favor of having merchants call launcher.clearActiveRequests() (doesn't have to be the same name). A better solution may be to revisit the acceptance criteria for browser switching to make sure we have it right.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok agreed for now I am going to keep it under the hood because I think it should always be called immediately after a successful parse, but created a ticket to revisit this pattern before GA

Comment on lines +16 to +22
BrowserSwitchResult getBrowserSwitchResult() {
return browserSwitchResult;
}

Exception getError() {
return error;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these need to be public w/ docstrings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No the idea with this result object is that the merchant doesn't have to do anything with it / be aware of any params and just passes it directly to the PayPalClient#onBrowserSwitchResult method, which will then handle any errors and call them back to the merchant. We could break it up and allow merchants to handle errors at each step, but this seems cleaner for integrations

v5_MIGRATION_GUIDE.md Outdated Show resolved Hide resolved
@sarahkoop sarahkoop mentioned this pull request Oct 24, 2023
1 task
CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: scannillo <[email protected]>
@sarahkoop sarahkoop merged commit 43eda0d into v5 Oct 25, 2023
2 checks passed
@sarahkoop sarahkoop deleted the paypal_launcher_api branch October 25, 2023 14:13
@scannillo scannillo mentioned this pull request Oct 31, 2023
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants