Custom Purchases & Non-Store Products
Overview
BillDog ships with a built-in StoreKit / Google Play Billing integration. If you need to use a different billing stack — RevenueCat, Qonversion, raw StoreKit 2, Google Play Billing 6+, or even web-only providers like Stripe and Paddle — you can hand purchase execution to your own code while BillDog continues to handle paywall display, analytics, entitlements and customer state.
Two surfaces enable this:
- PurchaseController — the unified contract you implement to take ownership of
purchase(productId:)andrestorePurchases(). - CustomProduct — a Superwall-style model that lets you describe products that don't exist in the App Store or Play Console at all (e.g. Stripe SKUs, Paddle plans, in-house entitlements).
1. Implement PurchaseController
The contract is identical across the iOS and Android SDKs.
iOS (Swift)
import BillDogFull
import RevenueCat
final class MyPurchaseController: PurchaseControllerProtocol {
func purchase(productId: String) async throws -> PurchaseResult {
do {
let result = try await Purchases.shared.purchase(product: ...)
if result.userCancelled { return .cancelled }
return .purchased(
transactionId: result.transaction?.transactionIdentifier ?? "",
productId: productId,
originalTransactionId: result.transaction?.orderIdentifier
)
} catch {
return .failed(error: error)
}
}
func restorePurchases() async throws -> RestoreResult {
let info = try await Purchases.shared.restorePurchases()
return .restored(items: info.activeSubscriptions.map {
RestoredPurchase(transactionId: "", productId: $0)
})
}
}
BillDog.shared.configure(
config: .init(apiKey: "YOUR_API_KEY"),
purchaseController: MyPurchaseController()
)Android (Kotlin)
import io.billdog.core.BillDog
import io.billdog.core.PurchaseController
import io.billdog.core.PurchaseResult
import io.billdog.core.RestoreResult
class MyPurchaseController : PurchaseController {
override suspend fun purchase(productId: String): PurchaseResult {
// Drive RevenueCat / Qonversion / raw BillingClient here.
return PurchaseResult.Purchased(
transactionId = "...",
productId = productId,
originalTransactionId = null,
)
}
override suspend fun restorePurchases(): RestoreResult {
return RestoreResult.Restored(items = emptyList())
}
}
BillDog.configure(
context = applicationContext,
apiKey = "YOUR_API_KEY",
config = BillDogConfig(),
purchaseController = MyPurchaseController(),
)Source tracking. When a custom controller is provided, every receipt posted to BillDog's backend is automatically stamped with source = EXTERNAL. Receipts driven by the bundled internal controller (StoreKit / Play Billing) are stamped INTERNAL. Purchases BillDog learns about from a provider webhook (e.g. Stripe) without a matching SDK call — and refund reconciliations — are stamped OBSERVED.
2. Map results correctly
Implementations must map user cancellation to .cancelled and Ask-to-Buy / Android PENDING to .pending — never to .failed. Misclassifying these breaks downstream funnel analytics and entitlement reconciliation.
See Purchase Error Handling for the full result-mapping table.
3. CustomProduct — non-StoreKit / non-Play products
CustomProduct lets you list products in BillDog and render them in paywalls without ever registering them in the App Store or Play Console. Useful for Stripe-only web flows, Paddle plans, or in-house entitlements granted server-side.
Register the product first. Create the product in your BillDog dashboard with Product kind = Custom, set its provider and provider product id, and map it to the entitlement it grants. Recording an external purchase resolves against this catalog entry, so an unregistered custom product cannot grant access.
Defining a custom product
// iOS
let stripeProduct = CustomProduct(
id: "stripe_pro_yearly",
displayName: "Pro (Annual)",
priceString: "$89.99",
price: 89.99,
currency: "USD",
provider: "stripe",
providerProductId: "price_1QabcXYZ",
period: "P1Y",
metadata: [:]
)
// Android
val stripeProduct = CustomProduct(
id = "stripe_pro_yearly",
displayName = "Pro (Annual)",
priceString = "$89.99",
price = 89.99,
currency = "USD",
provider = "stripe",
providerProductId = "price_1QabcXYZ",
period = "P1Y",
metadata = emptyMap()
)Routing to your controller
When a paywall button triggers a purchase for a CustomProduct, BillDog will onlydispatch it through a host-provided PurchaseController. The bundled internal controller will reject the call — custom products never touch StoreKit or Play Billing.
// iOS
let result = try await BillDog.shared.purchase(custom: stripeProduct)
// Android
val result = BillDog.purchase(product = stripeProduct)On a .purchased result, the SDK automatically records the purchase to BillDog with source = EXTERNAL (resolving the catalog product from the providerProductId), so the entitlement is granted and revenue is reported without any extra backend call from your app.
4. Worked example: Stripe Checkout
final class StripeController: PurchaseControllerProtocol {
func purchase(productId: String) async throws -> PurchaseResult {
// 1. Ask your backend for a Stripe Checkout session URL.
let session = try await api.createCheckoutSession(productId: productId)
// 2. Present it via SFSafariViewController and await the redirect.
let outcome = await StripeCheckoutPresenter.present(url: session.url)
switch outcome {
case .completed(let txId):
return .purchased(transactionId: txId, productId: productId, originalTransactionId: session.id)
case .cancelled:
return .cancelled
case .failed(let err):
return .failed(error: err)
}
}
func restorePurchases() async throws -> RestoreResult {
// Stripe restores are server-side: ask your backend for active subs.
let active = try await api.activeSubscriptions()
return .restored(items: active.map {
RestoredPurchase(transactionId: "", productId: $0.productId)
})
}
}5. Subscription lifecycle (renewals, refunds, cancellations)
For a custom subscription, BillDog records the first purchase and grants the entitlement, and the hourly expiry job revokes access at expires_at. Everything that happens at your billing provider after that — renewals, refunds, cancellations, billing retries — only BillDog knows about if you tell it. Since providers (Stripe, Paddle, in-house) all have different webhook shapes, your backend relays its provider's webhooks to two generic, provider-agnostic endpoints. Authenticate with your bd_secret_ /bd_public_test_ API key; identify the subscription by the sameoriginal_transaction_id you used at purchase.
Revenue events → POST /functions/v1/record-external-purchase
Re-post with transaction_type: "renewal" (or "restore") and the sameoriginal_transaction_id. BillDog extends the subscription's expires_at(derived from the product's period, or from an explicit expires_date), writes a correctly-labeled transaction, and re-materializes the entitlement.
// On your server, handling Stripe invoice.paid (renewal):
POST /functions/v1/record-external-purchase
{ "user_id": "<app user id>",
"original_transaction_id": "sub_123", // stable across renewals
"transaction_id": "in_456", // unique per renewal
"provider_product_id": "price_1Qabc",
"transaction_type": "renewal",
"purchase_date": "2026-07-19T00:00:00Z" }State events → POST /functions/v1/record-external-event
Non-revenue lifecycle. event_type ∈ refund · cancel ·uncancel · auto_renew_off · auto_renew_on ·grace_period · expire. BillDog maps each onto the same writers the App Store / Play webhooks use — e.g. refund revokes the entitlement immediately and stamps the transaction refunded; cancel keeps access until expiry (status →canceled).
// On your server, handling Stripe charge.refunded:
POST /functions/v1/record-external-event
{ "user_id": "<app user id>",
"original_transaction_id": "sub_123",
"event_type": "refund" }The iOS/Android SDKs also re-record restored custom purchases automatically when you call restorePurchases(), so a reinstall re-grants entitlements without extra work.
Related
- iOS SDK Guide — full purchase API reference
- Android SDK Guide — full purchase API reference
- Self-Hosted Proxy — route SDK traffic via your own infrastructure
Was this page helpful?
Or rate this page: