Laravel Stripe Setup

Viewed 24

okay, this is my first time to ask a question here so please give grace if it's not very clear. Anyway, I have this code in Laravel Billing.php.

Is this correct? Whenever a new customer is created, it doesn't have it's user email address but instead this unknown@domain.com was assigned to the user.

This was set by my previous developer. But ever since we hired him for just simple fix, we've had numerous issues with the site.

$stripeCustomer = StripeCustomer::create([
                    'email' => $currentCustomer->email ? $currentCustomer->email : 'unknown@domain.com',
                    'description' => $company->name,
                    'metadata' => [
                        'company_id' => $company->id,
                        'card_owner_email' => $currentCustomer->email ? $currentCustomer->email : false,
                        'company_name' => $company->name,
                    ],
                ]);
1 Answers

You can remove customer email from the StripeCustomer when creating since stripe API said that email field of customer is optional. Here is the reference link

Here what you should fix:

$customerObject = [
    'description' => $company->name,
    'metadata' => [
        'company_id' => $company->id,
        'company_name' => $company->name,
    ],
];
if ($currentCustomer->email) {
    $customerMetadata["metadata"]["card_owner_email"] = $currentCustomer->email;
    $customerObject["email"] = $currentCustomer->email;
}
$stripeCustomer = StripeCustomer::create($customerObject);
Related