diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index cb3c6fc69117..3bfbaece968b 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -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')); + } } diff --git a/app/Models/Gateway.php b/app/Models/Gateway.php index 5c49cfc9db71..d7d9f4248355 100644 --- a/app/Models/Gateway.php +++ b/app/Models/Gateway.php @@ -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 + + } + } diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index 4236c5c98121..10b9a3c6a26b 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -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() {} } \ No newline at end of file diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 1d3cbda85c9f..5028998cb5fe 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -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); + } + } \ No newline at end of file diff --git a/composer.json b/composer.json index 6a93d6a9cbd0..48938ffb5bda 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index dbefcee0018b..a9a90b6f37f6 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -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();