Skip to content
Open
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
262 changes: 81 additions & 181 deletions platforms/android/README.md

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions platforms/android/lib/api/lib.api
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,16 @@ public final class com/shopify/checkoutkit/CheckoutLineItem$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class com/shopify/checkoutkit/CheckoutPresentation {
public final fun connect (Lcom/shopify/checkoutkit/CheckoutCommunicationClient;)V
public final fun onCancel (Lkotlin/jvm/functions/Function0;)V
public final fun onFail (Lkotlin/jvm/functions/Function1;)V
public final fun onGeolocationPermissionsHidePrompt (Lkotlin/jvm/functions/Function0;)V
public final fun onGeolocationPermissionsShowPrompt (Lkotlin/jvm/functions/Function2;)V
public final fun onPermissionRequest (Lkotlin/jvm/functions/Function1;)V
public final fun onShowFileChooser (Lkotlin/jvm/functions/Function3;)V
}

public final class com/shopify/checkoutkit/CheckoutProtocol {
public static final field INSTANCE Lcom/shopify/checkoutkit/CheckoutProtocol;
public static final field specVersion Ljava/lang/String;
Expand Down Expand Up @@ -3927,6 +3937,7 @@ public final class com/shopify/checkoutkit/ShopifyCheckoutKit {
public static final fun preload (Ljava/lang/String;Landroidx/activity/ComponentActivity;)V
public static final fun present (Ljava/lang/String;Landroidx/activity/ComponentActivity;Lcom/shopify/checkoutkit/DefaultCheckoutEventProcessor;)Lcom/shopify/checkoutkit/CheckoutKitDialog;
public static final fun present (Ljava/lang/String;Landroidx/activity/ComponentActivity;Lcom/shopify/checkoutkit/DefaultCheckoutEventProcessor;Lcom/shopify/checkoutkit/CheckoutCommunicationClient;)Lcom/shopify/checkoutkit/CheckoutKitDialog;
public static final synthetic fun present (Ljava/lang/String;Landroidx/activity/ComponentActivity;Lkotlin/jvm/functions/Function1;)Lcom/shopify/checkoutkit/CheckoutKitDialog;
public static synthetic fun present$default (Ljava/lang/String;Landroidx/activity/ComponentActivity;Lcom/shopify/checkoutkit/DefaultCheckoutEventProcessor;Lcom/shopify/checkoutkit/CheckoutCommunicationClient;ILjava/lang/Object;)Lcom/shopify/checkoutkit/CheckoutKitDialog;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* MIT License
*
* Copyright 2023-present, Shopify Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.shopify.checkoutkit

import android.net.Uri
import android.webkit.GeolocationPermissions
import android.webkit.PermissionRequest
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
import android.webkit.WebView
import com.shopify.checkoutkit.lifecycleevents.CheckoutCompletedEvent

/**
* Kotlin-first builder for per-presentation checkout callbacks.
*
* Use through [ShopifyCheckoutKit.present].
*/
public class CheckoutPresentation internal constructor() {
internal var onFail: ((CheckoutException) -> Unit)? = null
internal var onCancel: (() -> Unit)? = null
internal var onPermissionRequest: ((PermissionRequest) -> Unit)? = null
internal var onShowFileChooser:
((WebView, ValueCallback<Array<Uri>>, WebChromeClient.FileChooserParams) -> Boolean)? = null
internal var onGeolocationPermissionsShowPrompt:
((String, GeolocationPermissions.Callback) -> Unit)? = null
internal var onGeolocationPermissionsHidePrompt: (() -> Unit)? = null
internal var communicationClient: CheckoutCommunicationClient? = null

/**
* Called when checkout fails.
*/
public fun onFail(handler: (CheckoutException) -> Unit) {
onFail = handler
}

/**
* Called when checkout is canceled by the buyer.
*/
public fun onCancel(handler: () -> Unit) {
onCancel = handler
}

/**
* Called when checkout requests a web permission, such as camera access.
*/
public fun onPermissionRequest(handler: (PermissionRequest) -> Unit) {
onPermissionRequest = handler
}

/**
* Called when checkout requests that the host app present a file chooser.
*/
public fun onShowFileChooser(
handler: (
webView: WebView,
filePathCallback: ValueCallback<Array<Uri>>,
fileChooserParams: WebChromeClient.FileChooserParams,
) -> Boolean,
) {
onShowFileChooser = handler
}

/**
* Called when checkout requests that the host app present a geolocation prompt.
*/
public fun onGeolocationPermissionsShowPrompt(
handler: (origin: String, callback: GeolocationPermissions.Callback) -> Unit,
) {
onGeolocationPermissionsShowPrompt = handler
}

/**
* Called when checkout requests that any visible geolocation prompt be dismissed.
*/
public fun onGeolocationPermissionsHidePrompt(handler: () -> Unit) {
onGeolocationPermissionsHidePrompt = handler
}

/**
* Connects a communication client for Embedded Checkout Protocol messages.
*/
public fun connect(client: CheckoutCommunicationClient?) {
communicationClient = client
}

internal fun buildEventProcessor(): DefaultCheckoutEventProcessor =
object : DefaultCheckoutEventProcessor() {
override fun onCheckoutCompleted(checkoutCompletedEvent: CheckoutCompletedEvent) = Unit
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This callback can be dropped here now right?


override fun onCheckoutFailed(error: CheckoutException) {
onFail?.invoke(error)
}

override fun onCheckoutCanceled() {
onCancel?.invoke()
}

override fun onPermissionRequest(permissionRequest: PermissionRequest) {
onPermissionRequest?.invoke(permissionRequest)
}

override fun onShowFileChooser(
webView: WebView,
filePathCallback: ValueCallback<Array<Uri>>,
fileChooserParams: WebChromeClient.FileChooserParams,
): Boolean {
return onShowFileChooser?.invoke(webView, filePathCallback, fileChooserParams) ?: false
}

override fun onGeolocationPermissionsShowPrompt(origin: String, callback: GeolocationPermissions.Callback) {
onGeolocationPermissionsShowPrompt?.invoke(origin, callback)
}

override fun onGeolocationPermissionsHidePrompt() {
onGeolocationPermissionsHidePrompt?.invoke()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,38 @@ public object ShopifyCheckoutKit {
}
}

/**
* Presents a Shopify checkout within a Dialog
*
* @param checkoutUrl The URL of the checkout to be presented, this can be obtained via the Storefront API
* @param context The context the checkout is being presented from
* @param configure a Kotlin-first builder for fail/cancel callbacks, browser/system hooks,
* and an optional communication client
* @return An instance of [CheckoutKitDialog] if the dialog was successfully created and displayed.
*/
@JvmStatic
@JvmSynthetic
public fun present(
checkoutUrl: String,
context: ComponentActivity,
configure: CheckoutPresentation.() -> Unit,
): CheckoutKitDialog? {
val presentation = CheckoutPresentation().apply(configure)
return present(
checkoutUrl = checkoutUrl,
context = context,
checkoutEventProcessor = presentation.buildEventProcessor(),
communicationClient = presentation.communicationClient,
)
}

/**
* Presents a Shopify checkout within a Dialog
*
* @param checkoutUrl The URL of the checkout to be presented, this can be obtained via the Storefront API
* @param context The context the checkout is being presented from
* @param checkoutEventProcessor provides callbacks to allow clients to listen for and respond to checkout lifecycle events such as
* (failure, completion, cancellation, external link clicks).
* (failure, completion, cancellation, and browser/system prompts).
* @param communicationClient optional handler for Embedded Checkout Protocol (ECP) messages.
* Implement [CheckoutCommunicationClient] to intercept arbitrary ECP messages from the checkout
* web page. Built-in messages ([ec.ready][EmbeddedCheckoutProtocol.METHOD_READY] and
Expand Down
Loading
Loading