【问题标题】:Parse Server + Stripe Connect - iOS解析服务器 + 条纹连接 - iOS
【发布时间】:2017-03-14 05:25:14
【问题描述】:

如何使用 Stripe Connect 设置 Parse Server?我的日子过得很苦……

我正在尝试将我的 Parse 服务器(托管在 Heroku 上)与 Stripe Connect 集成(这与标准 Stripe 不同,它允许您(应用程序)在收取“手续费”的同时将付款转移给第三方仅使用 Parse Server + Xcode(因为这是我所熟悉的)。

例如,Lyft 会从客户的信用卡中扣款,收取一定比例的行程费用,然后将余额转给司机。如何在 Stripe 中自动执行此操作?!

【问题讨论】:

    标签: ios heroku stripe-payments parse-server stripe-connect


    【解决方案1】:

    Stripe 的文档没有给我一个明确的例子,我挣扎了好几个小时……嗯,我终于明白了,想和你分享。希望你们都觉得这很有用:

    假设:

    • 您在 Stripe 上有一个帐户
    • 您已将 Stripe 添加到您的 Parse Server example here。如果您不明白,请给我留言了解详情。
    • 您已将 Stripe SDK 添加到您的 Xcode 项目中
    • 您已经在 Parse 服务器上设置了云代码(如果混淆,请再次发送消息)

    好的,所以我们要从信用卡中收取费用,向第三方付款,但要保留“费用”。首先,您将转到 Stripe.com 仪表板(单击屏幕右上角,查看所有选项)。然后单击连接并填写信息。

    重要提示:您无需填写“重定向 URI”字段。

    好的,现在我们需要创建一个 CONNECTED STRIPE 帐户。我们通过云代码做到这一点:

    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
            }
        });
    });
    

    此帐户由第三方管理。当您运行此代码时,它将为此第三方创建一个 Stripe 帐户并向他们发送一封电子邮件(到列出的电子邮件)。基本上,电子邮件会指示他们登录、输入密码并输入银行帐户。当他们激活帐户时,它将“连接”到您的帐户。

    连接后,现在是时候编写“充卡”方法了:

    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
            }  
        });
    });
    

    最后,快速浏览左侧导航窗格中的“关联账户”选项:

    哇。你已经完成了。

    希望这会有所帮助。如果您有任何问题,请告诉我。

    【讨论】:

    • 1.如何将 Stripe 添加到 Parse Server 2. 除了这两个云功能之外,我还需要其他功能吗? 3. 如何创建客户账号,是在iOS部分完成的吗?
    • 以及如何创建 ephemeralKeys?并获取 customerID
    猜你喜欢
    • 1970-01-01
    • 2015-12-09
    • 2016-07-26
    • 2018-08-22
    • 1970-01-01
    • 2018-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多