1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 09:21:34 +02:00
invoiceninja/app/Http/Controllers/Bank/YodleeController.php

84 lines
2.1 KiB
PHP
Raw Normal View History

2022-07-28 06:09:13 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Http\Controllers\Bank;
2022-07-28 08:29:42 +02:00
use App\Helpers\Bank\Yodlee\Yodlee;
2022-07-28 06:09:13 +02:00
use App\Http\Controllers\BaseController;
2022-08-10 03:56:46 +02:00
use App\Http\Requests\Yodlee\YodleeAuthRequest;
2022-07-28 06:09:13 +02:00
use Illuminate\Http\Request;
class YodleeController extends BaseController
{
2022-08-10 03:56:46 +02:00
public function auth(YodleeAuthRequest $request)
2022-07-28 06:09:13 +02:00
{
2022-08-06 10:11:43 +02:00
// create a user at this point
// use the one time token here to pull in the actual user
//store the user_account_id on the accounts table
2022-08-10 03:56:46 +02:00
$yodlee = new Yodlee();
$yodlee->setTestMode();
$company = $request->getCompany();
if($company->account->bank_integration_account_id){
$flow = 'edit';
$token = $company->account->bank_integration_account_id;
}
else{
$flow = 'add';
$response = $yodlee->createUser($company);
$token = $response->user->loginName;
$company->account->bank_integration_account_id = $token;
$company->push();
}
2022-08-10 11:49:27 +02:00
$yodlee = new Yodlee($token);
$yodlee->setTestMode();
2022-08-10 03:56:46 +02:00
if(!is_string($token))
dd($token);
2022-07-28 06:09:13 +02:00
$data = [
2022-08-10 03:56:46 +02:00
'access_token' => $yodlee->getAccessToken(),
'fasttrack_url' => $yodlee->getFastTrackUrl(),
'config_name' => 'testninja',
'flow' => $flow,
2022-08-10 11:49:27 +02:00
'company' => $company,
'account' => $company->account,
2022-07-28 06:09:13 +02:00
];
return view('bank.yodlee.auth', $data);
}
2022-08-11 03:49:39 +02:00
public function refreshAccounts(YodleeAdminRequest $request)
{
$token = auth()->user()->account->bank_integration_account_id;
if(!$token)
return response()->json(['message' => 'No bank integrations are present. Please add a bank account. '],400);
$yodlee = new Yodlee($token);
$yodlee->setTestMode();
$yodlee->getAccounts();
}
2022-07-28 06:09:13 +02:00
}