Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 1 addition & 8 deletions platforms/android/lib/api/lib.api
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,6 @@ public final class com/shopify/checkoutkit/Checkout$Companion {
}

public abstract interface class com/shopify/checkoutkit/CheckoutCommunicationClient {
public abstract fun openExternalUrl (Landroid/net/Uri;)Z
public abstract fun process (Ljava/lang/String;)Ljava/lang/String;
}

Expand Down Expand Up @@ -669,7 +668,6 @@ public abstract interface class com/shopify/checkoutkit/CheckoutEventProcessor {
public abstract fun onCheckoutCanceled ()V
public abstract fun onCheckoutCompleted (Lcom/shopify/checkoutkit/lifecycleevents/CheckoutCompletedEvent;)V
public abstract fun onCheckoutFailed (Lcom/shopify/checkoutkit/CheckoutException;)V
public abstract fun onCheckoutLinkClicked (Landroid/net/Uri;)V
public abstract fun onGeolocationPermissionsHidePrompt ()V
public abstract fun onGeolocationPermissionsShowPrompt (Ljava/lang/String;Landroid/webkit/GeolocationPermissions$Callback;)V
public abstract fun onPermissionRequest (Landroid/webkit/PermissionRequest;)V
Expand Down Expand Up @@ -773,8 +771,6 @@ public final class com/shopify/checkoutkit/CheckoutProtocol {
public final class com/shopify/checkoutkit/CheckoutProtocol$Client : com/shopify/checkoutkit/CheckoutCommunicationClient {
public fun <init> ()V
public final fun on (Lcom/shopify/checkoutkit/NotificationDescriptor;Lkotlin/jvm/functions/Function1;)Lcom/shopify/checkoutkit/CheckoutProtocol$Client;
public final fun onOpenExternalUrl (Lkotlin/jvm/functions/Function1;)Lcom/shopify/checkoutkit/CheckoutProtocol$Client;
public fun openExternalUrl (Landroid/net/Uri;)Z
public fun process (Ljava/lang/String;)Ljava/lang/String;
}

Expand Down Expand Up @@ -1368,10 +1364,7 @@ public final class com/shopify/checkoutkit/CredentialResult$Companion {
}

public abstract class com/shopify/checkoutkit/DefaultCheckoutEventProcessor : com/shopify/checkoutkit/CheckoutEventProcessor {
public fun <init> (Landroid/content/Context;)V
public fun <init> (Landroid/content/Context;Lcom/shopify/checkoutkit/LogWrapper;)V
public synthetic fun <init> (Landroid/content/Context;Lcom/shopify/checkoutkit/LogWrapper;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun onCheckoutLinkClicked (Landroid/net/Uri;)V
public fun <init> ()V
public fun onGeolocationPermissionsHidePrompt ()V
public fun onGeolocationPermissionsShowPrompt (Ljava/lang/String;Landroid/webkit/GeolocationPermissions$Callback;)V
public fun onPermissionRequest (Landroid/webkit/PermissionRequest;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*/
package com.shopify.checkoutkit

import android.net.Uri

/**
* Implement this interface to handle Embedded Checkout Protocol (ECP) messages beyond
* the built-in methods handled natively by the SDK.
Expand All @@ -34,20 +32,14 @@ public interface CheckoutCommunicationClient {
/**
* Process a JSON-RPC 2.0 ECP message from the checkout web page.
*
* Called for all EC notifications (ec.start, ec.error, ec.complete, ec.*.change)
* and any unknown methods. For requests, return a JSON-RPC 2.0 response string;
* for notifications, return null (no response is sent).
* Called for EC notifications (ec.start, ec.error, ec.complete, ec.*.change) and
* any unknown methods the kit doesn't handle natively. Delegations such as
* `ec.window.open_request` are handled internally by the kit and are not forwarded
* here. For requests, return a JSON-RPC 2.0 response string; for notifications,
* return null (no response is sent).
*
* @param message JSON-RPC 2.0 encoded message string
* @return JSON-RPC 2.0 encoded response string, or null to send no response
*/
public fun process(message: String): String?

/**
* Called when checkout requests that a URL be opened externally (ec.window.open_request).
*
* @param url the URL checkout wants opened in an external browser or app
* @return true if the URL was handled and displayed externally, false otherwise
*/
public fun openExternalUrl(url: Uri): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
*/
package com.shopify.checkoutkit

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.webkit.GeolocationPermissions
import android.webkit.PermissionRequest
Expand Down Expand Up @@ -57,12 +54,6 @@ public interface CheckoutEventProcessor {
*/
public fun onCheckoutCanceled()

/**
* Event indicating that a link has been clicked within checkout that should be opened outside
* of the WebView, e.g. in a system browser or email client. Protocols can be http/https/mailto/tel
*/
public fun onCheckoutLinkClicked(uri: Uri)

/**
* A permission has been requested by the web chrome client, e.g. to access the camera
*/
Expand Down Expand Up @@ -103,10 +94,6 @@ internal class NoopEventProcessor : CheckoutEventProcessor {
/* noop */
}

override fun onCheckoutLinkClicked(uri: Uri) {
/* noop */
}

override fun onShowFileChooser(
webView: WebView,
filePathCallback: ValueCallback<Array<Uri>>,
Expand All @@ -130,22 +117,9 @@ internal class NoopEventProcessor : CheckoutEventProcessor {

/**
* An abstract class that provides a default implementation of the CheckoutEventProcessor interface
* for handling checkout events and interacting with the Android operating system.
* @param context from which we will launch intents.
* for the optional permission and file-chooser callbacks. Override in subclasses as needed.
*/
public abstract class DefaultCheckoutEventProcessor @JvmOverloads constructor(
private val context: Context,
private val log: LogWrapper = LogWrapper(),
) : CheckoutEventProcessor {

override fun onCheckoutLinkClicked(uri: Uri) {
when (uri.scheme) {
"tel" -> context.launchPhoneApp(uri.schemeSpecificPart)
"mailto" -> context.launchEmailApp(uri.schemeSpecificPart)
"https", "http" -> context.launchBrowser(uri)
else -> context.tryLaunchDeepLink(uri)
}
}
public abstract class DefaultCheckoutEventProcessor : CheckoutEventProcessor {

override fun onPermissionRequest(permissionRequest: PermissionRequest) {
// no-op override to implement
Expand All @@ -166,42 +140,4 @@ public abstract class DefaultCheckoutEventProcessor @JvmOverloads constructor(
override fun onGeolocationPermissionsHidePrompt() {
// no-op override to implement
}

private fun Context.launchEmailApp(to: String) {
log.d(LOG_TAG, "Attempting to launch email app.")
val intent = Intent(Intent.ACTION_SEND)
intent.type = "vnd.android.cursor.item/email"
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf(to))
startActivity(intent)
}

private fun Context.launchBrowser(uri: Uri) {
log.d(LOG_TAG, "Attempting to launch browser for $uri.")
val intent = Intent(Intent.ACTION_VIEW)
intent.data = uri
startActivity(intent)
}

private fun Context.launchPhoneApp(phone: String) {
log.d(LOG_TAG, "Attempting to launch phone app.")
val intent = Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", phone, null))
startActivity(intent)
}

@SuppressLint("QueryPermissionsNeeded")
private fun Context.tryLaunchDeepLink(uri: Uri) {
log.d(LOG_TAG, "Attempting to launch deep link for uri $uri.")
val intent = Intent(Intent.ACTION_VIEW)
intent.data = uri
if (context.packageManager.queryIntentActivities(intent, 0).isNotEmpty()) {
startActivity(intent)
} else {
log.w(TAG, "Unrecognized scheme for link clicked in checkout '$uri'")
}
}

private companion object {
private const val LOG_TAG = "DefaultCheckoutEventProcessor"
private const val TAG = "DefaultCheckoutEventProcessor"
}
}
Loading
Loading