Launch offer for the first 500 accounts: $10K MTR free for 24 months + $100 credit →
    .io

    Web Checkout Setup Guide

    Web Checkout Overview

    BillDog Web Checkout enables you to offer web-based payment flows for your mobile app users. This is especially useful for apps that qualify for external payment links under Apple's "reader app" entitlement or for Android apps that want to offer alternative payment methods.

    Use Cases

    App-to-Web (App2Web)

    Deep-link from your iOS/Android app to a web checkout page. Useful for reader apps, streaming services, and apps with external purchase entitlement.

    Web Paywalls

    Show paywalls directly on your website with Stripe checkout integration. Perfect for landing pages and marketing sites.

    Reminder Notifications

    Send email or push notifications with direct purchase links. Great for re-engagement campaigns and trial expiration reminders.

    Pricing Experiments

    Test different price points using Stripe prices without modifying your App Store Connect or Google Play configuration.

    Prerequisites

    • Stripe account connected to your BillDog project
    • Products configured with Stripe price IDs
    • Stripe webhook configured for purchase confirmation

    Step 1: Enable Web Checkout

    Navigate to Settings → Web Checkout and turn on Enable Web Checkout. It is the project's switch for every web checkout: while it is off, each checkout request (from the SDKs, the hosted checkout page or your server) is refused with 403 ACCESS_DENIED (reason: web_checkout_disabled) and nothing is charged. Turn it off to stop selling on the web at once.

    The return URLs are sent with each checkout (success_url / cancel_url, Step 3), and the trial length comes from each product's trial setting.

    Step 2: Configure Stripe Webhook

    Add the BillDog webhook URL to your Stripe dashboard. Keep ?project_id=: without it every event is rejected with 401 Invalid signature. Settings → Web Checkout shows the URL with your project ID filled in.

    Webhook URL: https://api.billdog.io/v1/webhook-stripe?project_id=<PROJECT_ID>
    
    Events to listen for (all 17):
    - checkout.session.completed
    - checkout.session.async_payment_succeeded
    - checkout.session.async_payment_failed
    - checkout.session.expired
    - customer.subscription.created
    - customer.subscription.updated
    - customer.subscription.deleted
    - customer.subscription.trial_will_end
    - invoice.paid
    - invoice.payment_failed
    - invoice.payment_action_required
    - payment_intent.succeeded
    - payment_intent.payment_failed
    - charge.failed
    - charge.refunded
    - charge.dispute.created
    - charge.dispute.closed

    Already have an endpoint? Add checkout.session.async_payment_succeeded and checkout.session.async_payment_failed to it: a purchase paid by a delayed method (SEPA, ACH, Boleto, OXXO) completes only when these arrive.

    Step 3: Create Checkout Session (API)

    The SDKs call create-web-checkout for you (purchaseViaWeb on iOS, Android, React Native and Flutter; purchaseProduct on the web). This is the request they send (supabase/functions/create-web-checkout/index.ts, schema CheckoutSchema):

    POST /functions/v1/create-web-checkout
    X-BillDog-API-Key: bd_public_live_xxxxxxxx      // or api_key in the body
    X-BillDog-Device: $BillDogAnonymousID:…         // sent by the SDK
    X-BillDog-Device-Key: bdk_…                     // sent by the SDK
    X-BillDog-Session: <access token>               // when signed in with BillDog Auth
    
    {
      "source": "app_to_web",              // app_to_web | web_paywall
      "product_id": "product-uuid",        // products.id, product_identifier, Stripe price or store SKU
      "success_url": "https://yourapp.com/success",   // required for web_paywall; app_to_web defaults to the app's scheme
      "cancel_url": "https://yourapp.com/cancel",
      "app_user_id": "user-123",           // a secret key names its customer with this (or customer_id); otherwise a label only
      "region": "US",                      // ISO 3166-1 alpha-2; required when the project gates web checkout by region
      "platform": "ios",
      "gateway": "stripe",                 // optional; Stripe is the only merchant gateway
      "placement_id": "placement-uuid",    // optional attribution
      "metadata": { "campaign": "spring" } // optional, string values
    }
    
    // Response (Stripe)
    {
      "success": true,
      "data": {
        "kind": "redirect",
        "url": "https://checkout.stripe.com/...",
        "session_id": "cs_...",
        "pending_checkout_id": "uuid",
        "redemption_token": "app2web_…"     // app_to_web only: pre-linked to this checkout, valid 7 days
      },
      "meta": { "request_id": "...", "api_version": "v1", "timestamp": "..." }
    }

    Who the checkout is for

    The customer comes from the proof, never from a body field. A BillDog Auth session (X-BillDog-Session) or the install's device key (X-BillDog-Device +X-BillDog-Device-Key, sent by the SDK) is its own customer: a fresh device's customer is created here, with the key bound, so the purchase it pays for has an owner. A project secret key names its customer with customer_id (a UUID) or app_user_id (a label the server vouches for; an unknown label may be created). A public key alone is refused with 403 PROOF_REQUIRED; a session or device request whose app_user_id / customer_id names someone else is 403ACCESS_DENIED (reason: target_mismatch).

    The hosted checkout page (pay.<merchant>/p/<slug>) holds no key: it sends the server-signed checkout_token that get-paywall-by-slug minted for the page. That checkout is unbound (pending_checkouts.customer_id is null) and is bound to a person later by a proven redeem-purchase. An anonymous device id sent without its key is refused.

    Rules the server applies

    • The project always comes from the credential; a body project_id that differs is 403.
    • With Enable Web Checkout off, every request is 403 ACCESS_DENIED (reason: web_checkout_disabled).
    • The credential's environment must match the project's Stripe mode (sandbox key ↔ test mode), else 403 ACCESS_DENIED (reason: environment_mismatch).
    • The price comes from the product (or from a pricing-experiment arm this customer is assigned to). There is no trial_period_days in the request: the trial length is decided from products.trial_duration_days and the customer's history.
    • email is honoured only from a project secret key.
    • Promotion codes are the business's decision, never the payer's device: Stripe Checkout shows its code field when a project secret key sends allow_promotion_codes: true, or else when the placement's Web settings say so, or else when the project default on the Promotion Codes page is on. A secret key can instead apply a coupon up front with coupon_id or promotion_code (not together with allow_promotion_codes).
    • With source: app_to_web and region gating enabled on the project, a request without an allowed region is 403 ACCESS_DENIED with region_blocked: true.
    • Web checkout uses Stripe: the product needs a Stripe price. gateway: razorpay is refused with 400 (reason: unsupported_gateway).

    Step 4: Handle Purchase Redemption

    After a successful web purchase, the user redeems it in your app. For how the redemption token is delivered (deep link, QR code, copyable code) and how to handle it in the iOS and Android SDKs, see the Web Redemption Links guide.

    // The SDK redeems the token from the return link for you. If you call it yourself:
    POST /functions/v1/redeem-purchase
    X-BillDog-API-Key: bd_public_live_xxxxxxxx
    X-BillDog-Device: $BillDogAnonymousID:…   // or X-BillDog-Session — the proof decides WHO gets the purchase
    X-BillDog-Device-Key: bdk_…
    
    {
      "token": "token-from-the-return-link"
    }
    
    // Response
    {
      "success": true,
      "data": {
        "redeemed": true,
        "customer_id": "...",
        "product": { "id": "...", "identifier": "...", "name": "...", "type": "..." },
        "entitlements": [ { "id": "...", "identifier": "premium", "name": "Premium" } ],
        "subscription": { "stripe_subscription_id": "...", "current_period_end": "..." }
      },
      "meta": { "request_id": "..." }
    }
    
    // A public key alone is 403 PROOF_REQUIRED and the token is not consumed.
    // A token minted for another customer's label, or a purchase already bound
    // to another customer, is 403 ACCESS_DENIED (reason: target_mismatch).
    // A replay is 409 ALREADY_EXISTS; an expired token is 400 INVALID_REQUEST.

    Step 5: iOS App2Web Implementation

    import UIKit
    
    class WebCheckoutManager {
        func openWebCheckout(for productId: String, from presenter: UIViewController) async throws {
            // purchaseViaWeb opens the web checkout itself (Safari sheet,
            // required for Reader apps) and returns a redemption token once
            // the purchase completes. The signed-in app user is used automatically.
            let redemptionToken = try await BillDog.shared.purchaseViaWeb(
                productId: productId,
                from: presenter
            )
    
            // Redeem the returned token to grant entitlements in-app
            try await BillDog.shared.redeemPurchase(token: redemptionToken)
        }
    
        // A return link that arrives with no purchaseViaWeb call waiting
        // (e.g. the app was relaunched) is redeemed by the SDK itself.
        func handleOpenURL(_ url: URL) {
            BillDog.shared.handleDeepLink(url)
        }
    }

    Step 6: Android App2Web Implementation

    class WebCheckoutManager(private val context: Context) {
        suspend fun openWebCheckout(productId: String, userId: String) {
            // purchaseViaWeb creates the checkout and opens it in a Chrome Custom
            // Tab. It returns as soon as the tab opens — the purchase is not paid
            // yet, so do not redeem here.
            BillDog.purchaseViaWeb(context, productId, userId)
                .onFailure { error ->
                    Log.e("WebCheckout", "Web checkout failed", error)
                }
        }
    
        // The checkout returns to <applicationId>.billdog://checkout/success?token=…
        // (BillDogConfig.customUrlScheme to choose another); the SDK redeems the
        // token, refreshes customer info and dismisses the paywall.
        fun handleDeepLink(intent: Intent) {
            val uri = intent.data ?: return
            BillDog.handleDeepLink(uri)
        }
    }

    Step 7: Universal Links, App Links & Deep Link Runbook

    For seamless return from the web browser directly into your mobile app (without interstitial prompts), configure Apple Universal Links (iOS) and Android App Links (Android), along with the fallback custom scheme.

    1. iOS Universal Links & Custom Scheme

    Add the Associated Domains capability in Xcode and register the return scheme in Info.plist. The SDK’s default is <bundle id>.billdog (for com.yourcompany.app, com.yourcompany.app.billdog), a scheme only your app registers: the old shared billdog scheme let another BillDog-powered app on the phone receive the return link. An app that still registers only billdog keeps working (the SDK uses it and logs a warning) until you add its own. Set BillDogConfig.customUrlScheme to use a scheme of your choosing instead.

    <!-- Info.plist: Custom URL Scheme Fallback -->
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLName</key>
            <string>io.billdog.checkout</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>com.yourcompany.app.billdog</string>
            </array>
        </dict>
    </array>
    
    <!-- Entitlements: Universal Links -->
    <key>com.apple.developer.associated-domains</key>
    <array>
        <string>applinks:checkout.yourdomain.com</string>
    </array>

    Serve /.well-known/apple-app-site-association on your checkout domain:

    {
      "applinks": {
        "details": [
          {
            "appIDs": ["TEAMID.com.yourcompany.app"],
            "components": [
              { "/": "/checkout/*" }
            ]
          }
        ]
      }
    }

    2. Android App Links & Custom Scheme

    Configure an intent-filter in AndroidManifest.xml inside your launch Activity. The default return scheme is <applicationId>.billdog; the ${applicationId} placeholder writes it for you:

    <!-- AndroidManifest.xml -->
    <activity android:name=".MainActivity" android:exported="true">
        <!-- Fallback Custom Scheme -->
        <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="${applicationId}.billdog" android:host="checkout" />
            <data android:scheme="${applicationId}.billdog" android:host="redeem" />
        </intent-filter>
    
        <!-- Verified Android App Link -->
        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" android:host="checkout.yourdomain.com" android:pathPrefix="/checkout" />
        </intent-filter>
    </activity>

    Deploy /.well-known/assetlinks.json with your app's SHA-256 fingerprint:

    [{
      "relation": ["delegate_permission/common.handle_all_urls"],
      "target": {
        "namespace": "android_app",
        "package_name": "com.yourcompany.app",
        "sha256_cert_fingerprints": ["14:6D:E9:83:..."]
      }
    }]

    3. Cross-Platform Deep Link Handlers

    Pass incoming links to BillDog.handleDeepLink(url). The SDK automatically redeems the token, syncs entitlements, and dismisses any active paywall:

    // Android (Kotlin)
    fun handleDeepLink(intent: Intent) {
        val uri = intent.data ?: return
        BillDog.handleDeepLink(uri)
    }
    
    // iOS (Swift)
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
        return BillDog.shared.handleDeepLink(url) != nil
    }
    
    // React Native (TypeScript)
    Linking.addEventListener('url', async ({ url }) => {
        await BillDog.handleDeepLink(url);
    });
    
    // Flutter (Dart)
    await BillDog.shared.handleDeepLink(uri.toString());

    Test Mode

    Turn on Settings → Web Checkout → Enable Test Mode to test without real charges. Use a sandbox (bd_public_test_…) key with test mode; a key whose environment doesn’t match the Stripe mode is refused with 403 environment_mismatch.

    Test Mode Active: When enabled, all checkouts use Stripe test mode.

    • Use test card: 4242 4242 4242 4242
    • Any future expiry date
    • Any 3-digit CVC

    Next Steps

    Was this page helpful?

    Or rate this page:

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