<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Lucas</title>
    <description>The latest articles on DEV Community by Lucas (@_9848c5582063b42abecb7).</description>
    <link>https://dev.to/_9848c5582063b42abecb7</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3915788%2Fb07257c2-824f-43cb-b42e-635e733556bf.png</url>
      <title>DEV Community: Lucas</title>
      <link>https://dev.to/_9848c5582063b42abecb7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/_9848c5582063b42abecb7"/>
    <language>en</language>
    <item>
      <title>I built my own IAP backend instead of using RevenueCat — what 3 weeks of pain taught me</title>
      <dc:creator>Lucas</dc:creator>
      <pubDate>Wed, 06 May 2026 11:36:34 +0000</pubDate>
      <link>https://dev.to/_9848c5582063b42abecb7/i-built-my-own-iap-backend-instead-of-using-revenuecat-what-3-weeks-of-pain-taught-me-1l06</link>
      <guid>https://dev.to/_9848c5582063b42abecb7/i-built-my-own-iap-backend-instead-of-using-revenuecat-what-3-weeks-of-pain-taught-me-1l06</guid>
      <description>&lt;p&gt;I'm shipping a subscription-based React Native app and went through the&lt;br&gt;
"do I use RevenueCat or roll my own?" question that probably every solo&lt;br&gt;
RN dev hits. I ended up rolling my own, ran into more edge cases than I&lt;br&gt;
expected, and eventually pulled the working backend into an MIT package.&lt;br&gt;
Sharing the post-mortem in case it saves someone else the same weeks.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why not RevenueCat
&lt;/h2&gt;

&lt;p&gt;To be clear — RevenueCat is good. For a lot of apps it's the right call.&lt;br&gt;
Two things pushed me off it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Revenue share scales with you.&lt;/strong&gt; 1% after $2.5K MRR is fair pricing,
but it's a surface I want to own for the lifetime of the product, not
rent.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;My subscription state lives in their DB.&lt;/strong&gt; I still need to mirror
"user X is subscribed" into my own Postgres to join with the rest of
my data, which means I'm running a webhook handler from them either
way. Felt like I was paying to add a hop.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So I started writing it myself. Here's where the time actually went.&lt;/p&gt;
&lt;h2&gt;
  
  
  Where the time went
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Apple StoreKit 2 JWS verification (~2 days)
&lt;/h3&gt;

&lt;p&gt;You don't just trust the JWT. You walk the &lt;code&gt;x5c&lt;/code&gt; chain in the JWT&lt;br&gt;
header, verify each certificate against Apple Root CA G3, then verify&lt;br&gt;
the JWT signature against the leaf cert's public key. None of the&lt;br&gt;
tutorials I found did the full chain — most just decoded the payload&lt;br&gt;
and hoped.&lt;/p&gt;
&lt;h3&gt;
  
  
  Google Play Developer API v3 (~1 day)
&lt;/h3&gt;

&lt;p&gt;OAuth2 service account is fine. The non-obvious bit: use&lt;br&gt;
&lt;code&gt;purchases.subscriptionsv2.get&lt;/code&gt; — it returns a &lt;code&gt;subscriptionState&lt;/code&gt;&lt;br&gt;
enum that maps cleanly to lifecycle states. The v1 API doesn't, and&lt;br&gt;
most Stack Overflow answers still reference v1. Don't infer state from&lt;br&gt;
&lt;code&gt;expiryTimeMillis&lt;/code&gt; + &lt;code&gt;cancelReason&lt;/code&gt;, just read the enum.&lt;/p&gt;
&lt;h3&gt;
  
  
  Lifecycle state classification (~3 days)
&lt;/h3&gt;

&lt;p&gt;This is where it got nasty. Apple's &lt;code&gt;DID_FAIL_TO_RENEW&lt;/code&gt; with subtype&lt;br&gt;
&lt;code&gt;GRACE_PERIOD&lt;/code&gt; vs &lt;code&gt;GRACE_PERIOD_EXPIRED&lt;/code&gt;. Google's &lt;code&gt;IN_GRACE_PERIOD&lt;/code&gt;,&lt;br&gt;
&lt;code&gt;ON_HOLD&lt;/code&gt;, &lt;code&gt;SUBSCRIPTION_PAUSED&lt;/code&gt;. I needed an &lt;code&gt;active: boolean&lt;/code&gt; for&lt;br&gt;
gating but also the raw state for UX (showing "your card failed but&lt;br&gt;
you still have access" is a legitimately different message than "your&lt;br&gt;
subscription is on hold"). Collapsing both vendor's events into one&lt;br&gt;
state machine took a few rewrites.&lt;/p&gt;
&lt;h3&gt;
  
  
  The 3-day refund trap
&lt;/h3&gt;

&lt;p&gt;Google auto-refunds any purchase you don't &lt;code&gt;acknowledgePurchase&lt;/code&gt; within&lt;br&gt;
3 days. My first version didn't call it. None of the RN tutorials I&lt;br&gt;
followed mentioned it. Lost a handful of test purchases before I&lt;br&gt;
noticed pattern in the dashboard. Subscriptions need acknowledgement&lt;br&gt;
too, not just one-time IAP.&lt;/p&gt;
&lt;h3&gt;
  
  
  Webhook miss recovery
&lt;/h3&gt;

&lt;p&gt;Apple's App Store Server Notifications V2 are reliable but not&lt;br&gt;
guaranteed. If you miss one, the user's status drifts. Solution:&lt;br&gt;
direct fetch via App Store Server API on &lt;code&gt;/status&lt;/code&gt; checks, treat&lt;br&gt;
webhooks as "fast path" not "only path." Same for Google — RTDN can&lt;br&gt;
drop, fall back to &lt;code&gt;subscriptionsv2.get&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  What I extracted
&lt;/h2&gt;

&lt;p&gt;Once it was working in production, none of the above was app-specific.&lt;br&gt;
So I pulled it out: &lt;a href="https://github.com/jeonghwanko/onesub" rel="noopener noreferrer"&gt;github.com/jeonghwanko/onesub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;createOneSubMiddleware&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MIT licensed. Pluggable subscription store (PostgreSQL built-in,&lt;br&gt;
implement the interface for Redis / whatever). Optional RN SDK&lt;br&gt;
(&lt;code&gt;useOneSub()&lt;/code&gt; hook + paywall component) but the server works with any&lt;br&gt;
client — Flutter, native, plain fetch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Honest limitations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No analytics dashboard yet.&lt;/strong&gt; RevenueCat's actual moat is cohort
retention / LTV / experiments, not the receipt validation. There's a
self-hosted Docker dashboard but it's operational (active counts,
failed webhooks) — not cohort analysis.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No hosted version.&lt;/strong&gt; You run your own server. If "I want to ship
an MVP without running infra" is the goal, RevenueCat still wins.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Apple Family Sharing and Promotional Offers&lt;/strong&gt; aren't implemented
yet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Things I think turned out interesting
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;An MCP server is bundled — point Claude Code or Cursor at it and you
can say "add a monthly subscription to this Expo app" and it
generates the App Store Connect product, the Play Console product,
and the client integration. Not the main feature but it's the part
that surprised me with how much friction it removed.&lt;/li&gt;
&lt;li&gt;296+ tests, including multi-notification e2e scenarios for the
lifecycle stuff above. That's where most of the bugs live.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I'm asking
&lt;/h2&gt;

&lt;p&gt;If you've shipped IAP yourself in RN — what edge case tripped you up&lt;br&gt;
that I haven't listed? Curious if there's a class of bug I haven't&lt;br&gt;
hit yet. Especially interested in hearing from anyone who's dealt with&lt;br&gt;
Family Sharing or upgrade/downgrade chains in production.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Repo: &lt;a href="https://github.com/jeonghwanko/onesub" rel="noopener noreferrer"&gt;github.com/jeonghwanko/onesub&lt;/a&gt; — MIT licensed. Issues and PRs welcome.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>expo</category>
      <category>opensource</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
