如何使用PayPal rest API添加通用的“额外费用”?

I'm using the PayPal REST API (using PHP SDK) and I need to add extra fees (not paypal fees, but general handling fees in %). This is how I'm currently creating the transaction:

// The details (subtotal tax eclusive + shipping tax exclusive + tax)
$subTotalPlusShippingTaxEclusive = $cart->getSubtotal() + $cart->getShippingCosts();
$details = (new Details())
    ->setSubtotal($cart->getSubtotal())
    ->setShipping($cart->getShippingCosts())
    ->setTax($this->getTaxAmount($subTotalPlusShippingTaxEclusive));

// Total amount
$amount = (new Amount())
    ->setCurrency(self::CURRENCY_EUR)
    ->setDetails($details)
    ->setTotal($cart->getSubTotalTaxInclusive() + $cart->getShippingCostsTaxInclusive());

// The transaction
$transaction = (new Transaction())
    ->setAmount($amount)
    ->setItemList($this->createItems($cart->getAll()))
    ->setDescription(null);

I can't find a way to set those extra fees. Adding them to $amount will cause an error because $amount = $tax + $shipping + $subtotal.

You can add "extra" fees as additional line items on the order. That way the fee amount will be included in your $subtotal, and then the math will still add up and process correctly.