title: Passing the User ID between an iOS app and Rails backend for In-App Purchases
body: <p>I've got a Turbo-enabled Rails app and a <a href="https://github.com/hotwired/turbo-ios" rel="nofollow noreferrer">Turbo Native</a> iOS app.</p>
  <p>On the web app, you can purchase subscriptions via Stripe, and so I need to enable the iOS app users the ability to purchase within the app.</p>
  <p>So far, I've got the following set up:</p>
  <ul>
  <li><p>When in the native app, when the user hits the &quot;Buy&quot; button, the correct payment request is sent to Apple's servers and the &quot;Purchase&quot; interface pops up</p>
  </li>
  <li><p>Server notifications from Apple are set up such that an endpoint in my Rails app gets pinged when a subscription has been purchased, is renewed, or is cancelled with the receipt data. Right now, I'm just printing the JSON response to my logs.</p>
  </li>
  </ul>
  <p>What's the best way for me to connect the unique user ID from my web app to the Apple purchase?</p>
  <p>What happens at the moment is that my Sandbox iCloud user is marked as subscribed, but that information is not connected to the app's logged in user, so they don't have access to the paid tier features.</p>
  <p>This is the ideal workflow:</p>
  <ul>
  <li><p>A user hits &quot;Buy&quot; in the app and confirms the payment</p>
  </li>
  <li><p>When I get a successful server notification from Apple I'm able to mark that user as paid and create a subscription object for them, storing the original transaction id and other relevant subscription information</p>
  </li>
  <li><p>The user is redirected to another page/view within the app once the purchase is complete</p>
  </li>
  <li><p>When Apple sends further server notifications, I can match up the original transaction id with the subscription in my Rails app DB and update the user's access/subscription as is necessary.</p>
  </li>
  </ul>
  <p>The main thing is linking the payment with the user in my Rails app backend.</p>
  <p>Has anybody successfully set up such a workflow?</p>
  <p>I'd love some guidance on how to approach it.</p>
  <p>Thank you very much!</p>