diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index d86f8684074f..fead7b7b0121 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -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 diff --git a/app/Http/Controllers/PublicClientController.php b/app/Http/Controllers/PublicClientController.php index b0bc58a45165..b8c089379116 100644 --- a/app/Http/Controllers/PublicClientController.php +++ b/app/Http/Controllers/PublicClientController.php @@ -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')) { diff --git a/app/Services/PaymentService.php b/app/Services/PaymentService.php index 73d00b07e00e..d3ce97a7f935 100644 --- a/app/Services/PaymentService.php +++ b/app/Services/PaymentService.php @@ -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'];