public function setDefaultPaymentMethod()
{
if (!($contact = $this->getContact())) {
return $this->returnError();
}
$client = $contact->client;
$account = $client->account;
$validator = Validator::make(Input::all(), ['source' => 'required']);
if ($validator->fails()) {
return Redirect::to($client->account->enable_client_portal_dashboard ? '/client/dashboard' : '/client/payment_methods/');
}
$paymentDriver = $account->paymentDriver(false, GATEWAY_TYPE_TOKEN);
$paymentMethod = PaymentMethod::clientId($client->id)->wherePublicId(Input::get('source'))->firstOrFail();
$customer = $paymentDriver->customer($client->id);
$customer->default_payment_method_id = $paymentMethod->id;
$customer->save();
Session::flash('message', trans('texts.payment_method_set_as_default'));
return redirect()->to($client->account->enable_client_portal_dashboard ? '/client/dashboard' : '/client/payment_methods/');
}