soysushi
soysushi

Reputation: 71

How do I get stripe's application fee to reflect the adjustable quantity during checkout?

I added the adjustable quantity for Stripe's check out session call. I understand that the fee object is created after the payment.

I'm looking at the application fee object in stripe's documentation and it says it is capped at the final charge amount. How do I retrieve the charge amount or better, quantity during the checkout session?

    checkout_session = stripe.checkout.Session.create(
                success_url=domain_url + 'success?session_id={CHECKOUT_SESSION_ID}',
                cancel_url=domain_url + 'cancelled/',
                payment_method_types=['card'],
                customer=customer.id,
                payment_intent_data={
                    'application_fee_amount': int(stripe_price * fee_percentage),
                    'transfer_data': {
                    'destination': seller.stripe_user_id,
                    },
                },
                line_items=[
                {
                    'price_data': {
                        'currency': currency,
                        'unit_amount': price,
                        'product_data': {
                            'name': title
                        },
                    },
                    'adjustable_quantity': {
                    'enabled': True,
                    'minimum': 0,
                    'maximum': available_quantity,
                  },
                  'quantity': 1,
                },
                ],
                metadata={
                    "product_id": product.id,
                    "client_reference_id": user.id,
                },
                mode='payment',

            )
            return JsonResponse({'sessionId': checkout_session['id']})
        except Exception as e:
            return JsonResponse({'error': str(e)})

Upvotes: 0

Views: 926

Answers (1)

Justin Michael
Justin Michael

Reputation: 6475

Right now the best option is to do the following:

  1. Set payment_method_data.capture_method to manual on the Checkout Session
  2. When the Checkout Session is complete set an application_fee_amount when capturing the funds

This limits you to payment methods that support separate authorization and capture, but it will allow you to set application_fee_amount after the Checkout Session completes.

Upvotes: 2

Related Questions