1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00
invoiceninja/app/Http/Controllers/BlueVineController.php

94 lines
2.9 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
use Auth;
use Input;
use Redirect;
use Session;
2017-01-30 20:40:43 +01:00
use URL;
2017-01-30 17:05:31 +01:00
class BlueVineController extends BaseController
{
public function signup()
{
$user = Auth::user();
2017-01-30 20:40:43 +01:00
$data = [
'personal_user_full_name' => Input::get('name'),
'business_phone_number' => Input::get('phone'),
'email' => Input::get('email'),
'personal_fico_score' => intval(Input::get('fico_score')),
'business_annual_revenue' => intval(Input::get('annual_revenue')),
2017-01-30 17:05:31 +01:00
'business_monthly_average_bank_balance' => intval(Input::get('average_bank_balance')),
2017-01-30 20:40:43 +01:00
'business_inception_date' => date('Y-m-d', strtotime(Input::get('business_inception'))),
'partner_internal_business_id' => 'ninja_account_' . $user->account_id,
];
2017-01-30 17:05:31 +01:00
if (! empty(Input::get('quote_type_factoring'))) {
$data['invoice_factoring_offer'] = true;
2017-01-30 20:40:43 +01:00
$data['desired_credit_line'] = intval(Input::get('desired_credit_limit')['invoice_factoring']);
2017-01-30 17:05:31 +01:00
}
if (! empty(Input::get('quote_type_loc'))) {
2017-01-30 20:40:43 +01:00
$data['line_of_credit_offer'] = true;
2017-01-30 17:05:31 +01:00
$data['desired_credit_line_for_loc'] = intval(Input::get('desired_credit_limit')['line_of_credit']);
}
$api_client = new \GuzzleHttp\Client();
try {
$response = $api_client->request('POST',
2017-01-30 20:40:43 +01:00
'https://app.bluevine.com/api/v1/user/register_external?' . http_build_query([
2017-01-30 17:05:31 +01:00
'external_register_token' => env('BLUEVINE_PARTNER_TOKEN'),
2017-01-30 20:40:43 +01:00
'c' => env('BLUEVINE_PARTNER_UNIQUE_ID'),
'signup_parent_url' => URL::to('/bluevine/completed'),
]), [
'json' => $data,
]
2017-01-30 17:05:31 +01:00
);
} catch (\GuzzleHttp\Exception\RequestException $ex) {
if ($ex->getCode() == 403) {
$response_body = $ex->getResponse()->getBody(true);
$response_data = json_decode($response_body);
return response()->json([
2017-01-30 20:40:43 +01:00
'error' => true,
'message' => $response_data->reason,
2017-01-30 17:05:31 +01:00
]);
} else {
return response()->json([
2017-01-30 20:40:43 +01:00
'error' => true,
2017-01-30 17:05:31 +01:00
]);
}
}
$company = $user->account->company;
$company->bluevine_status = 'signed_up';
$company->save();
$quote_data = json_decode($response->getBody());
return response()->json($quote_data);
}
public function hideMessage()
{
$user = Auth::user();
if ($user) {
$company = $user->account->company;
$company->bluevine_status = 'ignored';
$company->save();
}
return 'success';
}
public function handleCompleted()
{
Session::flash('message', trans('texts.bluevine_completed'));
return Redirect::to('/dashboard');
}
2017-01-01 12:09:42 +01:00
}