This is currently only available on iOS.
Add subscriptions and one-time purchases to your Ruby Native app. Your users purchase directly in the app via Apple's StoreKit and your Rails app handles the rest. No third-party services required.
In-app purchases work on every plan, on iOS. Google Play Billing is not supported yet.
on_subscription_change callback.Run the IAP generator to create the purchase intents migration:
bin/rails generate ruby_native:iap
bin/rails db:migrate
Then add your app's bundle ID to config/ruby_native.yml, the same one you entered during Apple onboarding in the Ruby Native dashboard:
ios:
bundle_id: com.example.myapp
Ruby Native checks every purchase, restore, and webhook against it and rejects a transaction made in any other app. Without it, purchases still work but skip that check, and your server logs a warning. If you already set bundle_id for linked domains, you're done. Requires Ruby Native 0.21.0.
Add your callback in config/initializers/ruby_native.rb. This fires for every purchase event (new purchase, renewal, cancellation, refund), for subscriptions and one-time purchases alike.
# config/initializers/ruby_native.rb
RubyNative.on_subscription_change do |event|
user = User.find_by(id: event.owner_token)
next unless user
subscription = user.subscription || user.build_subscription
subscription.update!(
product_id: event.product_id,
original_transaction_id: event.original_transaction_id,
status: event.status,
expires_at: event.expires_date
)
end
| Method | Description |
|---|---|
event.type |
"subscription.created", "subscription.updated", "subscription.canceled", or "subscription.expired". For one-time purchases, "purchase.created", "purchase.updated", or "purchase.refunded" |
event.status |
"active" or "expired" |
event.owner_token |
Your user/customer identifier (passed when creating the purchase) |
event.product_id |
Apple product ID (e.g., com.yourapp.pro.monthly) |
event.original_transaction_id |
Apple's identifier for the subscription |
event.transaction_id |
Apple's identifier for this specific transaction |
event.purchase_date |
When this transaction was purchased |
event.expires_date |
When the current period ends. nil for one-time purchases |
event.environment |
The Apple environment the event came from (production or sandbox) |
event.active? / event.expired? |
Status checks |
event.created? / event.canceled? / event.refunded? |
Type checks |
event.one_time? |
true for a one-time purchase, like a lifetime unlock |
Renewals, plan changes, and auto-renew toggles all arrive as subscription.updated; a refund arrives as subscription.expired. If you follow the example above and mirror event.status and event.expires_date into your own model, every type is already handled and you rarely need to branch on event.type at all. Note that canceled still reports an "active" status: the user turned off auto-renew but keeps access until the period ends.
A non-consumable product, like a lifetime unlock or a premium content pack, uses the same paywall markup and the same callback. Its events arrive as purchase.created when it's bought or restored and purchase.refunded when Apple refunds it, with an "expired" status. Check event.one_time? to store it separately from a subscription:
RubyNative.on_subscription_change do |event|
user = User.find_by(id: event.owner_token)
next unless user
if event.one_time?
user.update!(premium: event.active?)
else
# Mirror the subscription, as above.
end
end
The purchase button reads "Purchased!" instead of "Subscribed!" after a one-time purchase. Requires Ruby Native 0.21.2.
Apple delivers renewals, cancellations, and refunds as App Store Server Notifications sent directly to your Rails app. The gem mounts the receiving endpoint at /native/webhooks/apple and handles verification and parsing; each event reaches your app through the callback above.
Point Apple at your app once:
https://yourapp.com/native/webhooks/apple with your production domain, and choose Version 2 notifications.
Create a paywall page with signal elements. The native app detects these and wires up StoreKit automatically. Use the product IDs from App Store Connect. You can find them in your app's Purchases tab in the Ruby Native dashboard after syncing.
<%# app/views/paywalls/show.html.erb %>
<h1>Upgrade to Pro</h1>
<div data-native-purchase="com.yourapp.pro.monthly"
data-native-customer-id="<%= current_user.id %>"
data-native-success-path="<%= dashboard_path %>">
<p>
Monthly: <span data-native-price="com.yourapp.pro.monthly">$9.99</span>/month
</p>
<button type="submit">Subscribe</button>
</div>
<button data-native-restore>Restore purchases</button>
| Attribute | Description |
|---|---|
data-native-purchase="PRODUCT_ID" |
Container for a purchasable product. Tapping the submit button inside triggers StoreKit. |
data-native-customer-id="ID" |
Your user identifier. Passed back in the owner_token event field. |
data-native-success-path="/path" |
Where to navigate after a successful purchase. |
data-native-price="PRODUCT_ID" |
Replaced with the localized price from Apple (e.g., "$9.99"). |
data-native-restore |
Tapping this element restores previous purchases. |
The data-native-price element shows a fallback price in HTML until Apple loads the real price. This means your paywall works on the web too.
Signal elements work however your page renders them: a Turbo visit, an Inertia visit, or a React or Vue component that mounts later. The paywall doesn't need a full page load.
Deploy your Rails app. Every build includes in-app purchases, so an app already in the store picks up your paywall with the deploy. An app built on Ruby Native 0.17 or earlier needs one update first: update Ruby Native and deploy an update.
Apple provides a sandbox environment for testing purchases without real charges. Create a sandbox tester account in App Store Connect and sign in on your test device under Settings, then App Store, then Sandbox Account.
Sandbox subscriptions renew on an accelerated schedule:
| Duration | Sandbox renewal |
|---|---|
| 1 week | 3 minutes |
| 1 month | 5 minutes |
| 3 months | 15 minutes |
| 6 months | 30 minutes |
| 1 year | 1 hour |