Gabotronix's avatar

Stripe PaymentIntents with connected account + charge fee

Hi everybody, my app will use stripe connected accounts to create a marketplace, I charge a 1€ fee for each payment my users receive when seeling their goods, I have experience with creating PaymentIntent for my customers but not with connected accounts, the docs are also a bit confusing.

Docs: https://stripe.com/docs/connect/collect-then-transfer-guide

Now if we take a look at the docs, where paymentIntent is created. NO customer and NO payment method is supplied, ONLY stripe connected account id is supplied, how can I tell then what customer is getting charged.

\Stripe\Stripe::setApiKey('sk_test_CGGvfNiIPwLXiDwaOfZ3oX6Y');

$payment_intent = \Stripe\PaymentIntent::create([
  'payment_method_types' => ['card'],
  'amount' => 1000,
  'currency' => 'usd',
  'application_fee_amount' => 123,
  'transfer_data' => [
    'destination' => '{{CONNECTED_STRIPE_ACCOUNT_ID}}',
  ],
]);

This is how I do charges for non-connected accounts for reference:

public function addPaymentCreateIntent(Request $request)
    {
        //$validatedData = $request->validate(StripeValidator::$addPaymentCreateIntent);

        $venue_id = $request->input('venue_id') ?? 1;
        $discount = $request->input('discount') ?? Discount::findOrFail(1);
        $products = $request->input('products') ?? Product::take(3)->get();

        $stripeId = $request->input('stripeId');
        $paymentMethod = PaymentMethod::retrieve($request->input('paymentMethodId'));
        $paymentMethod->attach(['customer' => $stripeId]);
        
        $amount = (int) ($request->input('total')*100);
        
        $paymentIntent = PaymentIntent::create([
            'amount' => $amount,
            'payment_method' => $paymentMethod['id'],
            'payment_method_types' => ['card'],
            'currency' => 'eur',
            'customer' => $stripeId,
            //'setup_future_usage' => 'off_session',
            'metadata' => [
                'user_id' => $request->input('user_id'),
                'last4' => $paymentMethod['card']['last4'],
                'brand' => $paymentMethod['card']['brand'],
            ],
        ], 
        ['idempotency_key' =>  sha1(Carbon::now()) ]);


        return response()->json([
            'paymentIntent' => $paymentIntent,
        ], 200);  
    }

As you can see with no connected accounts customer and payment method is supplied, with connected accounts am I not needed to supply these??

Also why is it so hard to find an example of a connected account payment flow in the internet?

0 likes
3 replies
Gabotronix's avatar

So in the docs:

$payment_intent = \Stripe\PaymentIntent::create([
  'payment_method_types' => ['card'],
  'amount' => 1000,
  'currency' => 'usd',
  'application_fee_amount' => 123,
  'transfer_data' => [
    'destination' => '{{CONNECTED_STRIPE_ACCOUNT_ID}}',
  ],
]);

I can see no customer or payment method being used to create the payment intent, how is this example complete?

extjac's avatar

did you manage to implement Stripe Connected Accounts?

Please or to participate in this conversation.