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

    Using BillDog Paywalls alongside RevenueCat & Adapty

    See it in the demo — Bring your history with you (~90s)
    10 min
    Intermediate
    Integration

    You already run RevenueCat or Adapty for purchases, and you don't want to rip that out. This tutorial puts BillDog Paywalls, experiments and analytics in front of your existing purchase code, without a migration and without changing who charges the customer: BillDog shows the paywall, and when the user taps buy, BillDog calls your code, which makes the purchase through your vendor.

    What "alongside" means

    You give the BillDog SDK your own purchase code: a PurchaseController in React Native, or a purchaseAdapter on the web. Paywall purchases and restores go through it, so the store transaction still runs on RevenueCat or Adapty. BillDog never reads or imports your vendor's entitlements.

    ResponsibilityOwned by
    Paywall design, A/B tests, remote updates
    BillDog
    Product analytics, paywall conversion reporting
    BillDog
    Making and finishing the store purchase
    RevenueCat / Adapty
    (through your code)
    Your vendor's entitlements / access levels
    RevenueCat / Adapty
    BillDog's entitlements (React Native)
    BillDog
    , recorded from the store's own evidence of the purchase
    Customer identity (login / logout)
    Your app
    logs the user in to both SDKs

    Prerequisites (1 min)

    • A working RevenueCat or Adapty integration in your React Native / Expo app, or your own purchase code on the web.
    • A BillDog account and SDK key (bd_...). Quick Start →
    • At least one placement configured in the BillDog dashboard (e.g. onboarding).
    • @billdog.io/react-native 1.1.0-beta.3 or later (React Native), or @billdog.io/web 1.1.0-beta.3 or later (web).

    Path A · RevenueCat

    Bridge: React Native (beta)

    On React Native and Expo, a ready-made bridge ships in @billdog.io/react-native (beta): after Purchases.configure(...), call BillDogRevenueCat.configure({ apiKey: 'bd_public_…' }, Purchases) instead of BillDogConfiguration.configure, and RevenueCat keeps making purchases while BillDog records them. The native iOS and Android bridges are coming soon. See the RevenueCat integration guide for details.

    To write it yourself instead, use the same approach as Path B: a PurchaseController whose purchase and restorePurchases call react-native-purchases instead of Adapty. Everything else in this tutorial applies; only the evidence you can hand BillDog differs.

    On Android, react-native-purchases 9.15 and later return the Play purchase token as the purchase's transaction.purchaseToken (typed string | null). When it is set, hand it to BillDog as evidence, as Path B does: evidence: transaction.purchaseToken ? [StoreEvidence.googlePlay({ purchaseToken: transaction.purchaseToken, productIds: [transaction.productIdentifier] })] : []. Older versions don't return it: report transaction.transactionIdentifier (the Play order id) as transactionId with no evidence, and BillDog finds the purchase in Play by that id. A consumable RevenueCat has already consumed is gone from Play by then, so it isn't recorded.

    On iOS, react-native-purchases never returns Apple's signed transaction. Report transaction.transactionIdentifier (StoreKit's transaction id) as transactionId with no evidence; BillDog finds the signed transaction in StoreKit by that id, which records subscriptions and non-consumables. A consumable that RevenueCat has already finished drops out of StoreKit's history, so the SDK sends its id with the device's signed AppTransaction (iOS 16 and later). BillDog looks the purchase up with your App Store In-App Purchase key and records it only when the same Apple account made it. On iOS 15 a bare id isn't recorded, unless the app sets SKIncludeConsumableInAppPurchaseHistory to true in its Info.plist (iOS 18 and later), which keeps finished consumables in that history.

    Path B · Adapty (React Native)

    ~5 min

    Step 1 — Write an Adapty purchase controller

    purchase buys the product through Adapty and reports the outcome; user cancellation must be reported as cancelled and a pending purchase as pending, never as a failure. Hand BillDog the store's evidence that Adapty returns: the Play purchase token on Android, and Apple's signed transaction (jwsTransaction) on iOS. BillDog's server verifies it with the store.

    Don't skip the iOS evidence. Without it, BillDog finds a subscription or a non-consumable in StoreKit at its next sweep, but a consumable that Adapty has already finished is gone from StoreKit's history. BillDog's server never accepts a bare Apple transaction id from an app, so that purchase is never recorded.

    import { Platform } from 'react-native';
    import { adapty } from 'react-native-adapty';
    import { StoreEvidence, type PurchaseController } from '@billdog.io/react-native';
    
    // An Adapty placement whose paywall lists every product your BillDog paywalls sell.
    const ADAPTY_PLACEMENT_ID = 'your_adapty_placement_id';
    
    async function findAdaptyProduct(productId: string) {
      const flow = await adapty.getFlow(ADAPTY_PLACEMENT_ID);
      const products = await adapty.getPaywallProducts(flow);
      return products.find((p) => p.vendorProductId === productId);
    }
    
    const message = (e: unknown) => (e instanceof Error ? e.message : String(e));
    
    // Apple's transaction id, read from the signed transaction's base64url payload.
    // BillDog's server verifies the signature. Never throws: the purchase has happened.
    function appleTransactionId(jws: string): string | undefined {
      try {
        const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
        let json = '', bits = 0, acc = 0;
        for (const c of jws.split('.')[1]) {
          acc = ((acc << 6) | alphabet.indexOf(c)) & 0xffff;
          bits += 6;
          if (bits >= 8) { bits -= 8; json += String.fromCharCode((acc >> bits) & 0xff); }
        }
        const id = JSON.parse(json).transactionId;
        return typeof id === 'string' ? id : undefined;
      } catch {
        return undefined;
      }
    }
    
    export const adaptyPurchaseController: PurchaseController = {
      async purchase(productId) {
        try {
          const product = await findAdaptyProduct(productId);
          if (!product) {
            return { type: 'failed', error: { category: 'store', message: `Adapty has no product ${productId}` } };
          }
          const res = await adapty.makePurchase(product);
          if (res.type !== 'success') {
            return res.type === 'pending' ? { type: 'pending' } : { type: 'cancelled' }; // 'user_cancelled'
          }
    
          const purchaseToken = res.android?.purchaseToken;          // Android
          const jws = res.ios?.jwsTransaction;                        // iOS (StoreKit 2)
          const transactionId = jws ? appleTransactionId(jws) : undefined;
          return {
            result: { type: 'purchased', productId, transactionId: transactionId ?? '' },
            evidence: purchaseToken
              ? [StoreEvidence.googlePlay({ purchaseToken, productIds: [productId] })]
              : jws && transactionId
                ? [StoreEvidence.appStore({ transactionId, productId, signedTransaction: jws })]
                : [],
          };
        } catch (e) {
          return { type: 'failed', error: { category: 'store', message: message(e) } };
        }
      },
    
      async restorePurchases() {
        try {
          const profile = await adapty.restorePurchases();
          // Report what this device's store restored: an empty list keeps a BillDog
          // paywall open as "nothing to restore". BillDog also sweeps the store and
          // records what the device owns.
          const store = Platform.OS === 'ios' ? 'app_store' : 'play_store';
          const subscriptions = Object.values(profile.subscriptions ?? {})
            .filter((s) => s.isActive && s.store === store)
            .map((s) => ({ productId: s.vendorProductId, transactionId: s.vendorTransactionId,
                           originalTransactionId: s.vendorOriginalTransactionId }));
          const nonConsumables = Object.values(profile.nonSubscriptions ?? {}).flat()
            .filter((p) => !p.isConsumable && !p.isRefund && p.store === store)
            .map((p) => ({ productId: p.vendorProductId, transactionId: p.vendorTransactionId ?? '' }));
          return {
            type: 'restored',
            items: [...subscriptions, ...nonConsumables].map((item) => ({ ...item, status: { type: 'restored' as const } })),
          };
        } catch (e) {
          return { type: 'failed', error: { category: 'store', message: message(e) } };
        }
      },
    };

    Written for react-native-adapty 4.x (getFlow, makePurchase returning success / user_cancelled / pending with ios.jwsTransaction and android.purchaseToken). Older Adapty SDKs name these differently; check yours.

    Step 2 — Register the controller with BillDog

    import { adapty } from 'react-native-adapty';
    import { BillDog, BillDogConfiguration } from '@billdog.io/react-native';
    import { adaptyPurchaseController } from './adaptyPurchaseController';
    
    await adapty.activate('public_live_...');   // your existing Adapty setup
    
    BillDogConfiguration.configure({
      apiKey: 'bd_public_live_xxxxxxxx',
      purchaseController: adaptyPurchaseController,
    });
    
    // Log the user in to both SDKs: neither one follows the other.
    await BillDog.logIn(currentUserId);
    await adapty.identify(currentUserId);

    From now on every purchase from a BillDog paywall, and every BillDog.purchase call, runs your controller. BillDog never finishes or acknowledges a transaction in this mode: Adapty does.

    On the web

    @billdog.io/web takes your purchase code as a purchaseAdapter. A BillDog paywall's buy button calls its purchaseProduct(productId); resolve true when the purchase completed. BillDog then tracks a purchase_completed event (product only: no price and no transaction) and calls your delegate’s onPurchaseCompleted. That is all it does with the purchase: it does not record a transaction, count revenue or grant an entitlement for it. Access stays with your vendor.

    The paywall’s Restore button calls your adapter’s restore() when it has one: answer with what your vendor restored, and the paywall closes when items is not empty and stays open (“nothing to restore”) when it is. restorePurchases() is still required, and is used when there is no restore(): true closes the paywall too, but names nothing, so BillDog.restore() and onRestoreCompleted report no items.

    import BillDog from '@billdog.io/web';
    
    // Your own web purchase code (for example, your vendor's web SDK).
    declare function buyWithMyVendor(productId: string): Promise<boolean>;
    // The purchases your vendor restored for this customer.
    declare function restoreWithMyVendor(): Promise<Array<{ productId: string; transactionId: string }>>;
    
    BillDog.configure({
      apiKey: 'bd_public_live_xxxxxxxx',
      purchaseAdapter: {
        purchaseProduct: (productId) => buyWithMyVendor(productId),
        // What your vendor restored. BillDog calls this when it is there.
        restore: async () => ({ type: 'restored', items: await restoreWithMyVendor() }),
        // Required: whether anything was restored.
        restorePurchases: async () => (await restoreWithMyVendor()).length > 0,
        getAvailableProducts: async () => [],
      },
    });

    Show the paywall

    ~2 min

    Once your purchase code is registered, showing a BillDog paywall is the same as without it. The buy button routes through your code, so the real transaction still runs on your vendor.

    // React Native: fetch the placement's config, check entitlement, present if needed.
    const result = await BillDog.register('onboarding');
    
    // Web
    await BillDog.presentPaywall('onboarding');

    Verify it works

    Present a BillDog paywall and tap a product: your vendor's purchase sheet appears.
    Complete a sandbox purchase: it settles in RevenueCat / Adapty as usual.
    React Native: the purchase shows up for the customer in BillDog once BillDog has recorded it from the store.
    A purchase_completed event shows up in BillDog Product Analytics.
    Cancel a purchase: your controller reports cancelled, and nothing is recorded.

    Common pitfalls

    Reporting a cancel as a failure

    Map Adapty's user_cancelled to { type: 'cancelled' } and pending to { type: 'pending' }. Reporting either as failed tells BillDog the purchase failed.

    Product missing from the Adapty placement

    The controller can only buy products the Adapty placement's paywall lists. Add every product your BillDog paywalls sell to it.

    Logging in to one SDK only

    Neither SDK follows the other's identity. Call BillDog.logIn and adapty.identify (or Purchases.logIn) with the same user id.

    Expecting BillDog to charge the card

    It never does. If no purchase happens, check the vendor SDK — the transaction lives entirely in RevenueCat / Adapty.

    Related Documentation

    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.