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();