The following flow charts represent the basic flow required to get Paystack split payments working for WC Vendors. This can also be adapted to support any payment gateway that supports split payments.
Looking at the Paystack for WooCommerce payment gateway plugin, it seems split payments are already supported but are for a fixed/predefined sub-account, and do not support dynamic sub-accounts based on the vendor list retrieved from the current order being processed. In order for WC Vendors Marketplace to support split payments with Paystack, it is required that the split is generated dynamically based on the number of vendors whose products are on the currently processed order.
In order to support multi-split payments, the Marketplace administrator must have a Paystack account and configure the plugin with the API keys so that sub-accounts can be created through the Paystack API. During vendor onboarding, vendors will provide their settlement account details which will be used to configure sub-accounts and facilitate split payments.
Download the flowchart as a PDF document
Vendor onboarding
We recommend a simple onboarding system that will allow vendors to create an account from the Marketplace settings by filling in a simple form with the details required by Paystack to create an account, or they can manually fill in the account details if they already have an account with Paystack
Here is a flow chart showing the onboarding process. This starts from the Vendor Dashboard under the Payment Settings page.
After the sub-account has been created, the sub-account code for the vendor must be saved to the current vendor’s account on the marketplace so that it can be used for split payments. See the payment gateway integration guide for details.
Example
<?php update_user_meta( $user->ID, '_paystack_sub_account_code', 'ACCT_xxxxxxxxxxxxx' ); ?>
Customer checkout flow
On the marketplace Shop page, a customer can buy any number of products from any number of Vendors. When checking out the payment gateway integration must retrieve the list of vendors from the order created and use this list to create the split payments based on the total for each vendor on the cart and the commission set by the marketplace admin.
Processing payment
Processing a payment involves calculating the splits based on the vendor dues from the order, see the Payment Gateway integration document for details. Below is a flowchart for processing the payment.
The split amounts must be calculated dynamically based on the order items, commission settings, and additional cart fees like taxes or shipping costs. The following also need to be checked to determine who receives the tax and shipping commission.
<?php if ( wc_string_to_bool( get_option( 'wcvendors_vendor_give_taxes' ) ) ) { // Addd tax fees to vendor total } else { // Add tax total to marketplace split } ?>
if ( wc_string_to_bool( get_option( 'wcvendors_vendor_give_shipping' ) ) ) { // Addd shipping fees to vendor total } else { // Add shipping total to marketplace split }
To create the split for each vendor based on the order, you can get the vendor dues from the order, and then retrieve the sub-account code for each vendor from the local database using the vendor ID, see the payment gateway integration document for reference. The sub-account code will be saved to the Vendor’s account on during onboarding.
Example:
public function process_split_payment( $order ) { $vendors_due = WCV_Vendors::get_vendor_dues_from_order( $order, false ); $sub_accounts = array(); foreach ( $vendors_due as $vendor_id => $products ) { $_vendor_account = get_user_meta( $vendor_id, '_paystack_sub_account_code', true ); $sub_accounts[] = array( 'subaccount' => $_vendor_account, 'share' => $calculated_share, ); // Other processing. } $split_payments = array( 'name' => 'Percentage Split for order #' . $order->get_id(), 'type' => 'percentage', 'currency' => woocommerce_get_currency(), 'subaccounts' => $sub_accounts, 'bearer_type' => 'subaccount', 'bearer_subaccount' => 'ACCT_hdl8abxl8drhrl3', ); $this->send_split_to_paystack( $split_payments ); // Other processing. }
Additional settings
When creating the split payments, it is necessary to check the admin’s settings and commission settings for any fees that may be deducted from the admin or from the sub-accounts. These include shipping costs, Paystack fees, taxes, and other charges. These charges must be correctly assigned and deducted or paid to each vendor if necessary.
These can also be configured on a per-transaction basis and can use configuration settings set by the platform owner on the setup page of the plugin. And, we’d also need to display this information to the vendors during onboarding so that they know what they are getting into and the fees related to this. Also, these settings should also only be available when WooCommerce + Paystack plugin for WooCommerce has been installed.