Android WebView SDK Setup
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.
INFO
Our video provider is currently experiencing an issue where certain video types are blocked from embedding. Thank you for your patience while we work to resolve this issue.
INFO
Our video provider is currently experiencing an issue where certain video types are blocked from embedding. Thank you for your patience while we work to resolve this issue.
INFO
Our video provider is currently experiencing an issue where certain video types are blocked from embedding. Thank you for your patience while we work to resolve this issue.
1. Install Bolt’s Android SDK Package
- Download the latest version of the Android Checkout SDK:
- 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/
). - Add the
.aar
file as a dependency in yourbuild.gradle
:implementation files("libs/checkout.aar")
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,
)
}
}
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.
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"
}
4. Start Checkout
After you have received the order token, call the startCheckout
method on the instance of BoltCheckout
.
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
}
}