📍 Bolt Help / Developer Resources / SDKs / Android WebView SDK Setup
Android WebView SDK Setup
Install Bolt into your Android tech stack using our platform software development kits (SDKs) for Android WebView.

Welcome to the Bolt Android SDK! Our goal is to deliver the most innovative checkout experience possible — for both you and your shoppers. To get started, follow this guide to install the Android SDK on your application.

Step 1: Install Bolt’s Android SDK Package

  1. Download the latest version of the Android Checkout SDK:
  1. Copy the .aar file into the libs folder of your app module directory, or wherever you store your local libraries (for example, /root/app/libs/).
  2. Add the .aar file as a dependency in your build.gradle:
    implementation files("libs/checkout.aar")
    

Step 2: Initialize the Bolt SDK

Before SDK functionality can be called anywhere in your code, you must initialize the SDK.

In the overridden onCreate method of your mainActivity (or whichever activities or application classes will need to use the SDK), call BoltCheckout.init and reference your Bolt API Keys. These keys can be found in the Merchant Dashboard > Developers > API.

// MainActivity.kt
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        BoltCheckout.init(
            publishableKey = "INSERT_YOUR_PUBLISHABLE_KEY",
            apiKey = "INSERT_YOUR_API_KEY",
            environment = BoltEnvironment.STAGING, // Replace with appropriate environment
            application = application,
        )
    }
}

Step 3: Generate an Order Token

Wherever you want to start checkout, you first need to create an order token to generate the Webview URL.

Your storefront app will need to tokenize the basket data and retrieve an order token via an order request with the createOrderToken endpoint. Similarly, a Progressive Web App (PWA) requires the token to initialize and configure the Bolt Checkout Button.

graph LR A[Bolt] <--> B((Bolt API)) B <--> D([Android App]) B <--> E([iOS App]) B <--> F([PWA]) D -->|token| G[Webview Checkout] E -->|token| H[Webview] F -->|token| I[iFrame Checkout]

The order token will be returned as a string in a successful request with the value token, which you can then use to proceed with initializing checkout.

{
  "cart": { ... },
  "dynamic_content": { ... },
  "external_data": { ... },
  "token": "string",
  "user_note": "string"
}

Step 4: Start Checkout

After you have received the order token, call the startCheckout method on the instance of BoltCheckout.

Step 5: Receive Callback Events

When checkout is complete, pass in an instance of BoltCheckoutDelegate to receive callback events.

// CartFragment.kt
class CartFragment : Fragment(), BoltCheckoutDelegate {

    private val boltCheckoutResultLauncher =
        boltCheckout.getBoltCheckoutActivityResultLauncher(this, this)

    fun handleCheckoutStart(orderToken: String) {
        val boltCheckout = BoltCheckout.get()
        boltCheckout.startCheckout(
            orderToken = orderToken, // Newly created token for this order
            hints = BoltMerchantHints( // Can prefill user input fields
                firstName = "Bob",
                lastName = "Builder",
            ),
        ),
        context = requireContext(),
        checkoutActivityResultLauncher = boltCheckoutResultLauncher,    
    }

    override fun onCheckoutCancel() {
        // todo handle cancel
    }

    override fun onCheckoutError(errorReason: String) {
        // todo handle error
    }

    override fun onCheckoutSuccess(orderReference: String) {
        // todo handle success
    }
}
Filter by Section
Filter by Topic