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

hasanhatem's avatar

Addressing Stripe Payment Element Issues and Handling Visitors in Laravel Cashier

Greetings,

I have a couple of questions to address:

Firstly, I am currently utilizing the Stripe Payment Element, but I am encountering an issue where the email field is displayed alongside the card inputs. However, I have already requested the user's email separately. How can I remove the email input from the Stripe elements?

Secondly, my website focuses on rentals, and the client wishes to allow both visitors and authenticated users to make payments. I am facing a challenge when it comes to handling visitors who do not have a user account. How can I address this issue? Additionally, I would like to know how to retrieve the following information for a visitor:

$intent = user()->createSetupIntent();

I am considering creating a Visitor Model similar to the User Model and applying the "Billable" trait to it. Do you have any advice regarding visitors and Laravel Cashier?

Thanks.

0 likes
1 reply
LaryAI's avatar
Level 58

For the first question, you can remove the email field from the Stripe Payment Element by setting the email option to false when creating the element. Here's an example:

const stripe = Stripe('your_publishable_key');

const elements = stripe.elements({
  fonts: [
    {
      cssSrc: 'https://fonts.googleapis.com/css?family=Source+Code+Pro',
    },
  ],
  // Set email option to false to remove email field
  email: false,
});

const card = elements.create('card', {
  style: {
    base: {
      fontFamily: 'Source Code Pro, monospace',
      fontSize: '16px',
      color: '#424770',
      '::placeholder': {
        color: '#aab7c4',
      },
    },
    invalid: {
      color: '#9e2146',
    },
  },
});

card.mount('#card-element');

For the second question, you can handle visitors who do not have a user account by creating a separate Visitor model and applying the Billable trait to it. Here's an example:

use Laravel\Cashier\Billable;

class Visitor extends Model
{
    use Billable;

    protected $guarded = [];

    // Override the default Stripe customer creation method to use email instead of name
    public function createAsStripeCustomer(array $options = [])
    {
        $options = array_merge([
            'email' => $this->email,
        ], $options);

        return $this->stripeCustomer()
            ?: $this->createStripeCustomer($options);
    }
}

To retrieve the setup intent for a visitor, you can use the createSetupIntent method on the Visitor model:

$visitor = new Visitor();
$intent = $visitor->createSetupIntent();

Please or to participate in this conversation.