StripyTiger
StripyTiger

Reputation: 1047

Obtain the Stripe fee from Payment Intent

I am trying to pull out the Stripe processing fees from the PaymentIntent - but I cannot seem to find it. Is there another call I need to make on the API?

Upvotes: 8

Views: 6755

Answers (4)

sendon1982
sendon1982

Reputation: 11314

Here is the java version if you are using Java refer to the link here:

https://docs.stripe.com/expand/use-cases#stripe-fee-for-payment

PaymentIntentRetrieveParams params =
  PaymentIntentRetrieveParams.builder()
    .addExpand("latest_charge.balance_transaction")
    .build();

PaymentIntent paymentIntent = PaymentIntent.retrieve("pi_1Gpl8kLHughnNhxyIb1RvRTu", params, null);

List<BalanceTransaction.Fee> feeDetails = paymentIntent.getLatestCharge().getBalanceTransactionObject().getFeeDetails();

Upvotes: 0

Sara Nafisa
Sara Nafisa

Reputation: 27

const stripe = require('stripe')('sk_testq');

const paymentIntent = await stripe.paymentIntents.retrieve(
  'pi_1Gpl8kLHughnNhxyIb1RvRTu',
  {
    expand: ['latest_charge.balance_transaction'],
  }
);

const feeDetails = paymentIntent.latest_charge.balance_transaction.fee_details;

Upvotes: 0

Here is a function which gives a json with all the Stripe fees details :

async function bankingFeesFun(paymentIntentId) {
  const balance = await balanceTransaction(paymentIntentId)
  return {
    amount: balance.amount,
    fee: balance.fee,
    net: balance.net,
    currency: balance.currency,
    fee_details: balance.fee_details
  }
}

async function balanceTransaction(paymentIntentId) {
  return await stripe.balanceTransactions.retrieve((await chargeFun(stripe, paymentIntentId)).balance_transaction)
}

async function charge(paymentIntentId) {
  return await stripe.charges.list({
    payment_intent: paymentIntentId
  }).then((res) => {
    return res.data[0]
  })
}

Upvotes: 0

Jonathan Steele
Jonathan Steele

Reputation: 1963

You can do this when retrieving the Payment Intent by expanding certain fields:

const paymentIntent = await stripe.paymentIntents.retrieve('pi_xxx', {
  expand: ['charges.data.balance_transaction'],
});

Your paymentIntent constant will then include a balance_transaction hash on the related Charge object that will include details of the Stripe processing fees.

Upvotes: 15

Related Questions