mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Update billing address when adding payment method
This commit is contained in:
parent
745a6b7d84
commit
258401715c
@ -399,16 +399,7 @@ class PaymentController extends BaseController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function do_payment($invitationKey, $onSite = true, $useToken = false, $sourceId = false)
|
public static function processPaymentClientDetails($client, $accountGateway, $paymentType, $onSite = true){
|
||||||
{
|
|
||||||
$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;
|
|
||||||
|
|
||||||
$rules = [
|
$rules = [
|
||||||
'first_name' => 'required',
|
'first_name' => 'required',
|
||||||
'last_name' => 'required',
|
'last_name' => 'required',
|
||||||
@ -437,17 +428,6 @@ class PaymentController extends BaseController
|
|||||||
'country_id' => 'required',
|
'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) {
|
if ($onSite) {
|
||||||
$validator = Validator::make(Input::all(), $rules);
|
$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 {
|
try {
|
||||||
// For offsite payments send the client's details on file
|
// 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
|
// If we're using a token then we don't need to send any other data
|
||||||
|
@ -884,6 +884,11 @@ class PublicClientController extends BaseController
|
|||||||
$accountGateway = $account->getGatewayByType($paymentType);
|
$accountGateway = $account->getGatewayByType($paymentType);
|
||||||
$sourceToken = $accountGateway->gateway_id == GATEWAY_STRIPE ? Input::get('stripeToken'):Input::get('payment_method_nonce');
|
$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) {
|
if ($sourceToken) {
|
||||||
$details = array('token' => $sourceToken);
|
$details = array('token' => $sourceToken);
|
||||||
} elseif (Input::get('plaidPublicToken')) {
|
} elseif (Input::get('plaidPublicToken')) {
|
||||||
|
@ -98,7 +98,7 @@ class PaymentService extends BaseService
|
|||||||
if ($input && $accountGateway->isGateway(GATEWAY_STRIPE)) {
|
if ($input && $accountGateway->isGateway(GATEWAY_STRIPE)) {
|
||||||
if (!empty($input['stripeToken'])) {
|
if (!empty($input['stripeToken'])) {
|
||||||
$data['token'] = $input['stripeToken'];
|
$data['token'] = $input['stripeToken'];
|
||||||
unset($details['card']);
|
unset($data['card']);
|
||||||
} elseif (!empty($input['plaidPublicToken'])) {
|
} elseif (!empty($input['plaidPublicToken'])) {
|
||||||
$data['plaidPublicToken'] = $input['plaidPublicToken'];
|
$data['plaidPublicToken'] = $input['plaidPublicToken'];
|
||||||
$data['plaidAccountId'] = $input['plaidAccountId'];
|
$data['plaidAccountId'] = $input['plaidAccountId'];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user