Ibdakine
Ibdakine

Reputation: 514

Parse Server + Stripe Connect - iOS

How do you setup Parse Server with Stripe Connect? 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).

For example, Lyft charges the customer's credit card, takes a percentage of the ride, and the remaining balance is transferred to the driver. How do I do this in Stripe automatically?!

Upvotes: 0

Views: 553

Answers (1)

Ibdakine
Ibdakine

Reputation: 514

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. Hope you all find this useful:

Assumptions:

  • You have an account on Stripe
  • You've added Stripe to your Parse Server example here. If you don't understand, message me for details.
  • You've added Stripe SDK to your Xcode project
  • You've setup Cloud Code on your Parse Server (again message if confused)

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). Then click CONNECT and fill out the info.

IMPORTANT: YOU DO NOT NEED TO FILL OUT THE FIELDS "REDIRECT URI".

First fill out the required info

OK so now we need to create a CONNECTED STRIPE ACCOUNT. 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: '[email protected]' //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). 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:

occurs after you turn on Connected Accounts

Walah. You are done.

Hope this helps. Let me know if you have any questions.

Upvotes: 4

Related Questions