Update billing address when adding payment method

This commit is contained in:
Joshua Dwire 2016-05-10 22:15:30 -04:00
parent 745a6b7d84
commit 258401715c
3 changed files with 38 additions and 22 deletions

View File

@ -399,16 +399,7 @@ class PaymentController extends BaseController
}
}
public function do_payment($invitationKey, $onSite = true, $useToken = false, $sourceId = false)
{
$invitation = Invitation::with('invoice.invoice_items', 'invoice.client.currency', 'invoice.client.account.currency', 'invoice.client.account.account_gateways.gateway')->where('invitation_key', '=', $invitationKey)->firstOrFail();
$invoice = $invitation->invoice;
$client = $invoice->client;
$account = $client->account;
$paymentType = Session::get($invitation->id . 'payment_type');
$accountGateway = $account->getGatewayByType($paymentType);
$paymentMethod = null;
public static function processPaymentClientDetails($client, $accountGateway, $paymentType, $onSite = true){
$rules = [
'first_name' => 'required',
'last_name' => 'required',
@ -437,17 +428,6 @@ class PaymentController extends BaseController
'country_id' => 'required',
]);
}
if ($useToken) {
if(!$sourceId) {
Session::flash('error', trans('texts.no_payment_method_specified'));
return Redirect::to('payment/' . $invitationKey)->withInput(Request::except('cvv'));
} else {
$customerReference = $client->getGatewayToken($accountGateway, $accountGatewayToken/* return parameter*/);
$paymentMethod = PaymentMethod::scope($sourceId, $account->id, $accountGatewayToken->id)->firstOrFail();
$sourceReference = $paymentMethod->source_reference;
}
}
if ($onSite) {
$validator = Validator::make(Input::all(), $rules);
@ -469,6 +449,37 @@ class PaymentController extends BaseController
}
}
return true;
}
public function do_payment($invitationKey, $onSite = true, $useToken = false, $sourceId = false)
{
$invitation = Invitation::with('invoice.invoice_items', 'invoice.client.currency', 'invoice.client.account.currency', 'invoice.client.account.account_gateways.gateway')->where('invitation_key', '=', $invitationKey)->firstOrFail();
$invoice = $invitation->invoice;
$client = $invoice->client;
$account = $client->account;
$paymentType = Session::get($invitation->id . 'payment_type');
$accountGateway = $account->getGatewayByType($paymentType);
$paymentMethod = null;
if ($useToken) {
if(!$sourceId) {
Session::flash('error', trans('texts.no_payment_method_specified'));
return Redirect::to('payment/' . $invitationKey)->withInput(Request::except('cvv'));
} else {
$customerReference = $client->getGatewayToken($accountGateway, $accountGatewayToken/* return parameter*/);
$paymentMethod = PaymentMethod::scope($sourceId, $account->id, $accountGatewayToken->id)->firstOrFail();
$sourceReference = $paymentMethod->source_reference;
}
}
$result = static::processPaymentClientDetails($client, $accountGateway, $paymentType, $onSite);
if ($result !== true) {
return $result;
}
try {
// For offsite payments send the client's details on file
// If we're using a token then we don't need to send any other data

View File

@ -884,6 +884,11 @@ class PublicClientController extends BaseController
$accountGateway = $account->getGatewayByType($paymentType);
$sourceToken = $accountGateway->gateway_id == GATEWAY_STRIPE ? Input::get('stripeToken'):Input::get('payment_method_nonce');
$result = PaymentController::processPaymentClientDetails($client, $accountGateway, $paymentType);
if ($result !== true) {
return $result;
}
if ($sourceToken) {
$details = array('token' => $sourceToken);
} elseif (Input::get('plaidPublicToken')) {

View File

@ -98,7 +98,7 @@ class PaymentService extends BaseService
if ($input && $accountGateway->isGateway(GATEWAY_STRIPE)) {
if (!empty($input['stripeToken'])) {
$data['token'] = $input['stripeToken'];
unset($details['card']);
unset($data['card']);
} elseif (!empty($input['plaidPublicToken'])) {
$data['plaidPublicToken'] = $input['plaidPublicToken'];
$data['plaidAccountId'] = $input['plaidAccountId'];