Hello everybody,
I am trying to get Cashier with Stripe running (at least to use the stripe-checkout). To archive this, I am using another model as Billable.
This is the AppServiceProvider:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Laravel\Cashier\Cashier;
//...
class AppServiceProvider extends ServiceProvider {
/**
* Register any application services.
*
* @return void
*/
public function register()
{
Cashier::ignoreMigrations();
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Cashier::calculateTaxes();
Cashier::useCustomerModel(Team::class);
//...
}
}
This is the model that should be billable:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravel\Cashier\Billable;
/**
*
*/
class Team extends Model {
use HasFactory, Billable;
public function stripeName()
{
return $this->fullname;
}
public function stripeAddress()
{
return [
"city" => $this->location->city,
"country" => $this->location->country,
"line1" => $this->location->street . " " . $this->location->housenumber,
"line2" => null,
"postal_code" => $this->location->zip,
"state" => null,
];
}
/**
* @return string
*/
public function getFullNameAttribute(): string
{
return "{$this->name} {$this->type}";
}
}
So if I now run something like this:
$team = Team::find(5);
$team->newSubscription('default', 'price_1...')->allowPromotionCodes()->collectTaxIds()
->checkout([
'success_url' => route('home),
'cancel_url' => route('home'),
]);
I am getting this error:
Stripe/Exception/InvalidRequestException with message 'Tax ID collection requires updating business name on the customer. To enable tax ID collection for an existing customer, please set `customer_update[name]` to `auto`.'
So for now I am quite confused as when I look at cashier's source code (https://github.com/laravel/cashier-stripe/blob/d7651e3e8c38be37283a0b2ee33e88add0153c02/src/Concerns/PerformsCharges.php#L94-L97) I do find this:
// Make sure to collect address and name when Tax ID collection is enabled...
if ($payload['tax_id_collection']['enabled'] ?? false) {
$payload['customer_update']['address'] = 'auto';
$payload['customer_update']['name'] = 'auto';
}
and $payload['tax_id_collection']['enabled'] comes from
'tax_id_collection' => [
'enabled' => Cashier::$calculatesTaxes ?: $this->collectTaxIds,
],
and Cashier::$calculatesTaxes returns true in my app.
Even if I rebuild this in Tinkerwell, I am getting this array:
$payload = array_filter([
'allow_promotion_codes' => true,
'automatic_tax' => true,
'discounts' => true,
'tax_id_collection' => [
'enabled' => Laravel\Cashier\Cashier::$calculatesTaxes ?: $this->collectTaxIds,
],
]);
// Make sure to collect address and name when Tax ID collection is enabled...
if ($payload['tax_id_collection']['enabled'] ?? false) {
$payload['customer_update']['address'] = 'auto';
$payload['customer_update']['name'] = 'auto';
}
$payload;
=> [
"allow_promotion_codes" => true,
"automatic_tax" => true,
"discounts" => true,
"tax_id_collection" => [
"enabled" => true,
],
"customer_update" => [
"address" => "auto",
"name" => "auto",
],
]
So it should be cool...? Is there something I don't see?