DEV Community

Silvia Satoar Plabon
Silvia Satoar Plabon

Posted on • Updated on

Stripe Multipartner platform for the express or custom-connected account.

If you wish to run a business with a number of merchants, you must use a multi-partner platform service from Stripe. There are three sorts of accounts that may be used for a multi-partner platform. A standard linked account can only accept direct charges, but a custom or express connected account can accept destination charges as well as separate costs/transfers. You can select an account based on your charge type.
Let's pick the option of a charge and after that, we can select an account type.

Now, I am expressing my integrated business requirements. The platform will pay stripe fees. So, if a user purchased a product for 100 $, the platform will deduct the application fee, and stripe fees, and after that platform will forward merchant money. But charges are not fixed for every suborder.
If I choose direct charges, the money will be paid to the merchant account first if a user spends $100 on products. The merchant will then send the platform-determined application cost. Stripe fees will be charged to merchants, and merchants will be accountable for refunds, fees, and chargebacks. Because the platform will pay Stripe fees, this option is not appropriate. If this option matches your business requirements, you can select it.

If my selected option is destination charges then If a user spends $100 on items, the money initially goes to the platform account, which matched my integrated business first requirement. Following that, the platform will collect the application fee, which is set by the platform. Stripe fees will be paid by the platform, and the remaining cash will be sent to merchant accounts.

But, for my integrated business, each suborder will have distinct pricing (ex: shipping cost, tax, etc). Because my integrated business will pay Stripe fees, direct charges are not an option. When I pick destination charges, I am unable to apply separate costs. As a result of the fees, I need to transfer money from the platform to the merchant. There is just one choice that will answer my question. It will transfer money from the user to the platform. The platform can compute how much the costs will be for each suborder and how much the merchant will receive, and he will transfer the leftover money to the merchant. So, I will use separate charges and transfers for my integrated business.

Now, I picked separate charges and transfers. So, I am not able to use a standard account. For Standard connected accounts, the account debit service won't work. But for my integrated business, I may need to deduct extra charges from merchants as they will use platform services(ex: dashboard, ad service, etc).

Depending on my integrated business requirement I need to pick either an express or custom-connected account. if I choose a custom connected account, the integration effort will be more from an express connected account. For express accounts, stripe and platform both can provide service and one great thing are that user can access the dashboard. But for the customer account, the user can't access the dashboard and user support will be provided by the only platform. But for my business, there will be an easier integration process if I use an express-connected account. There have no price differences between express and connected accounts, every month need to pay 2 dollars for every active connected account. you can also check this link to get the differences between accounts.

Step 1: create your stripe connection

const stripe = require('stripe')(STRIPE_API_KEY);
Enter fullscreen mode Exit fullscreen mode

here, you just need to place your API key.

Step 2: Create an account
According to your company, you can submit extra parameters when creating a connected account at this link, which will prevent a repeat request for this information throughout the onboarding process.

const account = await stripe.accounts.create({
  "company": {
        "name": "Demo Business",
        "tax_id": "xxxxxxxx",
        "phone": "0000000000",
        "address": {
            "city": "Washington",
            "state": "DC",
            "postal_code": "20001",
            "line1": "United States, DC, Washington, U St NW"
        }
    },
    "metadata": {
        "email": "x@gmail.com",
        "merchantId": "1"
    },
    "business_profile": {
        "url": "https://xxxxxxxxxxxx.com"
    },
    "type": "express",
    "business_type": "company",
    "capabilities": {
        "card_payments": {
            "requested": true
        },
        "transfers": {
            "requested": true
        }
    },
    "email": "x@gmail.com"
});
Enter fullscreen mode Exit fullscreen mode

Here, I've included information on the company, metadata, business profile, type, business type, capabilities, and email. Depending on the sort of business you operate, more information may be provided.
Step 3: Complete your onboarding process.
Your account was created. But stripe needs more information related to your business. So, the connected account users need to complete this process, otherwise, the account won't work.

const accountLink = await stripe.accountLinks.create({
  account: '{{CONNECTED_ACCOUNT_ID}}',
  refresh_url: 'https://example.com/reauth',
  return_url: 'https://example.com/return',
  type: 'account_onboarding',
});
Enter fullscreen mode Exit fullscreen mode

Replace the CONNECTED ACCOUNT ID with your newly formed linked account id below. Your merchant account must be redirected to the account link URL. If something goes wrong (expired, refused, etc. ), refresh _url will take you back to your website. If you completed the onboarding process, the return URL will redirect after entering the onboarding process data; however, this does not mean that your account is ready for use or that your onboarding process is ended.

const account = await stripe.accounts.retrieve(
 CONNECTED_ACCOUNT_ID
);
Enter fullscreen mode Exit fullscreen mode

Now you need to check the details_submitted and charges_enabled keys. If the details submitted or charges enabled are false, then you need to redirect your connected account users to the Stripe Express dashboard for completing the rest process or solving issues.

const loginLink = await stripe.accounts.createLoginLink(
  CONNECTED_ACCOUNT_ID
);
Enter fullscreen mode Exit fullscreen mode

Stripe will do their verification process. it will take less time. We can use webhook and through webhook, if the charges enabled are changed to true, we can send an email to the merchant. Therefore, the merchant may now access his dashboard and administer his business. Without payment, product purchasing won't happen, so you just need to block a connected account whose charges_enabled are false.
Our company is finally ready, but how will users pay? I will show payment and issue a refund. Let's get started.

STEP 4: Create a Checkout session

const checkoutData={
    "mode": "payment",
    "success_url": "https://a.com",
    "cancel_url": "https://a.com",
    "line_items": [
        {
            "price_data": {
                "product_data": {
                    "name": "Car"
                },
                "unit_amount_decimal": 108000,
                "currency": "USD"
            },
            "quantity": 1
        }
    ],
    "metadata": {
        "transactionDetails": "[{\"productData\":[{\"name\":\"Car\",\"quantity\":1,\"price\":108000},{\"name\":\"Ship+Tax(suborder id)\",\"quantity\":1,\"price\":7020}]}]"
    },
    "payment_intent_data": {
        "transfer_group": "xh701Ek1677392840752",
        "capture_method": "automatic"
    }
}
stripe.checkout.sessions.create(checkoutData, unique key).catch();
Enter fullscreen mode Exit fullscreen mode

Here, if the user needs to cancel the payment and return to your website you need to enter cancel_url. if payment is successful then it will redirect to success_url.
Here, I am using the mode of checkout session as payment. As you are using the multi-partner platform, a user can purchase from multiple merchants. So, inside of payment_intent_data, you need to provide transfer_group, so it can identify that resulting payment as part of a group. capture_method will determine when you need to capture money from the customer account. So, you can handle capturing money manually. you can store metadata for getting more information about an order. As, for my business, the platform will pay stripe fees, which I will process money from the platform to the merchant by keeping platform fees. you can specify application_fee_amount. Please have a look at this page, you can use the key whichever you want.

STEP 5: Update Your Order Status
your payment succeeded or failed? let's wait for payment_intent.succeeded webhook. Now you can update your order status and process money to the merchant.

 await this.client.transfers.create({
      amount: amount,
      currency: DEFAULT_CURRENCY,
      source_transaction: sourceTransactionId,
      destination: destinationAccountId,
      metadata: {transactionDetails: JSON.stringify(destinationDetails)},
      transfer_group: transferGroup,
    }, uniqueKey)
        .then((res) =>

          ))
        .catch(async (err) => {}
Enter fullscreen mode Exit fullscreen mode

You must enter the amount that you will send to the seller. Assume a consumer purchases $100 goods, with shipping and tax expenses of $10 and Stripe fees of $10; therefore, the platform must deliver $80 to the merchant. You may utilize the suborder loop to handle merchant money by calculating suborder money. Enter the sourceTransactionId and destinationAccountId here. You may also enter metadata.

STEP 6: Refund Process
Now, if a user cancels or returns a purchase, how will we handle the money? Can we refund the user? Will it deduct payment fees again? This sort of question will occur to you. Stripe will not charge you any fees for a refund. You can get a full or partial refund.

const refund = await stripe.refunds.create({
  charge: chargeId,
});
Enter fullscreen mode Exit fullscreen mode

if you need a partial refund, then specify the amount.
But, because the platform will be paying Stripe fees, they must obtain them from the merchant. As a result, we must deduct money from the merchant because they will incur payment charges.

 await stripe.charges.create({
        amount: amount,
        currency: "usd",
        source: destinationAccountId,
        metadata: metadata,
      });
Enter fullscreen mode Exit fullscreen mode

We may take money out of the merchant stripe account because we are utilizing the express account. Stripe, however, will charge for each transaction. Depending on the amount of the refund, the merchant must pay the platform's costs. For instance, if you need to transfer $10 to a merchant, you must figure out how much you must pay Stripe to transmit $10. The account debit percentage is now fixed at 1.5 percent. Hence, you must first determine how much the stripe fees will cost for 10 dollars. Next, you must determine the stripe fees once more and how much they will cost. You must deduct both fees from the merchant. You may always deduct any kind of fee from the merchant.

STEP 7: Take A Deep Breath And Enjoy.
You may now manage your business profitably. Transfer money to my account as well. I'm joking.

Top comments (0)