if(! empty($cu)) might be your problem. You're redirecting is if $cu is not empty.
Sep 1, 2017
4
Level 2
Redirect if customer has no cards on file
Hello,
I want to redirect the user to an add a card page if they don't have any cards on stripe.
public function showCurrentCards ($id) { $cus = Auth::user()->stripe;
Stripe::setApiKey("XXXXX");
$cu = Customer::Retrieve(array("id" => $cus, "expand" => array("default_source")));
if(! empty($cu)) {
return redirect()->route('showCard')->with('error', 'You need to add a card');
}
$cards = Customer::retrieve($cus)->sources->all(array('object' => 'card'));
return view('show-payment', ['cards' => $cards, 'cu' => $cu]);
}
Level 1
You could try something like:
$cu = Customer::retrieve(array("id" => $cus, "expand" => array("default_source")));
$cardId = $cu->default_source;
if(! isset($cardId)) {
return redirect()->route('showCard')->with('error', 'You need to add a card');
}
Please or to participate in this conversation.