diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index f53d65a259a0..9e92c7a8fc20 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -35,12 +35,15 @@ class PaymentMethodController extends Controller */ public function create() { + $gateway = auth()->user()->client->getCreditCardGateway(); + $data = [ 'gateway' => $gateway, 'token' => false, ]; - return view('portal.default.gateways.authorize', $data); + return $gateway->driver()->authorizeCreditCardView($data); + //return view('portal.default.gateways.authorize', $data); } /** diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 4f20484f9d80..2122f7e49346 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -34,7 +34,7 @@ class CompanyGateway extends BaseModel public function gateway() { - return $this->hasOne(Gateway::class); + return $this->belongsTo(Gateway::class); } public function type() @@ -53,9 +53,12 @@ class CompanyGateway extends BaseModel private function driver_class() { $class = 'App\\PaymentDrivers\\' . $this->gateway->provider . 'PaymentDriver'; - $class = str_replace('\\', '', $class); + //$class = str_replace('\\', '', $class); $class = str_replace('_', '', $class); + \Log::error($class); + + if (class_exists($class)) { return $class; } else { @@ -63,22 +66,39 @@ class CompanyGateway extends BaseModel } } - public function getConfigAttribute() + /** + * @param $config + */ + public function setConfig($config) { - return decrypt($this->config); + $this->config = encrypt(json_encode($config)); } - public function setConfigAttribute($value) + /** + * @return mixed + */ + public function getConfig() { - $this->attributes['config'] = encrypt(json_encode($value)); + return json_decode(decrypt($this->config)); } + /** + * @param $field + * + * @return mixed + */ + public function getConfigField($field) + { + return object_get($this->getConfig(), $field, false); + } + + /** * @return bool */ public function getAchEnabled() { - return ! empty($this->config('enableAch')); + return ! empty($this->getConfigField('enableAch')); } /** @@ -86,7 +106,7 @@ class CompanyGateway extends BaseModel */ public function getApplePayEnabled() { - return ! empty($this->config('enableApplePay')); + return ! empty($this->getConfigField('enableApplePay')); } /** @@ -94,7 +114,7 @@ class CompanyGateway extends BaseModel */ public function getAlipayEnabled() { - return ! empty($this->config('enableAlipay')); + return ! empty($this->getConfigField('enableAlipay')); } /** @@ -102,7 +122,7 @@ class CompanyGateway extends BaseModel */ public function getSofortEnabled() { - return ! empty($this->config('enableSofort')); + return ! empty($this->getConfigField('enableSofort')); } /** @@ -110,7 +130,7 @@ class CompanyGateway extends BaseModel */ public function getSepaEnabled() { - return ! empty($this->config('enableSepa')); + return ! empty($this->getConfigField('enableSepa')); } /** @@ -118,7 +138,7 @@ class CompanyGateway extends BaseModel */ public function getBitcoinEnabled() { - return ! empty($this->config('enableBitcoin')); + return ! empty($this->getConfigField('enableBitcoin')); } /** @@ -126,7 +146,7 @@ class CompanyGateway extends BaseModel */ public function getPayPalEnabled() { - return ! empty($this->config('enablePayPal')); + return ! empty($this->getConfigField('enablePayPal')); } public function feesEnabled() @@ -134,6 +154,16 @@ class CompanyGateway extends BaseModel return floatval($this->fee_amount) || floatval($this->fee_percent); } + /** + * Get Publishable Key + * Only works for STRIPE and PAYMILL + * @return string The Publishable key + */ + public function getPublishableKey() :string + { + return $this->getConfigField('publishableKey'); + } + /** * Returns the formatted fee amount for the gateway * diff --git a/app/PaymentDrivers/BasePaymentDriver.php b/app/PaymentDrivers/BasePaymentDriver.php index 5bee2dde2937..c78280fcbe8a 100644 --- a/app/PaymentDrivers/BasePaymentDriver.php +++ b/app/PaymentDrivers/BasePaymentDriver.php @@ -57,6 +57,16 @@ class BasePaymentDriver } + /** + * Return the configuration fields for the + * Gatway + * @return array The configuration fields + */ + public function getFields() + { + return $this->gateway->getDefaultParameters(); + } + public function invoice() { return $this->invitation->invoice; @@ -146,5 +156,6 @@ class BasePaymentDriver /* $this->purchaseResponse = (array)$response->getData();*/ } - + + } \ No newline at end of file diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 26f213e033c9..a9f818618f36 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -13,6 +13,7 @@ namespace App\PaymentDrivers; use App\Models\GatewayType; use Stripe\PaymentIntent; +use Stripe\SetupIntent; use Stripe\Stripe; class StripePaymentDriver extends BasePaymentDriver @@ -78,28 +79,28 @@ class StripePaymentDriver extends BasePaymentDriver { switch ($payment_type) { case GatewayType::CREDIT_CARD: - return 'gateways.stripe.credit_card'; + return 'portal.default.gateways.stripe.credit_card'; break; case GatewayType::TOKEN: - return 'gateways.stripe.credit_card'; + return 'portal.default.gateways.stripe.credit_card'; break; case GatewayType::SOFORT: - return 'gateways.stripe.sofort'; + return 'portal.default.gateways.stripe.sofort'; break; case GatewayType::BANK_TRANSFER: - return 'gateways.stripe.ach'; + return 'portal.default.gateways.stripe.ach'; break; case GatewayType::SEPA: - return 'gateways.stripe.sepa'; + return 'portal.default.gateways.stripe.sepa'; break; case GatewayType::BITCOIN: - return 'gateways.stripe.other'; + return 'portal.default.gateways.stripe.other'; break; case GatewayType::ALIPAY: - return 'gateways.stripe.other'; + return 'portal.default.gateways.stripe.other'; break; case GatewayType::APPLE_PAY: - return 'gateways.stripe.other'; + return 'portal.default.gateways.stripe.other'; break; default: @@ -108,6 +109,13 @@ class StripePaymentDriver extends BasePaymentDriver } } + public function authorizeCreditCardView($data) + { + + return view('portal.default.gateways.stripe.create_customer', $data); + + } + /** * Creates a new String Payment Intent * @param array $data The data array to be passed to Stripe @@ -117,6 +125,21 @@ class StripePaymentDriver extends BasePaymentDriver { return PaymentIntent::create($data); } + + /** + * Returns a setup intent that allows the user to enter card details without initiating a transaction. + * + * @return \Stripe\SetupIntent + */ + public function getSetupIntent() + { + return SetupIntent::create(); + } + + public function getPublishableKey() + { + return $this->company_gateway->getPublishableKey(); + } /************************************** Omnipay API methods **********************************************************/ diff --git a/config/ninja.php b/config/ninja.php index 1ee7b38b0b7d..6c9f645b6b13 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -58,6 +58,7 @@ return [ 'username' => 'user@example.com', 'clientname' => 'client@example.com', 'password' => 'password', + 'stripe' => env('STRIPE_KEYS',''), ], 'contact' => [ diff --git a/database/seeds/RandomDataSeeder.php b/database/seeds/RandomDataSeeder.php index 835c07d9cdd6..4feae7e9562e 100644 --- a/database/seeds/RandomDataSeeder.php +++ b/database/seeds/RandomDataSeeder.php @@ -6,7 +6,9 @@ use App\DataMapper\DefaultSettings; use App\Models\Account; use App\Models\Client; use App\Models\ClientContact; +use App\Models\CompanyGateway; use App\Models\CompanyToken; +use App\Models\GatewayType; use App\Models\GroupSetting; use App\Models\User; use App\Models\UserAccount; @@ -127,6 +129,29 @@ class RandomDataSeeder extends Seeder 'name' => 'Default Client Settings', ]); + + \Log::error("stripe keys?"); + \Log::error(config('ninja.testvars.stripe')); + + if(config('ninja.testvars.stripe')) + { + \Log::error("inserting stripe keys"); + $cg = new CompanyGateway; + $cg->company_id = $company->id; + $cg->user_id = $user->id; + $cg->gateway_id = 20; + $cg->gateway_type_id = GatewayType::CREDIT_CARD; + $cg->require_cvv = true; + $cg->show_address = true; + $cg->show_shipping_address = true; + $cg->update_details = true; + $cg->config = encrypt(env('STRIPE_KEYS')); + $cg->priority_id = 1; + $cg->save(); + } + } + + } diff --git a/resources/views/portal/default/gateways/authorize.blade.php b/resources/views/portal/default/gateways/authorize.blade.php index 817b811df15c..7a03b937cea7 100644 --- a/resources/views/portal/default/gateways/authorize.blade.php +++ b/resources/views/portal/default/gateways/authorize.blade.php @@ -14,7 +14,7 @@