Launch offer for the first 500 accounts: $10K MTR free for 24 months + $100 credit →
    .io
    Monetization
    Any platform
    Intermediate
    32 min

    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 redeem deep links that open your app and are redeemed by the SDK
    • The premium entitlement 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 min
    1. purchaseViaWeb asks 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.
    2. The buyer pays in the browser. Stripe redirects to <scheme>://checkout/success?token=…, which opens your app.
    3. Your app hands the URL to handleDeepLink. The SDK redeems the token, refreshes customer info and calls onDidRedeemLink on 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 min

    The 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.

    Info.plist
    <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleURLSchemes</key>
        <array>
          <string>com.acme.app.billdog</string>
        </array>
      </dict>
    </array>
    AndroidManifest.xml
    <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.

    5. Start the web checkout

    6 min

    Name 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.

    BuyOnWebButton.swift
    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.

    MainActivity.kt
    // 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 min

    Use 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.

    Frequently asked questions

    Seven days from when the token was created, and it can be used once. After that the SDK reports expired; a second use reports already redeemed. The expiry isn't configurable.

    Only when the website and the app are the same BillDog customer, for example signed in to the same account with BillDog Auth. Then the purchase and its entitlement are already on that customer and the app sees premium after getCustomerInfo, with no link needed. A purchase by an anonymous web visitor belongs to that visitor and can't be redeemed by the app.

    No, not for links. handleDeepLink redeems success and redeem links and calls onDidRedeemLink. Call redeemAndNotify yourself only for the token iOS purchaseViaWeb returns, or for a token you got another way, such as CustomerInfo.pendingRedemptions.

    The current customer's web purchases that are paid and not yet redeemed in the app, newest first (up to 10). A checkout that was opened but never paid, expired, or whose purchase was refunded, failed or charged back is not listed, so every entry can be redeemed with redeemAndNotify.

    By default your bundle ID (iOS) or application ID (Android), lower-cased, plus .billdog, for example com.acme.app.billdog://checkout/success. Register it in Info.plist or AndroidManifest.xml, or set customUrlScheme in BillDogConfig and register that instead.

    Reference

    Ship it on a free project

    Create a project, grab your SDK key and follow along. Sandbox purchases and data stay separate from production, so test transactions never mix with real revenue.

    We use cookies and process your data to provide our services. By continuing, you agree to our Terms and Privacy Policy.