Skip to content

Commit

Permalink
check if the user have the taxid
Browse files Browse the repository at this point in the history
  • Loading branch information
rabol committed Aug 18, 2021
1 parent fd951c5 commit 008e3e5
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/LaravelSimplesubscriptionStripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,30 @@ public static function updateTaxIdOnCustomer(User $user, string $value, string $
$taxIds = self::stripe()->customers->allTaxIds($user->stripe_id);
$addNewTaxId = true;

// check if the user have the TaxId
if ($taxIds && $taxIds->count() != 0) {
foreach ($taxIds as $taxId) {
if ($taxId->type == $type && $taxId->value == $value) {
if ($taxId->type == $type && ($taxId->value == $value || $taxId->value == str_replace('-', '', $value))) {
$addNewTaxId = false;
}
}
}

// Does not seem like the TaxId is attached to the user, so let's attach it
if ($addNewTaxId) {
$taxId = self::stripe()->customers->createTaxId($user->stripe_id, [
'type' => $type,
'value' => $value,
]);

$user->stripe_tax_id = $taxId->id;
$user->save();
try {
$taxId = self::stripe()->customers->createTaxId($user->stripe_id, [
'type' => $type,
'value' => $value,
]);

if($taxId) {
$user->stripe_tax_id = $taxId->id;
$user->save();
}
} catch (\Exception $e) {
Log::error($e->getMessage());
}
}
}
}

0 comments on commit 008e3e5

Please sign in to comment.