PHP Stripe: You can not pass `payment_intent_data` in `subscription` mode

Viewed 2250

I'm trying to create a subscription for the merchant's users but facing "You can not pass payment_intent_data in subscription mode" error. With regular payments, it works well, but subscriptions aren't working.

Here is an example of what I want to do: John has an e-commerce shop based on recurring billing. Matthew is John's customer and wants to purchase a subscription from John. How can I easily take fees and transfer money to John's connect account while using "Stripe Checkout"?

  $session = \Stripe\Checkout\Session::create([
    'payment_method_types' => ['card'],
    'line_items' => [[
      'price' => $priceIntent->id,
      'quantity' => 1,
      ]],
    'customer' => Auth::User() -> stripe_code,
    'mode' => 'subscription',
    'payment_intent_data' => [
      'application_fee_amount' => $total_fees,
      'transfer_data' => [
        'destination' => $merchantId,
      ],
    ],
    'success_url' => env('APP_URL') . '/order/success/{CHECKOUT_SESSION_ID}',
    'cancel_url' => env('APP_URL') . '/order/cancel/',
  ]);

Thanks!

1 Answers

Basically, you can't use payment_intent_data on a Checkout Session in subscription mode, since the subscription creates invoices instead of PaymentIntents.

To do this, you need to use the subscription_data hash: https://stripe.com/docs/api/checkout/sessions/create?lang=php#create_checkout_session-subscription_data-application_fee_percent and specify the merchant account.

Example of the API call with merchant details:

  $session = \Stripe\Checkout\Session::create([

    'subscription_data' => [
      'application_fee_percent' => $fees_percent,
    ],

  ],array("stripe_account" => "acct_xxxxxxxxx"));

Also, don't forget to pass all the other required variables in the call.

Cheers :)

Related