使用 WordPress 中的自定义连接帐户在多供应商网站中实现条纹时出现问题

问题描述 投票:0回答:1

我有一个具体的 WordPress 网站多站点,我想为每个供应商实现自定义连接帐户..

我正在使用 woocommerce 和 woocommerce stripe gateway 进行付款,一切正常,但当我将钱转移到关联帐户时,问题就出现了。

我正在使用以下功能将资金转移到关联帐户,但问题是,当下订单并付款时,它会转到待处理余额,现在我无法向关联帐户付款,因为我没有余额及其悬而未决,所以如何解决这个问题..

有什么方法可以让我在主帐户付款之前拆分付款,或者有什么方法可以将待处理余额发送到我的关联帐户...任何帮助将不胜感激...

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');
        }
    }
}
wordpress stripe-payments
1个回答
0
投票

创建转账时您想要做的是将相应的费用 ID 包含在

source_transaction
参数中:https://stripe.com/docs/api/transfers/create#create_transfer-source_transaction

要记住的要点是,使用

source_transaction
时,如果付款仍处于待处理状态,则转账将从待处理余额中提取资金。如果付款已经可用,则转账将从可用余额中提取资金。

如果您不指定

source_transaction
,它将始终尝试使用您的可用余额中的资金,如果付款资金尚未可用,并且您不指定
source_transaction
,那么您可能会遇到资金不足的问题。

© www.soinside.com 2019 - 2024. All rights reserved.