Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

phillipvarsted's avatar

Laravel Cashier B2B subscriptions

Hello!

We are developing a B2B subscription management software thats accessible by only employees. Instead of having our customers to signup and create a subscription we onboard the customer.

We create the customer, create the subscription and send it.

Currently we're using Laravel Cashier (stripe) and use this:

$user->newSubscription('default', 'price_monthly')->createAndSendInvoice();

What am I trying to accomplish here?

When the customer pays the initial invoice (the first one) then we want the subscription to be paid automatically using the customers card which was used to pay the invoice.

I've went through the Laravel docs for days, and whatever I try I cant get the customers card to be the default payment method for that subscription. It just keeps sending the customer an invoice on the next recurring payment date.

Any ideas? Is it even possible using cashier and stripe, or should we be doing some manual work?

0 likes
4 replies
LaryAI's avatar
Level 58

Hello!

To achieve the behavior you're looking for, you need to ensure that when the customer pays their initial invoice, their payment method is saved and set as the default for future payments. With Laravel Cashier, this typically involves a few steps:

  1. When creating a subscription, you need to make sure you're collecting and storing the customer's payment method.
  2. You need to set this payment method as the default for the subscription.

Here's a step-by-step guide on how you might accomplish this:

  1. Collect Payment Method: When you onboard the customer, you should collect their payment method details and create a payment method in Stripe.

  2. Create a Customer: Create a Stripe customer with the payment method from step 1.

  3. Create a Subscription: When creating the subscription, attach the payment method as the default.

Here's an example of how you might modify your existing code to include these steps:

// Assuming you have the payment method token (e.g., from a payment form)
$paymentMethod = $request->input('payment_method');

// Create a new customer in Stripe and set the payment method as default
$stripeCustomer = $user->createAsStripeCustomer([
    'email' => $user->email,
    'payment_method' => $paymentMethod,
]);

// Now, when creating the subscription, specify that you want to use the default payment method
$subscription = $user->newSubscription('default', 'price_monthly')
    ->create($paymentMethod, [
        'invoice_settings' => [
            'default_payment_method' => $paymentMethod,
        ],
    ]);

// Optionally, send the invoice to the customer
$subscription->invoice();

Make sure that the $paymentMethod variable contains the payment method ID that you've obtained from the Stripe payment form or Stripe Elements.

This code assumes that you're using a version of Laravel Cashier that supports the createAsStripeCustomer and create methods with the specified parameters. If you're using an older version of Cashier, you may need to adjust the code accordingly.

By setting the 'default_payment_method' in the invoice_settings, you're telling Stripe to use this payment method for future invoices.

Please ensure that you're handling any potential exceptions that might be thrown during this process, such as card declines or network issues.

If you're still having trouble, you might want to check the Stripe Dashboard to see if the payment method is being set correctly, or use Stripe's API logs to debug the issue further.

Remember to comply with PCI DSS requirements when handling payment information. Laravel Cashier and Stripe provide tools to help you with this, but it's important to understand and follow the necessary guidelines to ensure the security of your customers' payment information.

dualklip's avatar

Hi @phillipvarsted ,

I don't know much about Stripe & Cashier because I'm only used a couple of times. What you think about creating the subscription in the simple way, which allow you to setup a Payment method, and then use the webhook customer.subscription.created to send the first invoice?

use Illuminate\Http\Request;
 
Route::post('/user/subscribe', function (Request $request) {
    $request->user()->newSubscription(
        'default', 'price_monthly'
    )->create($request->paymentMethodId);
 
    // ...
});
phillipvarsted's avatar

Hi @dualklip,

Thank you for replying. We do not have the customer signup themselves so they wont be setting up the payment intent until we send them the first invoice.

We need it to be like this: We create the customer & subscription in our internal system > Customer receives invoice with payment link > Customers credit card is being used to future payments of that subscription

dualklip's avatar

Ok, then...

How do you think about this aproach?

  1. You create the customer
  2. You create a Setup Intent
  3. You send the link to the customer
  4. The client add the payment method info
  5. You create the subscription
  6. You get the first invoice and send it to the customer

You will need to change something in your approach. If you don't like mine you can do other, but createAndSendInvoice method is for an option different that you wanted. With that option the customer received an invoice in each period with a link to pay it.

Please or to participate in this conversation.