Search code examples
iosruby-on-railsherokustripe-payments

How can I communicate iOS side with server side (Heroku)


I am implementing Stripe Payments in my iOS app and I obviously can't store credit card information over the iOS app so I have to create tokens and send that to the server to be charged etc.

My question is how can I communicate iOS => server and vice versa My web app is in Rails by the way. I read in some places that I might need to create a API on my server, then call it from my iOS side?

If anyone has an idea on how to do such a thing please let me know, I would appreciate it a lot.


Solution

  • Yes, you must create (or update) your Rails application to expose an HTTP API, which usually communicates using JSON. Your API will need to respond to POST/GET/whatever requests the iOS app make and behave correctly based on what you expect to do (do something with some tokens from my understanding).

    Please notice though that handling payments and not having already the knowledge on how to do such a thing might be dangerous for the end user.

    To give you a general overview of the process:

    • Create Rails routes, controllers, models required to manage the logic of perform a payment from a token, this is entirely your job unless the Rails app you are working with, already support this
    • Update your iOS app to send, probably with a POST request, the token you talked about, you'll probably need to define some sort of authentication protocol, look into JWT or something similar, you won't have cookies at your disposal in the iOS app

    It's a long but interesting task