简体   繁体   English

解析服务器+ Stripe Connect-iOS

[英]Parse Server + Stripe Connect - iOS

How do you setup Parse Server with Stripe Connect? 如何使用Stripe Connect设置Parse Server? I'm having a miserable time... 我现在很痛苦

I'm trying to integrate my Parse Server (hosted on Heroku) with Stripe Connect (this is different that standard Stripe, in it allows you (the app) to transfer payments to a third party while taking a 'processing fee' while ONLY USING Parse Server + Xcode (as this is all that I'm familiar with). 我正在尝试将我的Parse Server(托管在Heroku上)与Stripe Connect集成(这与标准Stripe不同,因为它允许您(该应用程序)将付款转账给第三方,同时仅收取“处理费”解析服务器+ Xcode(因为这是我所熟悉的全部)。

For example, Lyft charges the customer's credit card, takes a percentage of the ride, and the remaining balance is transferred to the driver. 例如,Lyft向客户的信用卡收费,占乘车费用的一部分,然后将剩余余额转移给驾驶员。 How do I do this in Stripe automatically?! 如何在Stripe中自动执行此操作?

Stripe's documentation did not give me an explicit example and I struggled for hours... Well, I finally got it and wanted to share it with you. Stripe的文档没有给我一个明确的例子,我花了好几个小时努力...好吧,我终于明白了,想与您分享。 Hope you all find this useful: 希望大家都觉得有用:

Assumptions: 假设:

  • You have an account on Stripe 您在Stripe上有一个帐户
  • You've added Stripe to your Parse Server example here . 您已在此处将Stripe添加到您的Parse Server 示例中 If you don't understand, message me for details. 如果您听不懂,请发消息给我。
  • You've added Stripe SDK to your Xcode project 您已将Stripe SDK添加到Xcode项目
  • You've setup Cloud Code on your Parse Server (again message if confused) 您已经在您的Parse Server上设置了Cloud Code(如果混淆,同样会显示消息)

OK, so we are going to charge a credit card, pay the third party, but keep a 'fee'. 好的,因此我们将收取信用卡费用,向第三方付款,但要保留“费用”。 First you'll go to the Stripe.com dashboard (click the top right of the screen, to view all of the options). 首先,您将转到Stripe.com仪表板(单击屏幕的右上角以查看所有选项)。 Then click CONNECT and fill out the info. 然后单击“连接”并填写信息。

IMPORTANT: YOU DO NOT NEED TO FILL OUT THE FIELDS "REDIRECT URI". 重要提示:您不需要填写“重定向URI”字段。

首先填写必填信息

OK so now we need to create a CONNECTED STRIPE ACCOUNT. 好的,所以现在我们需要创建一个CONNECTED STRIPE帐户。 We do this by cloud code: 我们通过云代码来做到这一点:

Parse.Cloud.define("createConnectedAccount", function(request, response) {

    var stripe = require('stripe')('YOUR_SECRET_KEY');

    stripe.accounts.create({
        managed: false,
        country: 'US',
        email: 'example@gmail.com' //THIS IS YOUR THIRD PARTY ACCOUNT EMAIL ADDRESS

}, function(err, account) {
        // asynchronously called
        if (err) {
            //other errror
             response.error(err); // return error
        } else {
            //no error
             response.success(account); // return charge success
        }
    });
});

This account is managed by the THIRD PARTY. 此帐户由第三方管理。 When you run this code, it will create a Stripe account for this third party and send them an email (to the email listed). 当您运行此代码时,它将为该第三方创建一个Stripe帐户,并向他们发送电子邮件(发送到列出的电子邮件)。 Basically, the email instructs them to Login, enter a password, and enter a bank account. 基本上,电子邮件会指示他们登录,输入密码和输入银行帐户。 When they activate the account, it will be 'connected' to your account. 当他们激活帐户后,该帐户将被“连接”到您的帐户。

Once connected, now it's time to write the "charge the card" method: 建立连接后,现在该编写“为卡收费”方法了:

Parse.Cloud.define("charge", function(request, response) {

    var stripe = require('stripe')('YOUR_SECRET_KEY');

    stripe.charges.create({

        amount: 100, //in CENTS
        currency: "usd",
        customer: request.params.customer, //customer is the id given by stripe when you create a customer. example: cus_EXAMPLE398FMFJKEP876 
        description: "example for people",
        application_fee: 25, //again, in CENTS

        }, {stripe_account: "3RD_PARTY_ACCOUNT_NUMBER"}, function(err, charge) { //the third party account number looks something like this acct_EXAMPLE352JFLE3207ME and can be found by clicking "Connected Accounts" (left side pane option after you set it up).
        // asynchronously called
        if (err && err.type === 'StripeCardError') {
            // The card has been declined
             response.error(err); // card declineded
        } else if (err) {
            //other errror
             response.error(err); // return error
        } else {
            //no error
             response.success(charge); // return charge success
        }  
    });
});

Lastly, a quick picture of the "connected accounts" option on the left navigation pane: 最后,在左侧导航窗格中快速浏览了“关联帐户”选项:

开启关联帐户后发生

Walah. Walah。 You are done. 大功告成

Hope this helps. 希望这可以帮助。 Let me know if you have any questions. 如果您有任何疑问,请告诉我。

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

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