Umut Derbentoğlu
Umut Derbentoğlu

Reputation: 1196

Get Stripe Processing Fee After Successful Session

We are creating a Stripe session in our application like this:

        StripeConfiguration.ApiKey = ConfigurationManager.AppSettings["StripeKey"];

        var baseUrl = ConfigurationManager.AppSettings["DomainURL"];

        var options = new SessionCreateOptions
        {
            PaymentMethodTypes = new List<string> {
                "card",
            },
            PaymentIntentData = new SessionPaymentIntentDataOptions()
            {
                Description = requestDto.TrackingNumber,
                ReceiptEmail = requestDto.User.Email,
            },
            CustomerEmail = requestDto.User.Email,
            ClientReferenceId = requestDto.TrackingNumber,
            LineItems = new List<SessionLineItemOptions> {
                new SessionLineItemOptions {
                    Name = requestDto.Title,
                    Amount = requestDto.Total,
                    Currency = "usd",
                    Quantity = 1,
                    Description = requestDto.TrackingNumber
                },
            },
            SuccessUrl = baseUrl + $"/Payment/Success",
            CancelUrl = baseUrl + $"/Payment/Failure",
        };

        var service = new SessionService();
        var session = service.Create(options);

        return session.Id;

After that, stripe payment page shows up and user enters credit card information. We are trying to get Stripe processing fee after successful payment. We tried "BalanceTransactionService" but it did not work. I think "balance transaction" object is not available for this payment type. Is there a way to get processings fee from stripe?

Upvotes: 8

Views: 4307

Answers (1)

ttmarek
ttmarek

Reputation: 3240

Every successful (card) Checkout session will include a reference to the associated successful payment intent:

https://stripe.com/docs/api/checkout/sessions/object#checkout_session_object-payment_intent

Using the payment intent you can retrieve the Stripe fees by retrieving the payment intent's balance transaction. The Stripe docs have an exact example of that here:

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

The canonical place to perform this logic would be in a webhook after fulfilling the order: https://stripe.com/docs/payments/checkout/fulfill-orders

Upvotes: 13

Related Questions