Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Stripe Connect in an iOS app

Has anyone had success using Stripe connect with an iOS app. I have a few questions:

I'm following the guidelines here: https://stripe.com/docs/connect/getting-started

Registering an Application: easy, no problem here

Then a little further down:

Send your users to Stripe: again, easy no problem here, I just have a button that opens up the link in a UIWebView. I assume having the client_id in the URL is fine? A lot of my uncertainty is what IDs/keys I should hard-code into the app

Then a little further down:

After the user connects or creates a Stripe account, we'll redirect them back to the redirect_uri you set in yourapplication settings with a code parameter or an error.

What I'm doing here is using the UIWebview's webView:shouldStartLoadWithReqest:navigationType delegate method to check for the string "code=" in the URL. If it finds that, then I'm able to grab the "code" parameter. So in reality, the redirect_uri is completely unnecessary for me. Is this the right way to handle this? Should I be doing this within my app or on my server?

After receiving the code, we are supposed to make a POST call to receive an access_token. Again, should this be done within the app or on the Server? It requires the use of a secret_key, so I'm guessing server? And how do I send credit card information along with this token if the token needs to be sent to the server? I know how to obtain the card number, exp date, and CVV. But in terms of passing it to the server (with or without the token) is something I'm not sure of.

Then when it comes to actually writing PHP, Ruby, or Python code on the server, I'm at a total loss.

Any help would be greatly appreciated.

like image 999
Choppin Broccoli Avatar asked Nov 08 '13 18:11

Choppin Broccoli


People also ask

Can Stripe be used in iOS apps?

You can use any of Stripe's supported payment methods and Apple Pay in your iOS app to sell physical goods (for example, groceries and clothing) or for services your business provides (for example, club memberships and hotel reservations).

Can you use Stripe in an app?

Stripe Terminal can easily be integrated with a mobile application via our iOS or Android SDK. From there, our pre-certified card readers can be used to collect in-person payments. Did this answer your question?

How do I integrate payments with Stripe?

Find a guide to integrate Stripe's payments APIs. Build a payment form or use a prebuilt checkout page to accept online payments. Set up recurring billing for your SaaS or e-commerce business. Set up your bank account to receive payouts.


Video Answer


2 Answers

You should setup a small web app to create stripe charges and storing you customers Authorization Code. Configure two routes in your web app for redirect_uri and webhook_uri and add the url in your Stripe Apps settings. The charges should be created from a server side app because it requires the secret_key / authorization_code which should not be stored in an iPad app. Otherwise they may lead to a security leak. I'm trying to describe the concept below:

  1. Provide the stripe connect button in your app and set the link to open in Safari (not in an web view). You should add a state parameter to the url with an id which is unique to your users.

  2. On tapping the button your user will be redirected to Stripe where s/he will be asked to authorize your application. Upon authorization stripe will hit your redirect_uri with a authorization_code and the state you previously provided. Do a post call according to Stripe Documentation with the authorization_code to get an access_token. Store the access_token mapped with the state in a database.

  3. Define a custom url scheme in your app. Invoke the custom url from your web app. The user supposed to open the url in mobile safari. So invoking the custom url will reopen your application. You can pass an additional parameter to indicate failure / success. In your app update the view based on this parameter.

  4. Now you are all set to create a charge on your server on behalf of the iPad user. Use stripe iOS sdk to generate a card_token from the card information. It'll require your stripe publishable_key. Then define an api in your web app which takes 3 parameters: card_token, user_id and amount. Call this api from your iPad app whenever you want to create a charge. You can also encrypt this information with a key if you're worried about security using any standard encryption method. You can easily decrypt the info in your web app as you know the key.

  5. When this api is called from the iPad app you'll receive the user_id (which you saved as state previously), card_token and amount. Retrieve the access_token mapped to the user_id (or state). You can then made a charge on behalf of the user using the access_token, card_token and amount.

You can use ruby / php / python / node in the server as Stripe provides sdk for them. I assume other languages can be used as well as there is a REST interface.

Please note that this is just a concept. It should work like it but I haven't implemented it yet. I'll update this answer with sample code when I'm done.

like image 171
rushafi Avatar answered Oct 01 '22 16:10

rushafi


You can use UIWebView. You will still need to use redirect urls and monitor the redirect using the delegate "webView:shouldStartLoadWithRequest:navigationType:"

like image 29
HungryMonkey Avatar answered Oct 01 '22 16:10

HungryMonkey