mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-20 00:11:35 +02:00
Working on card authorisation for Stripe
This commit is contained in:
parent
6b8cbe4e7c
commit
0331575197
@ -42,7 +42,7 @@ class PaymentMethodController extends Controller
|
||||
'token' => false,
|
||||
];
|
||||
|
||||
return $gateway->driver()->authorizeCreditCardView($data);
|
||||
return $gateway->driver(auth()->user()->client)->authorizeCreditCardView($data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -246,7 +246,7 @@ class Client extends BaseModel
|
||||
foreach($gateways as $gateway)
|
||||
{
|
||||
|
||||
if(in_array(GatewayType::CREDIT_CARD, $gateway->driver()->gatewayTypes()))
|
||||
if(in_array(GatewayType::CREDIT_CARD, $gateway->driver($this)->gatewayTypes()))
|
||||
return $gateway;
|
||||
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Company;
|
||||
use App\Models\Gateway;
|
||||
use App\Models\GatewayType;
|
||||
@ -43,11 +44,11 @@ class CompanyGateway extends BaseModel
|
||||
}
|
||||
|
||||
/* This is the public entry point into the payment superclass */
|
||||
public function driver()
|
||||
public function driver(Client $client)
|
||||
{
|
||||
$class = static::driver_class();
|
||||
|
||||
return new $class($this);
|
||||
return new $class($this, $client);
|
||||
}
|
||||
|
||||
private function driver_class()
|
||||
|
@ -31,6 +31,11 @@ class ClientPresenter extends EntityPresenter
|
||||
return $this->entity->primary_contact->first() !== null ? $this->entity->primary_contact->first()->first_name . ' '. $this->entity->primary_contact->first()->last_name : 'No primary contact set';
|
||||
}
|
||||
|
||||
public function email()
|
||||
{
|
||||
return $this->entity->primary_contact->first() !== null ? $this->entity->primary_contact->first()->email : 'No Email Set';
|
||||
}
|
||||
|
||||
public function address()
|
||||
{
|
||||
$str = '';
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\PaymentDrivers;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\GatewayType;
|
||||
use Omnipay\Omnipay;
|
||||
@ -39,10 +40,11 @@ class BasePaymentDriver
|
||||
protected $can_authorise_credit_card = false;
|
||||
|
||||
|
||||
public function __construct(CompanyGateway $company_gateway, $invitation = false)
|
||||
public function __construct(CompanyGateway $company_gateway, Client $client, $invitation = false)
|
||||
{
|
||||
$this->company_gateway = $company_gateway;
|
||||
$this->invitation = $invitation;
|
||||
$this->client = $client;
|
||||
//$this->gatewayType = $gatewayType ?: $this->gatewayTypes()[0];
|
||||
}
|
||||
|
||||
@ -70,26 +72,6 @@ class BasePaymentDriver
|
||||
return $this->gateway->getDefaultParameters();
|
||||
}
|
||||
|
||||
public function invoice()
|
||||
{
|
||||
return $this->invitation->invoice;
|
||||
}
|
||||
|
||||
public function contact()
|
||||
{
|
||||
return $this->invitation->contact;
|
||||
}
|
||||
|
||||
public function client()
|
||||
{
|
||||
return $this->contact()->client;
|
||||
}
|
||||
|
||||
public function company()
|
||||
{
|
||||
return $this->invitation->company;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default gateway type
|
||||
*/
|
||||
@ -118,6 +100,11 @@ class BasePaymentDriver
|
||||
return $this->token_billing;
|
||||
}
|
||||
|
||||
public function canAuthoriseCreditCard()
|
||||
{
|
||||
return $this->can_authorise_credit_card;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refunds a given payment
|
||||
* @return void
|
||||
|
@ -40,9 +40,9 @@ class StripePaymentDriver extends BasePaymentDriver
|
||||
*/
|
||||
/************************************** Stripe API methods **********************************************************/
|
||||
|
||||
public function init($api_key)
|
||||
public function init()
|
||||
{
|
||||
Stripe::setApiKey($api_key);
|
||||
Stripe::setApiKey($this->company_gateway->getConfigField('23_apiKey'));
|
||||
}
|
||||
/**
|
||||
* Returns the gateway types
|
||||
@ -128,6 +128,7 @@ class StripePaymentDriver extends BasePaymentDriver
|
||||
*/
|
||||
public function createIntent($data)
|
||||
{
|
||||
$this->init();
|
||||
return PaymentIntent::create($data);
|
||||
}
|
||||
|
||||
@ -138,8 +139,7 @@ class StripePaymentDriver extends BasePaymentDriver
|
||||
*/
|
||||
public function getSetupIntent()
|
||||
{
|
||||
Stripe::setApiKey($this->company_gateway->getConfigField('23_apiKey'));
|
||||
|
||||
$this->init();
|
||||
return SetupIntent::create();
|
||||
}
|
||||
|
||||
@ -147,6 +147,29 @@ class StripePaymentDriver extends BasePaymentDriver
|
||||
{
|
||||
return $this->company_gateway->getPublishableKey();
|
||||
}
|
||||
|
||||
public function findOrCreateCustomer() :?\Stripe\Customer
|
||||
{
|
||||
|
||||
$customer = null;
|
||||
|
||||
$this->init();
|
||||
|
||||
$client_gateway_token = $this->client->gateway_tokens->whereGatewayId($this->company_gateway->gateway_id)->first();
|
||||
|
||||
if($client_gateway_token->gateway_customer_reference)
|
||||
$customer = \Stripe\Customer::retrieve($client_gateway_token->gateway_customer_reference);
|
||||
else{
|
||||
$customer = \Stripe\Customer::create([
|
||||
"email" => $this->client->present()->email(),
|
||||
"name" => $this->client->present()->name(),
|
||||
"phone" => $this->client->present()->phone(),
|
||||
]);
|
||||
}
|
||||
return $customer;
|
||||
}
|
||||
|
||||
|
||||
/************************************** Omnipay API methods **********************************************************/
|
||||
|
||||
|
||||
|
@ -906,10 +906,11 @@ class CreateUsersTable extends Migration
|
||||
$table->increments('id');
|
||||
$table->unsignedInteger('company_id');
|
||||
$table->unsignedInteger('client_id')->nullable();
|
||||
$table->text('token');
|
||||
$table->text('token')->default('');
|
||||
$table->unsignedInteger('company_gateway_id');
|
||||
$table->string('gateway_customer_reference')->default('');
|
||||
$table->unsignedInteger('payment_method_id');
|
||||
$table->boolean('is_default');
|
||||
$table->boolean('is_default')->default(0);
|
||||
$table->timestamps(6);
|
||||
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
||||
$table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
|
||||
@ -919,7 +920,7 @@ class CreateUsersTable extends Migration
|
||||
$table->increments('id');
|
||||
$table->unsignedInteger('company_id');
|
||||
$table->unsignedInteger('user_id')->nullable();
|
||||
$table->string('name');
|
||||
$table->string('name')->default('');
|
||||
$table->text('settings');
|
||||
|
||||
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
|
||||
|
@ -49,7 +49,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@include($gateway->driver()->viewForType($payment_method_id))
|
||||
@include($gateway->driver(auth()->user()->client)->viewForType($payment_method_id))
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
@ -3,13 +3,16 @@
|
||||
@section('credit_card')
|
||||
|
||||
<div class="py-md-5 ninja stripe">
|
||||
<input id="cardholder-name" type="text">
|
||||
<div class="form-group">
|
||||
|
||||
<input class="form-control" id="cardholder-name" type="text" placeholder="{{ ctrans('texts.name') }}">
|
||||
<!-- placeholder for Elements -->
|
||||
<div id="card-element"></div>
|
||||
<button id="card-button" data-secret="<?= $intent->client_secret ?>">
|
||||
Save Card
|
||||
<div id="card-element" class="form-control"></div>
|
||||
<button id="card-button" class="btn btn-primary pull-right" data-secret="{{ $intent->client_secret }}">
|
||||
{{ ctrans('texts.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
@push('scripts')
|
||||
@ -48,7 +51,33 @@
|
||||
|
||||
@push('css')
|
||||
<style type="text/css">
|
||||
.StripeElement {
|
||||
box-sizing: border-box;
|
||||
|
||||
height: 40px;
|
||||
|
||||
padding: 10px 12px;
|
||||
|
||||
border: 1px solid transparent;
|
||||
border-radius: 4px;
|
||||
background-color: white;
|
||||
|
||||
box-shadow: 0 1px 3px 0 #e6ebf1;
|
||||
-webkit-transition: box-shadow 150ms ease;
|
||||
transition: box-shadow 150ms ease;
|
||||
}
|
||||
|
||||
.StripeElement--focus {
|
||||
box-shadow: 0 1px 3px 0 #cfd7df;
|
||||
}
|
||||
|
||||
.StripeElement--invalid {
|
||||
border-color: #fa755a;
|
||||
}
|
||||
|
||||
.StripeElement--webkit-autofill {
|
||||
background-color: #fefde5 !important;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user