mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Working on Stripe payment driver
This commit is contained in:
parent
03c3cc8702
commit
f8734db1b6
@ -41,4 +41,81 @@ class CompanyGateway extends Model
|
||||
{
|
||||
return $this->hasOne(GatewayType::class);
|
||||
}
|
||||
|
||||
/* This is the public entry point into the payment superclass */
|
||||
public function driver()
|
||||
{
|
||||
$class = static::driver_class();
|
||||
|
||||
return new $class($this);
|
||||
}
|
||||
|
||||
private function driver_class()
|
||||
{
|
||||
$class = 'App\\PaymentDrivers\\' . $this->gateway->provider . 'PaymentDriver';
|
||||
$class = str_replace('\\', '', $class);
|
||||
$class = str_replace('_', '', $class);
|
||||
|
||||
if (class_exists($class)) {
|
||||
return $class;
|
||||
} else {
|
||||
return 'App\\PaymentDrivers\\BasePaymentDriver';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getAchEnabled()
|
||||
{
|
||||
return ! empty($this->getConfigField('enableAch'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getApplePayEnabled()
|
||||
{
|
||||
return ! empty($this->getConfigField('enableApplePay'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getAlipayEnabled()
|
||||
{
|
||||
return ! empty($this->getConfigField('enableAlipay'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getSofortEnabled()
|
||||
{
|
||||
return ! empty($this->getConfigField('enableSofort'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getSepaEnabled()
|
||||
{
|
||||
return ! empty($this->getConfigField('enableSepa'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getBitcoinEnabled()
|
||||
{
|
||||
return ! empty($this->getConfigField('enableBitcoin'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getPayPalEnabled()
|
||||
{
|
||||
return ! empty($this->getConfigField('enablePayPal'));
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,41 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Omnipay\Omnipay;
|
||||
|
||||
class Gateway extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFields()
|
||||
{
|
||||
|
||||
if ($this->isCustom())
|
||||
{
|
||||
return [
|
||||
'name' => '',
|
||||
'text' => '',
|
||||
];
|
||||
} else
|
||||
{
|
||||
return Omnipay::create($this->provider)->getDefaultParameters();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if gateway is custom
|
||||
* @return boolean TRUE|FALSE
|
||||
*/
|
||||
public function isCustom() :bool
|
||||
{
|
||||
|
||||
return in_array($this->id, [62, 67, 68]); //static table ids of the custom gateways
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,14 +11,44 @@
|
||||
|
||||
namespace App\PaymentDrivers;
|
||||
|
||||
use App\Models\CompanyGateway;
|
||||
use Omnipay\Omnipay;
|
||||
|
||||
|
||||
/**
|
||||
* Class BasePaymentDriver
|
||||
* @package App\PaymentDrivers
|
||||
*/
|
||||
abstract class BasePaymentDriver
|
||||
class BasePaymentDriver
|
||||
{
|
||||
|
||||
protected $company_gateway;
|
||||
|
||||
protected $gateway;
|
||||
|
||||
public function __construct(CompanyGateway $company_gateway)
|
||||
{
|
||||
$this->company_gateway = $company_gateway;
|
||||
//$this->invitation = $invitation;
|
||||
//$this->gatewayType = $gatewayType ?: $this->gatewayTypes()[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Omnipay driver
|
||||
* @return object Omnipay initialized object
|
||||
*/
|
||||
protected function gateway()
|
||||
{
|
||||
if ($this->gateway)
|
||||
return $this->gateway;
|
||||
|
||||
$this->gateway = Omnipay::create($this->company_gateway->gateway->provider);
|
||||
$this->gateway->initialize((array) $this->company_gateway->getConfig());
|
||||
|
||||
return $this->gateway;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether refunds are possible with the gateway
|
||||
* @return boolean TRUE|FALSE
|
||||
@ -32,9 +62,8 @@ abstract class BasePaymentDriver
|
||||
public function hasTokenBilling() :bool {}
|
||||
|
||||
/**
|
||||
* Returns the Omnipay driver
|
||||
* @return object Omnipay initialized object
|
||||
* Refunds a given payment
|
||||
* @return void
|
||||
*/
|
||||
public function gateway() {}
|
||||
|
||||
public function refundPayment() {}
|
||||
}
|
@ -11,7 +11,39 @@
|
||||
|
||||
namespace App\PaymentDrivers;
|
||||
|
||||
use Stripe\Stripe;
|
||||
|
||||
class StripePaymentDriver extends BasePaymentDriver
|
||||
{
|
||||
|
||||
/**
|
||||
* Methods in this class are divided into
|
||||
* two separate streams
|
||||
*
|
||||
* 1. Omnipay Specific
|
||||
* 2. Stripe Specific
|
||||
*
|
||||
* Our Stripe integration is deeper than
|
||||
* other gateways and therefore
|
||||
* relies on direct calls to the API
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/************************************** Omnipay API methods **********************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/************************************** Stripe API methods **********************************************************/
|
||||
|
||||
public function init($api_key)
|
||||
{
|
||||
Stripe::setApiKey($api_key);
|
||||
}
|
||||
|
||||
}
|
@ -39,6 +39,7 @@
|
||||
"sentry/sentry-laravel": "^1.0",
|
||||
"simshaun/recurr": "^4.0",
|
||||
"spatie/browsershot": "^3.29",
|
||||
"stripe/stripe-php": "^7.0",
|
||||
"superbalist/laravel-google-cloud-storage": "^2.2",
|
||||
"webpatser/laravel-countries": "dev-master#75992ad",
|
||||
"wildbit/postmark-php": "^2.6",
|
||||
|
@ -345,7 +345,7 @@ class CreateUsersTable extends Migration
|
||||
});
|
||||
|
||||
|
||||
Schema::create('account_gateways', function($table)
|
||||
Schema::create('company_gateways', function($table)
|
||||
{
|
||||
$table->increments('id');
|
||||
$table->unsignedInteger('company_id')->unique();
|
||||
|
Loading…
x
Reference in New Issue
Block a user