Ecommerce Shopify WordPress Discussion

Problem with implementing stripe in multi vender website using custom connected account in wordpress

I have a wordpress website multi site to be specific and i want to implement custom connected account for each vendor.. i am using woocommerce and woocommerce stripe gatway for payments it all works fine but the problem comes in when i am transfering money to connected account. i am using the below function for transfering money to a connected account but the problem is that when an order is placed and payment is made it goes to pending balance and now i am not able to pay to connected account because i don't have balance and its in pending so how can tackle the issue.. is there some way that i can split the payment before a payment is made main account or is there some way i can send the pending balance to my connected account... any help would be appreciated... add_action('woocommerce_payment_complete', 'custom_split_payment', 10, 1); function custom_split_payment($order_id) { // Get the order object $order = wc_get_order($order_id); // Check if the order is paid if ($order->is_paid()) { // Get the payment method used $payment_method = $order->get_payment_method(); // Check if the payment method is Stripe if ($payment_method === 'stripe') { // Get the Stripe customer ID associated with the order $customer_id = $order->get_meta('_stripe_customer_id', true); $blog_id = get_current_blog_id(); $connected_account_id = get_site_option('vendor_stripe_id_' . $blog_id); // Get the order total $order_total = $order->get_total(); $stripe_api_keys = get_site_option('stripe_api_keys'); $key = ''; if( isset( $stripe_api_keys["test_mode"] ) ) { if( isset($stripe_api_keys['test_secret_key']) ){ $key = $stripe_api_keys['test_secret_key']; } } else if ( isset( $stripe_api_keys['live_secret_key'] ) ) { $key = $stripe_api_keys['live_secret_key']; } $stripe = new \Stripe\StripeClient($key); $commission_key = 'vendor_commission_percentage_' . $blog_id; $commission_percentage = get_site_option($commission_key); $commission_amount = number_format($order_total * ($commission_percentage / 100), 2); $array = [ 'amount' => $commission_amount * 100, // Amount in cents 'currency' => 'usd', // Change currency as needed 'destination' => $connected_account_id, ]; try { // Your Stripe API call here $stripe->transfers->create($array); // Additional code if the API call is successful } catch (\Stripe\Exception\ApiErrorException $e) { // This block will be executed if there is an API error echo 'Stripe API Error: ' . $e->getMessage(); // You can handle the exception here, log the error, or take appropriate actions } catch (Exception $e) { // This block will be executed for other exceptions not specific to Stripe echo 'Error: ' . $e->getMessage(); // Handle other exceptions here } finally { // This block will be executed regardless of whether an exception occurred or not // You can include cleanup code or additional actions that need to be performed } die(); $stripe->transfers->create($array); $order->update_status('processing'); } } }
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.