mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
wip
This commit is contained in:
parent
7f1621b2fd
commit
eef9065f08
@ -67,19 +67,18 @@ class OneTimeTokenController extends BaseController
|
||||
*/
|
||||
public function create(OneTimeTokenRequest $request)
|
||||
{
|
||||
|
||||
$hash = Str::random(64);
|
||||
|
||||
$data = [
|
||||
'user_id' => auth()->user()->id,
|
||||
'company_key'=> auth()->company()->company_key,
|
||||
'context' => $requst->input('context'),
|
||||
'company_key'=> auth()->user()->company->company_key,
|
||||
'context' => $request->input('context'),
|
||||
];
|
||||
|
||||
Cache::put( $hash, $data, 3600 );
|
||||
|
||||
return response()->json(['hash' => $hash], 200);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function router(OneTimeRouterRequest $request)
|
||||
|
45
app/Http/Controllers/StripeConnectController.php
Normal file
45
app/Http/Controllers/StripeConnectController.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\StripeConnect\InitializeStripeConnectRequest;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\PaymentDrivers\Stripe\Connect\Account;
|
||||
use Stripe\Exception\ApiErrorException;
|
||||
|
||||
class StripeConnectController extends BaseController
|
||||
{
|
||||
/**
|
||||
* Initialize Stripe Connect flow.
|
||||
*
|
||||
* @param string $token One-time token
|
||||
* @throws ApiErrorException
|
||||
*/
|
||||
public function initialize(InitializeStripeConnectRequest $request, string $token)
|
||||
{
|
||||
// $request->getTokenContent();
|
||||
|
||||
$data = [
|
||||
'email' => 'user@example.com',
|
||||
'country' => 'US',
|
||||
];
|
||||
|
||||
$account = Account::create($data);
|
||||
|
||||
$link = Account::link($account->id);
|
||||
|
||||
// Store account->id into company_gateways.
|
||||
|
||||
return redirect($link['url']);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Http\Requests\StripeConnect;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class InitializeStripeConnectRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve one-time token instance.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTokenContent()
|
||||
{
|
||||
$data = Cache::get($this->input('token'));
|
||||
|
||||
abort_if(!$data, 404);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -12,24 +12,40 @@
|
||||
|
||||
namespace App\PaymentDrivers\Stripe\Connect;
|
||||
|
||||
use App\Exceptions\PaymentFailed;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Jobs\Mail\PaymentFailureMailer;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Models\ClientGatewayToken;
|
||||
use App\Models\GatewayType;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentType;
|
||||
use App\Models\SystemLog;
|
||||
use App\PaymentDrivers\StripePaymentDriver;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Exception;
|
||||
use Stripe\Customer;
|
||||
use Stripe\Exception\CardException;
|
||||
use Stripe\Exception\InvalidRequestException;
|
||||
|
||||
class Account
|
||||
{
|
||||
/**
|
||||
* @throws \Stripe\Exception\ApiErrorException
|
||||
*/
|
||||
public static function create(array $payload): \Stripe\Account
|
||||
{
|
||||
$stripe = new \Stripe\StripeClient(
|
||||
config('ninja.stripe_private_key')
|
||||
);
|
||||
|
||||
return $stripe->accounts->create([
|
||||
'type' => 'standard',
|
||||
'country' => $payload['country'],
|
||||
'email' => $payload['email'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Stripe\Exception\ApiErrorException
|
||||
*/
|
||||
public static function link(string $account_id): \Stripe\AccountLink
|
||||
{
|
||||
$stripe = new \Stripe\StripeClient(
|
||||
config('ninja.stripe_private_key')
|
||||
);
|
||||
|
||||
return $stripe->accountLinks->create([
|
||||
'account' => $account_id,
|
||||
'refresh_url' => 'http://localhost:8080/stripe_connect/reauth',
|
||||
'return_url' => 'http://localhost:8080/stripe_connect/return',
|
||||
'type' => 'account_onboarding',
|
||||
]);
|
||||
}
|
||||
|
||||
/*** If this is a new account (ie there is no account_id in company_gateways.config, the we need to create an account as below.
|
||||
|
||||
@ -148,7 +164,7 @@ class Account
|
||||
|
||||
// now we start the stripe onboarding flow
|
||||
// https://stripe.com/docs/api/account_links/object
|
||||
//
|
||||
//
|
||||
/**
|
||||
* $stripe = new \Stripe\StripeClient(
|
||||
'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
|
||||
@ -162,7 +178,7 @@ $stripe->accountLinks->create([
|
||||
*/
|
||||
|
||||
/**
|
||||
* Response =
|
||||
* Response =
|
||||
* {
|
||||
"object": "account_link",
|
||||
"created": 1618869558,
|
||||
@ -177,11 +193,11 @@ $stripe->accountLinks->create([
|
||||
|
||||
|
||||
// What next?
|
||||
//
|
||||
//
|
||||
// Now we need to create a superclass of the StripePaymentDriver, i believe the only thing we need to change is the way we initialize the gateway..
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
\Stripe\Stripe::setApiKey("{{PLATFORM_SECRET_KEY}}"); <--- platform secret key = Invoice Ninja secret key
|
||||
\Stripe\Customer::create(
|
||||
["email" => "person@example.edu"],
|
||||
@ -191,4 +207,4 @@ $stripe->accountLinks->create([
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -147,4 +147,5 @@ return [
|
||||
'webcron_secret' => env('WEBCRON_SECRET', false),
|
||||
'disable_auto_update' => env('DISABLE_AUTO_UPDATE', false),
|
||||
'invoiceninja_hosted_pdf_generation' => env('NINJA_HOSTED_PDF', false),
|
||||
'stripe_private_key' => env('STRIPE_PRIVATE_KEY', null),
|
||||
];
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Gateway;
|
||||
use App\Utils\Ninja;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
@ -17,24 +19,22 @@ class StripeConnectGateway extends Migration
|
||||
Model::unguard();
|
||||
|
||||
$gateway = [
|
||||
'id' => 56,
|
||||
'name' => 'Stripe Connect',
|
||||
'provider' => 'StripeConnect',
|
||||
'sort_order' => 1,
|
||||
'key' => 'd14dd26a47cecc30fdd65700bfb67b34',
|
||||
'id' => 56,
|
||||
'name' => 'Stripe Connect',
|
||||
'provider' => 'StripeConnect',
|
||||
'sort_order' => 1,
|
||||
'key' => 'd14dd26a47cecc30fdd65700bfb67b34',
|
||||
'fields' => '{"apiKey":"", "publishableKey":""}'
|
||||
];
|
||||
|
||||
Gateway::create($gateway);
|
||||
|
||||
if(Ninja::isNinja())
|
||||
{
|
||||
if (Ninja::isNinja()) {
|
||||
Gateway::where('id', 20)->update(['visible' => 0]);
|
||||
Gateway::where('id', 56)->update(['visible' => 1]);
|
||||
}
|
||||
|
||||
Model::guard();
|
||||
|
||||
Model::reguard();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -187,6 +187,11 @@ Route::match(['get', 'post'], 'payment_webhook/{company_key}/{company_gateway_id
|
||||
->name('payment_webhook');
|
||||
|
||||
Route::post('api/v1/postmark_webhook', 'PostMarkController@webhook');
|
||||
|
||||
Route::get('token_hash_router', 'OneTimeTokenController@router');
|
||||
|
||||
Route::get('webcron', 'WebCronController@index');
|
||||
|
||||
Route::get('stripe_connect/{token}', 'StripeConnectController@initialize')->name('stripe_connect.initialization');
|
||||
|
||||
Route::fallback('BaseController@notFound');
|
||||
|
Loading…
x
Reference in New Issue
Block a user