Enabled updating accepted credit cards without re-entering payment credentials

This commit is contained in:
Hillel Coren 2014-09-14 10:33:34 +03:00
parent 2995814927
commit f8c2edc0dc

View File

@ -623,12 +623,13 @@ class AccountController extends \BaseController {
} }
else else
{ {
$account = Account::findOrFail(Auth::user()->account_id); $account = Account::with('account_gateways')->findOrFail(Auth::user()->account_id);
if ($gatewayId) if ($gatewayId)
{ {
$accountGateway = AccountGateway::createNew(); $accountGateway = AccountGateway::createNew();
$accountGateway->gateway_id = $gatewayId; $accountGateway->gateway_id = $gatewayId;
$isMasked = false;
$config = new stdClass; $config = new stdClass;
foreach ($fields as $field => $details) foreach ($fields as $field => $details)
@ -637,27 +638,35 @@ class AccountController extends \BaseController {
if ($value && $value === str_repeat('*', strlen($value))) if ($value && $value === str_repeat('*', strlen($value)))
{ {
Session::flash('error', trans('validation.notmasked')); $isMasked = true;
return Redirect::to('company/payments');
} }
$config->$field = $value; $config->$field = $value;
} }
$cardCount = 0; $cardCount = 0;
if ($creditcards) if ($creditcards)
{ {
foreach($creditcards as $card => $value) foreach($creditcards as $card => $value)
{ {
$cardCount += intval($value); $cardCount += intval($value);
} }
} }
$accountGateway->config = json_encode($config); if ($isMasked && count($account->account_gateways))
$accountGateway->accepted_credit_cards = $cardCount; {
$currentGateway = $account->account_gateways[0];
$currentGateway->accepted_credit_cards = $cardCount;
$currentGateway->save();
}
else
{
$accountGateway->config = json_encode($config);
$accountGateway->accepted_credit_cards = $cardCount;
$account->account_gateways()->delete(); $account->account_gateways()->delete();
$account->account_gateways()->save($accountGateway); $account->account_gateways()->save($accountGateway);
}
Session::flash('message', trans('texts.updated_settings')); Session::flash('message', trans('texts.updated_settings'));
} }