Sell on the web and unlock in the app with redemption links
To sell on the web and unlock in your app with BillDog, register the <bundle id>.billdog URL scheme, pass every incoming URL to BillDog.shared.handleDeepLink(url) (Android: BillDog.handleDeepLink(uri)), and start the sale with purchaseViaWeb. Stripe sends the buyer back to <scheme>://checkout/success?token=…; the SDK redeems the single-use token, grants the entitlement and reports the result to onDidRedeemLink.
Steps last checked against the SDK source on 16 Nov 2026.
What you'll build
- A "Buy on the web" button that opens Stripe Checkout from the app
- Return and
redeemdeep links that open your app and are redeemed by the SDK - The
premiumentitlement granted after payment, with clear messages for expired, used and foreign links
What you'll need
- An iOS or Android app with the BillDog SDK configured (the iOS or Android codelab)
- Stripe connected, Web Checkout and test mode on, and a product with a Stripe price that grants
premium(steps 1 and 2 of the headless web paywall codelab)
1. Understand the redemption flow
3 minpurchaseViaWebasks BillDog for a Stripe Checkout session. The server creates a single-use redemption token for this customer, valid for 7 days, and the SDK keeps it on the device.- The buyer pays in the browser. Stripe redirects to
<scheme>://checkout/success?token=…, which opens your app. - Your app hands the URL to
handleDeepLink. The SDK redeems the token, refreshes customer info and callsonDidRedeemLinkon your delegate.
A token can also arrive on its own as <scheme>://redeem?token=… (or <scheme>://redeem/<token>). handleDeepLink redeems those the same way.
A token can only be redeemed by the customer it was issued for. That makes this flow reliable for checkouts started inside your app. A purchase made by an anonymous visitor on your website with the web SDK belongs to that visitor, and redeeming its link in the app fails with userMismatch. See the FAQ for buyers who pay on the web first.
Before you ship a web-purchase button in an iOS app, check the App Store Review Guidelines and Apple's external purchase rules for each storefront you sell in. Google Play has its own rules for alternative billing.
2. Register the app's checkout scheme
6 minThe SDKs use a scheme only your app registers: your bundle ID (iOS) or application ID (Android), lower-cased, plus .billdog. For com.acme.app that is com.acme.app.billdog. Characters other than letters, digits, +, - and . become -. A per-app scheme matters because the token is a bearer secret: with a shared scheme, another app could receive it.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>com.acme.app.billdog</string>
</array>
</dict>
</array><activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop">
<!-- your existing MAIN/LAUNCHER intent-filter stays here -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="com.acme.app.billdog" />
<data android:host="checkout" />
<data android:host="redeem" />
</intent-filter>
</activity>If you need a different scheme, set customUrlScheme in BillDogConfig on both platforms and register that instead. An app that still registers only the old shared billdog scheme keeps working, but the SDK logs a warning.
3. Route links to the SDK on iOS
6 minPass every URL the app opens to handleDeepLink. It returns nil for links that aren't BillDog's, so your own deep links are untouched. Set a delegate to hear the result: onDidRedeemLink gets a RedemptionOutcome whether the link came from a checkout started now, a cold start, or a redeem link. The SDK holds the delegate weakly, so keep a strong reference.
import SwiftUI
import BillDogFull
final class RedemptionHandler: BillDogDelegate {
func onDidRedeemLink(outcome: RedemptionOutcome) {
DispatchQueue.main.async {
switch outcome {
case .success(let result):
print("Unlocked: \(result.entitlements.map(\.identifier))")
case .expired:
print("This link has expired.")
case .alreadyRedeemed:
print("This purchase was already redeemed.")
case .userMismatch:
print("This purchase belongs to another account.")
case .invalid:
print("This link isn't valid.")
case .refused, .error:
print("Couldn't confirm the purchase yet. Try again shortly.")
@unknown default:
break
}
}
}
}
@main
struct MyApp: App {
private let redemptions = RedemptionHandler()
init() {
BillDog.shared.configure(
config: BillDogConfig(apiKey: "bd_public_test_YOUR_KEY")
)
BillDog.shared.delegate = redemptions
}
var body: some Scene {
WindowGroup {
ContentView()
.onOpenURL { url in
_ = BillDog.shared.handleDeepLink(url)
}
}
}
}
// Replace the print calls with your own UI.4. Route links to the SDK on Android
6 minHandle the link in onCreate (cold start) and onNewIntent (app already running). BillDog.handleDeepLink(uri) redeems a success or redeem link in the background and calls your delegate's onDidRedeemLink. Don't also call redeemPurchase for the same link: the second call is refused as already redeemed. BillDog.delegate is held weakly, so the delegate must live as long as you need it; here it is the activity.
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import io.billdog.core.BillDog
import io.billdog.core.BillDogDelegate
import io.billdog.core.RedemptionOutcome
class MainActivity : ComponentActivity(), BillDogDelegate {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
BillDog.delegate = this
intent?.data?.let { BillDog.handleDeepLink(it) }
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
intent.data?.let { BillDog.handleDeepLink(it) }
}
override fun onDidRedeemLink(outcome: RedemptionOutcome) {
runOnUiThread {
val message = when (outcome) {
is RedemptionOutcome.Success -> "Premium unlocked"
RedemptionOutcome.Expired -> "This link has expired."
RedemptionOutcome.AlreadyRedeemed -> "This purchase was already redeemed."
RedemptionOutcome.UserMismatch -> "This purchase belongs to another account."
RedemptionOutcome.Invalid -> "This link isn't valid."
is RedemptionOutcome.Refused,
is RedemptionOutcome.Error -> "Couldn't confirm the purchase yet. Try again shortly."
}
Log.i("Redemption", message) // show it in your own UI
}
}
}5. Start the web checkout
6 minName the product by its Product Identifier. On iOS, purchaseViaWeb(productId:from:) opens Stripe in a Safari sheet and returns the redemption token when the success link comes back; redeem it with redeemAndNotify(token:), which retries short failures and calls your delegate. It throws if the buyer closes the sheet, and after 60 seconds of waiting. A buyer who pays after that still comes back through handleDeepLink, which redeems the token itself.
import SwiftUI
import UIKit
import BillDogFull
struct BuyOnWebButton: View {
var body: some View {
Button("Buy on the web") {
Task { @MainActor in
guard let presenter = topViewController() else { return }
do {
let token = try await BillDog.shared.purchaseViaWeb(
productId: "premium_monthly",
from: presenter
)
await BillDog.shared.redeemAndNotify(token: token)
} catch {
// Closed, timed out or refused. A late success link is
// still redeemed by handleDeepLink.
print("Web checkout: \(error)")
}
}
}
}
}
@MainActor
func topViewController() -> UIViewController? {
let scene = UIApplication.shared.connectedScenes
.compactMap { $0 as? UIWindowScene }
.first { $0.activationState == .foregroundActive }
var top = scene?.keyWindow?.rootViewController
while let presented = top?.presentedViewController { top = presented }
return top
}On Android, purchaseViaWeb is a suspend function that opens a Custom Tab and returns once it is open. The purchase completes when the return link reaches handleDeepLink.
// Add to MainActivity, with these imports:
// import androidx.lifecycle.lifecycleScope
// import kotlinx.coroutines.launch
fun buyOnTheWeb() {
val userId = BillDog.getAppUserId() ?: return
lifecycleScope.launch {
BillDog.purchaseViaWeb(this@MainActivity, "premium_monthly", userId)
.onFailure { Log.w("WebCheckout", "Couldn't open checkout: ${it.message}") }
}
}On Android 1.1.1-beta.5, when offerings are loaded, purchaseViaWeb swaps an identifier that matches a loaded package for that package's Play product ID before calling the server, and the server can't find a product by its Play ID. Until this is fixed, give the product a Product Identifier equal to its Play Store Product ID, or pass its Stripe price ID (price_…).
6. Test it and handle failed links
5 minUse a bd_public_test_ key with Stripe in test mode. Tap the button, pay with Stripe's test card 4242 4242 4242 4242 (any future expiry, any CVC) and let Stripe open your app. You should see a success outcome. Then switch the dashboard header to Sandbox and open Customers: the purchase and premium should be on the customer.
Open the same link again to see a refusal. What each outcome means:
alreadyRedeemed/AlreadyRedeemed: the token was used. Tokens are claimed atomically, so two racing attempts give one success and one refusal.expired/Expired: more than 7 days passed since the token was created. The expiry is fixed.userMismatch/UserMismatch: the token belongs to another customer. It isn't used up, so the right customer can still redeem it.invalid/Invalid: the server doesn't know the token.error/Error: the network failed, or Stripe's webhook hasn't recorded the payment yet. The SDK retries for a few seconds first and keeps the token on the device.refused/Refused: the server refused the caller's identity, not the token. The token is kept.
Because the checkout was started for this customer, Stripe's webhook also grants premium to it directly. If you got error because the webhook was slow, getCustomerInfo(forceRefresh: true) a little later shows the entitlement.