简体   繁体   English

如何在iOS应用中使用Stripe Connect

[英]How to use Stripe Connect in an iOS app

Has anyone had success using Stripe connect with an iOS app. 有没有人成功使用Stripe连接iOS应用程序。 I have a few questions: 我有几个问题:

I'm following the guidelines here: https://stripe.com/docs/connect/getting-started 我遵循这些指南: 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. 将您的用户发送到Stripe:再次,这里没问题,我只需要一个按钮,在UIWebView中打开链接。 I assume having the client_id in the URL is fine? 我假设URL中的client_id很好吗? A lot of my uncertainty is what IDs/keys I should hard-code into the app 我的很多不确定性是我应该在应用程序中硬编码的ID /密钥

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. 用户连接或创建Stripe帐户后,我们会将它们重定向回您在应用程序设置中使用代码参数或错误设置的redirect_uri。

What I'm doing here is using the UIWebview's webView:shouldStartLoadWithReqest:navigationType delegate method to check for the string "code=" in the URL. 我在这里做的是使用UIWebview的webView:shouldStartLoadWithReqest:navigationType委托方法来检查URL中的字符串“code =”。 If it finds that, then I'm able to grab the "code" parameter. 如果它找到了,那么我就能抓住“代码”参数。 So in reality, the redirect_uri is completely unnecessary for me. 所以实际上,redirect_uri对我来说完全没必要。 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. 收到代码后,我们应该进行POST调用以接收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? 它需要使用secret_key,所以我猜服务器? 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. 我知道如何获得卡号,exp日期和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. 然后,当涉及到在服务器上实际编写PHP,Ruby或Python代码时,我完全失去了。

Any help would be greatly appreciated. 任何帮助将不胜感激。

You should setup a small web app to create stripe charges and storing you customers Authorization Code. 您应该设置一个小型Web应用程序来创建条带费用并为您存储客户授权代码。 Configure two routes in your web app for redirect_uri and webhook_uri and add the url in your Stripe Apps settings . 在您的Web应用程序中为redirect_uriwebhook_uri配置两个路由,并在Stripe Apps设置中添加URL。 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. 收费应该从服务器端应用程序创建,因为它需要secret_key / authorization_code,不应该存储在iPad应用程序中。 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). 在应用程序中提供stripe connect button ,并将链接设置为在Safari中打开(不在Web视图中)。 You should add a state parameter to the url with an id which is unique to your users. 您应该向URL添加一个state参数,其id对您的用户是唯一的。

  2. On tapping the button your user will be redirected to Stripe where s/he will be asked to authorize your application. 点击按钮后,您的用户将被重定向到Stripe,在那里他/她将被要求授权您的应用程序。 Upon authorization stripe will hit your redirect_uri with a authorization_code and the state you previously provided. 授权后,条带将使用authorization_code和您之前提供的state命中redirect_uri Do a post call according to Stripe Documentation with the authorization_code to get an access_token . 根据Stripe Documentation使用authorization_code进行一次post调用以获取access_token Store the access_token mapped with the state in a database. 将与state映射的access_token存储在数据库中。

  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. 因此,调用自定义URL将重新打开您的应用程序。 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. 现在,您已准备好代表iPad用户在服务器上创建费用。 Use stripe iOS sdk to generate a card_token from the card information. 使用条带iOS sdk从卡信息生成card_token It'll require your stripe publishable_key . 它需要你的条纹publishable_key Then define an api in your web app which takes 3 parameters: card_token , user_id and amount . 然后在您的Web应用程序中定义一个api,它包含3个参数: card_tokenuser_idamount Call this api from your iPad app whenever you want to create a charge. 无论何时想要收费,都可以从iPad应用程序中调用此api。 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 . 当从iPad应用程序调用此API时,您将收到user_id (您之前保存为state ), card_tokenamount Retrieve the access_token mapped to the user_id (or state). 检索映射到user_id (或state)的access_token You can then made a charge on behalf of the user using the access_token , card_token and amount . 然后,您可以使用access_tokencard_tokenamount代表用户card_token amount

You can use ruby / php / python / node in the server as Stripe provides sdk for them. 您可以在服务器中使用ruby / php / python / node,因为Stripe为它们提供了sdk。 I assume other languages can be used as well as there is a REST interface. 我假设可以使用其他语言,还有一个REST接口。

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. 我完成后,我会用示例代码更新这个答案。

You can use UIWebView. 您可以使用UIWebView。 You will still need to use redirect urls and monitor the redirect using the delegate "webView:shouldStartLoadWithRequest:navigationType:" 您仍然需要使用重定向URL并使用委托“webView:shouldStartLoadWithRequest:navigationType:”监视重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM