Add Stripe Connect data to wc_stripe_payment_request

Question

I am using Stripe Connect to collect a commission for sales on a woocommerce site.

I need to add the following to the payment request JSON.

  'application_fee_amount' => (Gateway Based Fees Amount),
  'transfer_data' => [
    'destination' => '{{CONNECTED_STRIPE_ACCOUNT_ID}}',
  ],

This code I found and modified a little to fit my purpose

//add_filter( 'woocommerce_stripe_request_body', 'add_application_fee', 20, 2 );
add_filter('wc_stripe_generate_payment_request', 'add_application_fee', 20, 3 );

function add_application_fee( $request, $api ) {

    //  Try to retrieve the order ID from the metadata

    $orderID = $request['metadata']['order_id'];
    $order = wc_get_order($orderID);

    //  This filter is hit multiple times, so the order ID might not be available. If not, just return the request.

    if (!$order) {
        return $request;
    }

    //$applicationFee = $gateway_fee; //I need to find the value calculated by the woocommerce gateway based fees plugin. 
    $applicationFee = 2;  //  <- Use this for testing, I 
    $request['application_fee_amount'] = $applicationFee;
    $request['transfer_data']['destination'] = '{{CONNECTED_STRIPE_ACCOUNT_ID}}';
    return $request;
}

This does not produce any errors, however the information does not get added onto the stripe payment.

{
  "amount": "12766",
  "currency": "USD",
  "description": "Order 35215",
  "metadata": {
    "instance": "example.com",
    "order_id": "35215",
    "order_email": "example@gmail.com",
    "cart_hash": ""
  },
  "setup_future_usage": "off_session",
  "capture_method": "automatic",
  "confirmation_method": "manual",
  "customer": "cus_H1VGhq2aNJWokc"
}
0
, JpaytonWPD 3 years 2020-04-03T00:51:41-05:00 0 Answers 121 views 0

Leave an answer

Browse
Browse