XF 2.3 How to get payment fee in completePurchase(XF\Payment\CallbackState $state)?

Siropu

Well-known member
After digging into PayPalRest.php code and doing some research, I think this might work: $state->resource['purchase_units'][0]['payments']['captures'][0]['seller_receivable_breakdown']['paypal_fee']['value']

What about Stripe and other providers?
 
Solution
Ok, I figured it out:

For PayPal: $fee = $state->resource['seller_receivable_breakdown']['paypal_fee']['value'];

For Stripe:
PHP:
if (\XF::config('enableLivePayments'))
{
    $key = $paymentProfile->options['live_secret_key'];
}
else
{
    $key = $paymentProfile->options['test_secret_key'];
}

\Stripe\Stripe::setApiKey($key);

$charge = \Stripe\Charge::retrieve([
    'id'     => $state->event['id'],
    'expand' => ['balance_transaction']
]);

$fee = $charge->balance_transaction->fee;
Ok, I figured it out:

For PayPal: $fee = $state->resource['seller_receivable_breakdown']['paypal_fee']['value'];

For Stripe:
PHP:
if (\XF::config('enableLivePayments'))
{
    $key = $paymentProfile->options['live_secret_key'];
}
else
{
    $key = $paymentProfile->options['test_secret_key'];
}

\Stripe\Stripe::setApiKey($key);

$charge = \Stripe\Charge::retrieve([
    'id'     => $state->event['id'],
    'expand' => ['balance_transaction']
]);

$fee = $charge->balance_transaction->fee;
 
Solution
Back
Top Bottom