1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 12:42:36 +01:00

Show BlueVine quote and redirect to BlueVine

This commit is contained in:
Joshua Dwire 2016-11-10 18:24:54 -05:00
parent 5713561261
commit 5bee41789f
8 changed files with 2327 additions and 2092 deletions

View File

@ -81,3 +81,7 @@ WEPAY_FEE_PAYER=payee
WEPAY_APP_FEE_MULTIPLIER=0.002
WEPAY_APP_FEE_FIXED=0
WEPAY_THEME='{"name":"Invoice Ninja","primary_color":"0b4d78","secondary_color":"0b4d78","background_color":"f8f8f8","button_color":"33b753"}' # See https://www.wepay.com/developer/reference/structures#theme
BLUEVINE_PARTNER_UNIQUE_ID=
BLUEVINE_PARTNER_TOKEN=

View File

@ -0,0 +1,88 @@
<?php
namespace App\Http\Controllers;
use Auth;
use Input;
use Redirect;
use URL;
use Session;
class BlueVineController extends BaseController {
public function signup() {
$user = Auth::user();
$data = array(
'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' ) ),
'business_monthly_average_bank_balance' => intval( Input::get( 'average_bank_balance' ) ),
'business_inception_date' => date( 'Y-m-d', strtotime( Input::get( 'business_inception' ) ) ),
'partner_internal_business_id' => 'ninja_account_' . $user->account_id,
);
if ( ! empty( Input::get( 'quote_type_factoring' ) ) ) {
$data['invoice_factoring_offer'] = true;
$data['desired_credit_line'] = intval( Input::get( 'desired_credit_limit' )['invoice_factoring'] );
}
if ( ! empty( Input::get( 'quote_type_loc' ) ) ) {
$data['line_of_credit_offer'] = true;
$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',
'https://app.bluevine.com/api/v1/user/register_external?' . http_build_query( array(
'external_register_token' => env( 'BLUEVINE_PARTNER_TOKEN' ),
'c' => env( 'BLUEVINE_PARTNER_UNIQUE_ID' ),
'signup_parent_url' => URL::to( '/bluevine/completed' ),
) ), array(
'json' => $data
)
);
} catch ( \GuzzleHttp\Exception\RequestException $ex ) {
if ( $ex->getCode() == 403 ) {
$response_body = $ex->getResponse()->getBody( true );
$response_data = json_decode( $response_body );
return response()->json( [
'error' => true,
'message' => $response_data->reason
] );
} else {
return response()->json( [
'error' => true
] );
}
}
$user->account->bluevine_status = 'signed_up';
$user->account->save();
$quote_data = json_decode( $response->getBody() );
return response()->json( $quote_data );
}
public function hideMessage() {
$user = Auth::user();
if ( $user ) {
$user->account->bluevine_status = 'ignored';
$user->account->save();
}
return 'success';
}
public function handleCompleted() {
Session::flash( 'message', trans( 'texts.bluevine_completed' ) );
return Redirect::to( '/dashboard' );
}
}

View File

@ -214,6 +214,11 @@ Route::group(['middleware' => 'auth:user'], function() {
Route::put('expense_categories/{expense_categories}', 'ExpenseCategoryController@update');
Route::get('expense_categories/{expense_categories}/edit', 'ExpenseCategoryController@edit');
Route::post('expense_categories/bulk', 'ExpenseCategoryController@bulk');
// BlueVine
Route::post('bluevine/signup', 'BlueVineController@signup');
Route::get('bluevine/hide_message', 'BlueVineController@hideMessage');
Route::get('bluevine/completed', 'BlueVineController@handleCompleted');
});
Route::group([

View File

@ -13003,6 +13003,10 @@ div.panel-body div.panel-body {
width:800px;
}
}
.bluevine-quote .row{
text-align: right;
}
/*!
* Start Bootstrap - Simple Sidebar (http://startbootstrap.com/)
* Copyright 2013-2016 Start Bootstrap

File diff suppressed because one or more lines are too long

View File

@ -1234,4 +1234,8 @@ div.panel-body div.panel-body {
#bluevineModal .modal-dialog{
width:800px;
}
}
.bluevine-quote .row{
text-align: right;
}

File diff suppressed because it is too large Load Diff

View File

@ -259,7 +259,10 @@
</div>
<script type="text/javascript">
function hideBlueVineMessage() {
jQuery('#bluevinePromo').remove();
jQuery('#bluevinePromo').fadeOut();
$.get('/bluevine/hide_message', function(response) {
console.log('Reponse: %s', response);
});
return false;
}
@ -294,6 +297,7 @@
function bluevineCreateAccount() {
var form = $('#bluevineSignup');
$('#bluevineModal').find('.alert').remove();
var fields = [
'bluevine_name',
@ -344,7 +348,6 @@
hasError = true;
} else {
formGroup.removeClass('has-error').find('.error-help-block').remove();
;
}
});
@ -354,14 +357,128 @@
$('#bluevineModal .btn-primary').attr('disabled', 'disabled');
$.post(form.attr('action'), form.serialize(), function (data) {
if (data.success) {
if (!data.error) {
$('#bluevineSignup').hide();
} else {
var factoringOffer, locOffer;
if (data.factoring_offer)factoringOffer = data.factoring_offer;
else if (data.invoice_factoring_offer)factoringOffer = data;
if (data.loc_offer)locOffer = data.loc_offer;
else if (data.line_of_credit_offer)locOffer = data;
var hasOffer, redirectUrl;
if (!hasOffer && factoringOffer) {
hasOffer = factoringOffer.is_conditional_offer;
redirectUrl = factoringOffer.external_register_url;
}
if (!hasOffer && locOffer) {
hasOffer = locOffer.is_conditional_offer;
redirectUrl = locOffer.external_register_url;
}
if (!hasOffer) {
window.location.href = redirectUrl;
} else {
if (factoringOffer) {
var quoteDetails = jQuery('<div class="bluevine-quote">');
if (factoringOffer.is_conditional_offer) {
quoteDetails.append(jQuery('<h4>').text("{{ trans('texts.bluevine_conditional_offer') }}"));
quoteDetails.append(jQuery('<div class="row">').append(
jQuery('<strong class="col-sm-3">').text("{{ trans('texts.bluevine_credit_line_amount') }}"),
jQuery('<div class="col-sm-2">').text(('$' + factoringOffer.credit_line_amount).replace(/(\d)(?=(\d{3})+$)/g, '$1,'))// Add commas to number
));
// Docs claim that advance_rate is a percent from 0 to 100 without fraction,
// but in my testing the number was a percent from 0 to 1.
var advanceRate = factoringOffer.advance_rate > 1 ? factoringOffer.advance_rate : factoringOffer.advance_rate * 100;
quoteDetails.append(jQuery('<div class="row">').append(
jQuery('<strong class="col-sm-3">').text("{{ trans('texts.bluevine_advance_rate') }}"),
jQuery('<div class="col-sm-2">').text(advanceRate + '%')
));
quoteDetails.append(jQuery('<div class="row">').append(
jQuery('<strong class="col-sm-3">').text("{{ trans('texts.bluevine_weekly_discount_rate') }}"),
jQuery('<div class="col-sm-2">').text(factoringOffer.weekly_discount_rate + '%')
));
quoteDetails.append(jQuery('<div class="row">').append(
jQuery('<strong class="col-sm-3">').text("{{ trans('texts.bluevine_minimum_fee_rate') }}"),
jQuery('<div class="col-sm-2">').text(factoringOffer.minimum_fee_rate + '%')
));
} else {
quoteDetails.append(jQuery('<p>').text("{{trans('texts.bluevine_no_conditional_offer')}}"));
}
$('#bluevineModal .modal-body').append(
jQuery('<h3>').text("{{ trans('texts.bluevine_invoice_factoring') }}"),
quoteDetails
);
}
if (locOffer) {
var quoteDetails = jQuery('<div class="bluevine-quote">');
if (locOffer.is_conditional_offer) {
quoteDetails.append(jQuery('<h4>').text("{{ trans('texts.bluevine_conditional_offer') }}"));
quoteDetails.append(jQuery('<div class="row">').append(
jQuery('<strong class="col-sm-3">').text("{{ trans('texts.bluevine_credit_line_amount') }}"),
jQuery('<div class="col-sm-2">').text(('$' + locOffer.credit_line_amount).replace(/(\d)(?=(\d{3})+$)/g, '$1,'))// Add commas to number
));
quoteDetails.append(jQuery('<div class="row">').append(
jQuery('<strong class="col-sm-3">').text("{{ trans('texts.bluevine_interest_rate') }}"),
jQuery('<div class="col-sm-2">').text(locOffer.interest_rate + '%')
));
quoteDetails.append(jQuery('<div class="row">').append(
jQuery('<strong class="col-sm-3">').text("{{ trans('texts.bluevine_weekly_draw_rate') }}"),
jQuery('<div class="col-sm-2">').text(locOffer.weekly_draw_rate + '%')
));
} else {
quoteDetails.append(jQuery('<p>').text("{{trans('texts.bluevine_no_conditional_offer')}}"));
}
$('#bluevineModal .modal-body').append(
jQuery('<h3>').text("{{ trans('texts.bluevine_line_of_credit') }}"),
quoteDetails
);
}
/*<div class="row"><strong class="col-sm-4">Credit Line Amount</strong> <div class="col-sm-2">$60,000</div>
</div>
<div class="row">
<strong class="col-sm-4">Advance Rate</strong> <div class="col-sm-4">90%</div>
</div>
<div class="row">
<strong class="col-sm-4">Weekly Discount Rate</strong> <div class="col-sm-2">0.8%</div>
</div>
<div class="row">
<strong class="col-sm-4">Minimum Rate</strong> <div class="col-sm-2">1.5%</div>
</div>*/
}
$('#bluevineModal .btn-primary').replaceWith(
jQuery('<a class="btn btn-primary">').attr('href', redirectUrl).text("{{ trans('texts.bluevine_continue') }}")
)
} else {
$('#bluevineModal .modal-body').append(
jQuery('<div class="alert alert-danger">').text(data.message ? data.message : "{{ trans('texts.bluevine_unexpected_error') }}")
);
}
$('#bluevineModal .btn-primary').removeAttr('disabled');
}, 'json');
}, 'json').error(
function () {
$('#bluevineModal .modal-body').append(
jQuery('<div class="alert alert-danger">').text("{{ trans('texts.bluevine_unexpected_error') }}")
);
$('#bluevineModal .btn-primary').removeAttr('disabled');
}
);
}
</script>
@endif