Ecommerce, PHP, Web Development
How to integrate Stripe Connect in On-Demand apps in PHP
By Goshila Sadaf · · Updated
In this article, we explain how to integrate the Stripe Connect payment gateway into on-demand applications using the Stripe PHP library. Stripe Connect is commonly used in marketplace and on-demand platforms where payments need to be split between the platform and service providers.
What are on-demand apps?
On-demand applications deliver services to customers through independent contractors or service providers who are paid via the platform. In many cases, the platform’s brand is central to the entire transaction. Rather than acting as a simple software provider, the platform manages pricing, ensures service quality, handles customer support, and oversees payments.
For example, in an on-demand service app, pricing is usually set by the platform. Although the service itself is delivered by a third party, the platform controls the user experience and payment flow from start to finish.
What are Stripe Connect Custom accounts?
When building an on-demand application with Stripe Connect, you typically need to create Custom accounts on behalf of your service providers. With Custom accounts, Stripe does not directly interact with your contractors. Instead, the platform is fully responsible for managing all required information and compliance.
With Stripe Connect Custom accounts, the platform must:
- Handle all identity verification requirements
- Set up bank accounts for contractor payouts
- Ensure contractors agree to platform terms and services
Integrating Stripe Connect With On-Demand Apps in PHP
1. Download the Stripe PHP Library
Start by downloading the latest Stripe PHP library. For this tutorial, version 6.30.5 is used.
Using Composer: Install the library via PHP Composer and create a configuration file to store your Stripe credentials.
After installation, add your Secret Key and Publishable Key to the config file:
require_once('vendor/autoload.php');
$stripe = [
"secret_key" => "********",
"publishable_key" => "*******",
];
\Stripe\Stripe::setApiKey($stripe['secret_key']);
2. Creating Stripe Accounts for Service Providers
Once you have collected the required contractor information, create a new Stripe account for each service provider.
require_once('./config.php');
$account = \Stripe\Account::create([
'country' => '{Country}',
'type' => '{custom | express}',
'email' => '[email protected]',
'requested_capabilities' => ['platform_payments'],
'business_profile' => [
'url' => '{Business URL}',
],
'business_type' => 'individual',
'individual' => [
'first_name' => '{First Name}',
'last_name' => '{Last Name}',
'address' => [
'city' => '{City}',
],
'dob' => [
'day' => '{Day}',
'month' => '{Month}',
'year' => '{Year}',
],
'ssn_last_4' => '{SSN Last 4}',
],
'tos_acceptance' => [
'date' => time(),
'ip' => $_SERVER['REMOTE_ADDR'],
],
]);
For additional optional parameters, refer to Stripe’s official documentation: https://stripe.com/docs/api/accounts/create
3. Adding a Bank Account for Payouts
To enable payouts, you must attach an external bank account to the newly created Stripe account. This allows Stripe to transfer funds directly to the service provider.
$account = \Stripe\Account::retrieve('{Stripe Account ID}');
$account->external_accounts->create([
'external_account' => '{Bank Account Parameters}',
]);
You can find the complete list of supported parameters here: https://stripe.com/docs/api/external_account_bank_accounts/create
4. Processing Payments to Contractors
To pay contractors, process the charge on your platform account and specify the destination parameter. This identifies the Stripe account that should receive the funds.
$charge = \Stripe\Charge::create([
'amount' => '{Amount}',
'currency' => '{Currency}',
'source' => '{Card Token}',
'destination' => '{Contractor Account ID}',
'application_fee' => '{Platform Fee}',
]);
This setup allows your platform to deduct its commission while transferring the remaining amount to the contractor.
For further details, visit: https://stripe.com/docs/recipes/on-demand-app
Conclusion
Stripe Connect provides a robust and scalable solution for handling payments in on-demand and marketplace applications. By properly managing custom accounts, bank payouts, and destination charges, platforms can deliver a seamless and secure payment experience for both customers and service providers.
If you are planning to integrate Stripe Connect into your on-demand application, feel free to contact The Right Software for professional implementation and support.
Frequently asked questions
What is Stripe Connect used for?
Stripe Connect handles payments for marketplace and on-demand platforms where money is split between the platform and independent service providers.
What is a Stripe Connect Custom account?
A connected account that the platform manages fully. Stripe does not interact with the contractor directly, so the platform must handle identity verification, bank account setup and the contractor's acceptance of terms.
How does the platform keep its commission?
The customer is charged on the platform account with the destination parameter pointing to the provider's connected account. The provider receives their share and the platform's commission stays on the platform account.
How do providers receive payouts?
Attach an external bank account to the provider's connected Stripe account. Stripe then pays out the provider's funds to that bank account.