How to integrate Stripe Connect in On-Demand apps in PHP

For a client, we were hired as WordPress developers. One of the problem was simple request. How to use WooCommerce to only allow next day delivery if before 1pm and day after tomorrow if ordered after 1pm.

In this article, we show you how to integrate Stripe Connect payment gateway with your on-demand apps using their PHP library.

 

What are On-Demand apps?

On-demand apps provide services to your customer using contractors, who are paid through your
platform.

For some businesses, the platform’s brand is at the center of the commerce: they aren’t just providing a software platform, they’re providing an end-to-end experience. For example, consider an on-demand app: Rates are set by the platform. Although a third party is providing the specific service, the platform is managing the experience, guaranteeing the quality, and handling the customer service.

Firstly, understand when you are creating the on-demand app you need to create Custom accounts on behalf of your service provider. One of the most important considerations with Custom accounts is that you are entirely responsible for providing the necessary information about your contractors, as Stripe will never interact with them, it is you who will. This means you must.

  • Address all necessary identity verification.
  • Establish the contractor’s bank account for payouts.
  • Have your contractor agree to your terms and services.

 

Integrate Stripe Connect with On-Demand apps in PHP

1. Download PHP Library

First, you have to download the latest Stripe library for PHP. Currently, the library is used for this
tutorial is 6.30.5.

  • Downloading library using PHP Composer
  • Create a config file.
  • After downloading the file add your Secret key and Publishable key in the config file.

Example:

require_once('vendor/autoload.php');  
$stripe = ["secret_key" => "********", "publishable_key" => "*******",];  
 
\Stripe\Stripe::setApiKey($stripe['secret_key']);

 

2. Creating Accounts

With the necessary information in hand create a new customer account for the service provider.

Example:

require_once('./config.php');
 $account = \Stripe\Account::create(['country' => {Country}',          
'type' => {Custom, Express}',            
"email" => "example@example.com",            
"requested_capabilities" => ["platform_payments"],            
"business_profile" => ['url' => {Business Url}",],            
"business_type" => "individual",            
"individual" => ["first_name" => {First Name Of The Account Holder}",                
"last_name" => {Last Name Of The Account Holder},                
"address" => ["city" => "{Address Of The Account Holder}"],                
"dob" => ["day" => {Dob Day Of The Account Holder},                    
"month" => {Dob Month Of The Account Holder},                    
"year" => {Dob Year Of The Account Holder},                ],                
"ssn_last_4" => {Socila Security Number Of The Account Holder},],            
'tos_acceptance' => ['date' => time(),                
'ip' => $_SERVER['REMOTE_ADDR'],],]);

Check the link below for the extra parameters that you want to add.

https://stripe.com/docs/api/accounts/create

 

3. Add customer bank account

Add external bank account for the new customer created account to enable is payouts. Flow of funds here is to update the service provider’s account by adding a bank account to which Stripe will transfer payments.

Example:

$account = \Stripe\Account::retrieve({Created Customer Account Number});
 
$account->external_accounts->create(["external_account" => {Parameters}]);

Check this link for the parameters to be passed for creating the external bank account.

https://stripe.com/docs/api/external_account_bank_accounts/create

 

4. Processing Payment

To pay contractors directly, simply process the charge on your account, setting a destination parameter that identifies the Stripe account that should receive the funds from the payment (i.e., the contractor). This requires a payment token created using the platform’s publishable API key.

$charge = \Stripe\Charge::create(['amount'   => {Total Account You Want To Transfer},        
'currency' => {Currency In Which The Amount Is Being Transferred},        
'source' => {Token Of The Card},        
'destination' => {Account Number On Which The Amount Is To Be Transfered},        
'application_fee' => {Total Fee That Your Marketplace Will Deduct},]);

For more details, you can visit this site.
https://stripe.com/docs/recipes/on-demand-app


If you have enjoyed the article and want to integrate Stripe Connect with your on-Demand app then you can contact The Right Software below.