Skip to content

Commit

Permalink
Merge pull request #106 from braintree/v3-into-main
Browse files Browse the repository at this point in the history
Merge v3 into main
  • Loading branch information
tdchow authored Jul 8, 2024
2 parents 7162f7b + 15358b5 commit 7430fd5
Show file tree
Hide file tree
Showing 44 changed files with 917 additions and 1,806 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup_java/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ runs:
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: zulu
1 change: 1 addition & 0 deletions .github/workflows/release_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- v3
env:
SIGNING_KEY_FILE: /home/runner/secretKey.gpg
jobs:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up Java 11
- name: Set up Java 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'microsoft'
- name: Lint
run: ./ci android_lint
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up Java 11
- name: Set up Java 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'zulu'
- name: Unit Tests
run: ./ci unit_tests
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# browser-switch-android Release Notes

## unreleased

* Make `BrowserSwitchClient.assertCanPerformBrowserSwitch()` public
* Breaking Changes
* Bump `minSdkVersion` to API 23
* Bump target Java version to Java 11
* Upgrade Kotlin version to 1.9.10
* Upgrade to Android Gradle Plugin 8
* Change `BrowserSwitchClient#start` parameters and return type
* Change `BrowserSwitchClient#parseResult` parameters
* Remove `deliverResult`, `getResult`, `captureResult`, `clearActiveRequests`, `getResultFromCache`, and `deliverResultFromCache` from `BrowserSwitchClient`
* Add `BrowserSwitchRequest` and `BrowserSwitchPendingRequest`
* Convert `BrowserSwitchResult` to sealed class and add `BrowserSwitchResultInfo`
* Remove `BrowserSwitchStatus`
* Rename `parseResult()` to `completeRequest()`

## 2.7.0

* Add `appLinkUri` to `BrowserSwitchOptions` for Android App Link support
Expand Down
59 changes: 36 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ To preview the latest work in progress builds, add the following SNAPSHOT depend

```groovy
dependencies {
implementation 'com.braintreepayments.api:browser-switch:2.7.1-SNAPSHOT'
implementation 'com.braintreepayments.api:browser-switch:3.0.0-beta1-SNAPSHOT'
}
```

Expand All @@ -42,7 +42,6 @@ Declare an activity that you own as a deep link target in your `AndroidManifest.

```xml
<activity android:name="com.myapp.MyDeepLinkTargetActivity"
android:launchMode="singleTask"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
Expand All @@ -62,29 +61,42 @@ If these requirements are not met, an error will be returned and no browser swit
A browser switch can be initiated by calling `BrowserSwitchClient#start()`. Use `BrowserSwitchOptions` to configure options for browser switching:

```kotlin
val browserSwitchOptions = BrowserSwitchOptions()
.requestCode(MY_REQUEST_CODE)
.url("https://site-to-load.com?callbackURL=my-custom-url-scheme%3A%2F%2Fsuccess")
.returnUrlScheme("my-custom-url-scheme")
browserSwitchClient.start(activity, browserSwitchOptions)
val browserSwitchOptions = BrowserSwitchOptions().apply {
requestCode = MY_REQUEST_CODE
url = "https://site-to-load.com?callbackURL=my-custom-url-scheme%3A%2F%2Fsuccess"
returnUrlScheme = "my-custom-url-scheme"
}

when (val pendingRequest = browserSwitchClient.start(this, browserSwitchOptions)) {
is BrowserSwitchPendingRequest.Started -> {
// store pending request
}
is BrowserSwitchPendingRequest.Failure -> {
// browser was unable to be launched, handle failure
}
}
```

In the above example, notice the encoded `callbackURL` parameter is forwarded to the website that will be loaded. The callback url must have the same custom scheme set in `BrowserSwitchOptions`. When this URL is loaded by the site, the Android OS will re-direct the user to the deep link destination `Activity` defined in the `AndroidManifest.xml`.

To capture a browser switch result, override your deep link target `Activity` with the following code snippet:

```kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
browserSwitchClient.deliverResult(this)?.let { result ->
when (result) {
BrowserSwitchStatus.OK -> {
// the browser switch returned data in the return uri
// TODO: handle success
override fun onResume() {
handleReturnToAppFromBrowser(intent)
}

fun handleReturnToAppFromBrowser(intent: Intent) {
// fetch stored pending request
fetchPendingRequestFromPersistentStorage()?.let { startedRequest ->
when (val browserSwitchResult = browserSwitchClient.parseResult(startedRequest, intent)) {
is BrowserSwitchResult.Success -> {
// handle successful browser switch result
// clear stored pending request
}
BrowserSwitchStatus.CANCEL -> {
// the user canceled and returned to your app return uri is null
// TODO: handle cancelation
is BrowserSwitchResult.NoResult -> {
// user did not complete browser switch
// allow user to complete browser switch, or clear stored pending request
}
}
}
Expand All @@ -93,23 +105,24 @@ override fun onCreate(savedInstanceState: Bundle?) {

## Launch Modes

If your deep link target `Activity` has `android:launchMode="singleTop"`, `android:launchMode="singleTask"`, or `android:launchMode="singleInstance"`, add the following code snippet to your deep link target `Activity`:
If your deep link target `Activity` has `android:launchMode="singleTop"`, `android:launchMode="singleTask"`, or `android:launchMode="singleInstance"`, add the following code snippet to your deep link target `Activity` in the `onNewIntent` method instead of `onResume`:

```kotlin
override fun onNewIntent(newIntent: Intent?) {
super.onNewIntent(intent)
intent = newIntent
handleReturnToAppFromBrowser(intent)
}
```

## Versions

This SDK abides by our Client SDK Deprecation Policy. For more information on the potential statuses of an SDK check our [developer docs](https://developer.paypal.com/braintree/docs/guides/client-sdk/deprecation-policy/android/v4).

| Major version number | Status | Released | Deprecated | Unsupported |
| -------------------- | ------ | -------- | ---------- | ----------- |
| 2.x.x | Active | February 2021 | TBA | TBA |
| 1.x.x | Inactive | June 2020 | April 2022 | April 2023 |
| Major version number | Status | Released | Deprecated | Unsupported |
|----------------------|----------|---------------| ---------- | ----------- |
| 3.x.x | Beta | TBA | TBA | TBA |
| 2.x.x | Active | February 2021 | TBA | TBA |
| 1.x.x | Inactive | June 2020 | April 2022 | April 2023 |

## Help

Expand Down
10 changes: 7 additions & 3 deletions browser-switch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ plugins {
}

android {
compileSdkVersion rootProject.compileSdkVersion
namespace "com.braintreepayments.api.browserswitch"
compileSdk rootProject.compileSdkVersion

defaultConfig {
minSdkVersion rootProject.minSdkVersion
Expand All @@ -15,8 +16,11 @@ android {
}

compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility versions.javaSourceCompatibility
targetCompatibility versions.javaTargetCompatibility
}
kotlinOptions {
jvmTarget = "11"
}

// robolectric
Expand Down
3 changes: 1 addition & 2 deletions browser-switch/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.braintreepayments.api.browserswitch">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<queries>
<intent>
Expand Down
Loading

0 comments on commit 7430fd5

Please sign in to comment.