Web Redemption Links
From web checkout to unlocked app
When a customer completes a BillDog web checkout, BillDog creates a single-use redemption token tied to that purchase and to the customer’s app_user_id. Your app passes the token to the SDK, the SDK calls the redeem-purchase endpoint, and the entitlements granted by the web purchase are attached to the customer in the app.
Where Redemption Tokens Come From
- App-to-web checkout (the SDK’s
purchaseViaWeb, backed bycreate-web-checkout): the token is created before the customer is sent to Stripe and returned in the response asredemption_token. These tokens start withapp2web_. - Web paywall checkout: when Stripe reports the completed checkout session, the Stripe webhook creates the token. It does this only when the session’s
sourceisapp_to_weborweb_paywalland the checkout carried anapp_user_id. A checkout without anapp_user_idgets no token.
How the Customer Receives the Token
Today, start the checkout in the app. purchaseViaWeb sends the buyer to Stripe, and Stripe sends them back to <app id>.billdog://checkout/success?token=…, which handleDeepLink redeems. The hosted success page described below (the “Open in app” button, QR code and copyable code) belongs to BillDog’s hosted checkout, which is not available yet, so a purchase started on a web page cannot be handed to the app this way.
BillDog’s hosted checkout success page looks up the token for the Stripe session_id and, when one exists, shows it three ways:
“Open in app” button
A deep link of the form <app id>.billdog://redeem?token=…, built from the project’s bundle id / package name. If the project has App Store / Google Play URLs configured, a “Download it” button links to the store on iOS and Android.
QR code
The same deep link as a QR code, so a customer who paid on a desktop can scan it with a phone that already has the app.
Copyable code
The raw token with a copy button, for apps that offer a “redeem code” field.
The success page also offers an email fallback: the customer enters their email and receives a subscription-management link (valid for 24 hours) for the page at /manage/:projectSlug. That email does not contain a redemption token, and BillDog does not send the token in a receipt email.
Token Lifecycle
Redemption claims the token atomically. If two requests race, exactly one succeeds and the other gets “already redeemed”.
Tokens expire 7 days after they are created. The expiry is fixed; it is not configurable per project.
A token created for an app_user_id can only be redeemed by that same app_user_id. Redeeming it as a different user is refused. Make sure the app is identified as the same user that started the checkout before redeeming.
Errors
redeem-purchase returns these errors. The SDK redemption helpers map them to typed outcomes (expired, alreadyRedeemed, userMismatch, invalid).
| error_code | HTTP | Meaning |
|---|---|---|
NOT_FOUND | 404 | No token with this value exists in the project. |
ALREADY_EXISTS | 409 | The token has already been redeemed. |
INVALID_REQUEST | 400 | The token has expired. |
ACCESS_DENIED | 403 | The token belongs to a different app_user_id. |
The Redeem Endpoint
The native SDKs call this for you. If you need to call it directly:
POST /functions/v1/redeem-purchase
x-billdog-api-key: <your public SDK key>
{
"token": "<redemption token>",
"app_user_id": "user-123",
"device_id": "optional",
"platform": "ios" // optional
}
// 200 response (inside the standard success envelope)
{
"redeemed": true,
"customer_id": "...",
"product": { ... },
"entitlements": [ ... ],
"subscription": { "stripe_subscription_id": "...", "current_period_end": ... }
}Handling Redemption in Your App
The hosted success page links to your app’s own scheme, <bundle id>.billdog:// on iOS and <applicationId>.billdog:// on Android (the SDKs’ default return scheme, from the bundle id / package name set on the project), so your app must register that scheme to be opened by the “Open in app” button and the QR code. A project with no app id, or a QR code shown on a desktop for apps whose iOS and Android ids differ, falls back to the legacy billdog://, which the SDKs still accept from apps that register it. Universal Links / App Links and deferred deep linking (redeeming after a fresh install) are not provided; a customer who installs the app afterwards can paste the copyable code into your app instead.
Every SDK routes a return or redemption link the same way: pass the URL the app opened to handleDeepLink. It redeems a checkout success or redeem link once and reports the outcome; links that aren’t BillDog’s are left to you. That is BillDog.shared.handleDeepLink(url) on iOS, BillDog.handleDeepLink(uri) on Android, BillDog.handleDeepLink(url) in React Native and Expo, and BillDog.shared.handleDeepLink(uri) in Flutter. Those three also offer purchaseViaWeb and an awaitable completeWebCheckout. Don’t also call redeemPurchase for the same link: the second call is refused as already redeemed.
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.Testing
- Turn on Settings → Web Checkout → Enable Test Mode, use a sandbox (
bd_public_test_…) key, and callpurchaseViaWebfrom a debug build. - Pay with Stripe’s test card
4242 4242 4242 4242. - Stripe returns to the app; confirm
onDidRedeemLinkreports success and the entitlement appears. - Open the same
<bundle id>.billdog://redeem?token=…link a second time and confirm the outcome is “already redeemed”.
Related Guides
Was this page helpful?
Or rate this page: