Working on gateway payment flow

This commit is contained in:
David Bomba 2019-09-08 22:13:55 +10:00
parent 0b0f0759f1
commit 0856fc2dfd
10 changed files with 106 additions and 14 deletions

View File

@ -90,6 +90,8 @@ class ClientSettings extends BaseSettings
public $size_id; public $size_id;
public $design; public $design;
public $default_company_gateway_id;
/** /**
* Cast object values and return entire class * Cast object values and return entire class
* prevents missing properties from not being returned * prevents missing properties from not being returned

View File

@ -112,6 +112,8 @@ class CompanySettings extends BaseSettings
public $counter_padding; public $counter_padding;
public $design; public $design;
public $default_company_gateway_id;
/** /**
* Cast object values and return entire class * Cast object values and return entire class
* prevents missing properties from not being returned * prevents missing properties from not being returned

View File

@ -35,7 +35,7 @@ class PaymentMethodController extends Controller
*/ */
public function create() public function create()
{ {
// echo 'hello';
} }
/** /**

View File

@ -104,5 +104,6 @@ class Kernel extends HttpKernel
'contact_token_auth' => \App\Http\Middleware\ContactTokenAuth::class, 'contact_token_auth' => \App\Http\Middleware\ContactTokenAuth::class,
'contact_db' => \App\Http\Middleware\ContactSetDb::class, 'contact_db' => \App\Http\Middleware\ContactSetDb::class,
'domain_db' => \App\Http\Middleware\SetDomainNameDb::class, 'domain_db' => \App\Http\Middleware\SetDomainNameDb::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
]; ];
} }

View File

@ -154,7 +154,15 @@ class Client extends BaseModel
public function getPaymentMethods() public function getPaymentMethods()
{ {
$settings = $this->getMergedSettings();
/* If we have a single default gateway - pass this back now.*/
if($settings->default_company_gateway_id);
return $settings->default_company_gateway_id;
/* If there is no default, then we pass back the Collection of gateways */
$gateways = $this->company->company_gateways;
} }

View File

@ -16,12 +16,29 @@ use Illuminate\Database\Eloquent\Model;
class GatewayType extends Model class GatewayType extends Model
{ {
public $timestamps = false; public $timestamps = false;
const CREDIT_CARD = 1;
const BANK_TRANSFER = 2;
const PAYPAL = 3;
const BITCOIN = 4;
const DWOLLA = 5;
const CUSTOM1 = 6;
const ALIPAY = 7;
const SOFORT = 8;
const SEPA = 9;
const GOCARDLESS = 10;
const APPLE_PAY = 11;
const CUSTOM2 = 12;
const CUSTOM3 = 13;
const TOKEN = 'token');
public function gateway() public function gateway()
{ {
return $this->belongsTo(Gateway::class); return $this->belongsTo(Gateway::class);
} }
} }

View File

@ -15,5 +15,4 @@ use Illuminate\Database\Eloquent\Model;
class PaymentType extends Model class PaymentType extends Model
{ {
//
} }

View File

@ -12,6 +12,7 @@
namespace App\PaymentDrivers; namespace App\PaymentDrivers;
use App\Models\CompanyGateway; use App\Models\CompanyGateway;
use App\Models\GatewayType;
use Omnipay\Omnipay; use Omnipay\Omnipay;
@ -27,14 +28,17 @@ class BasePaymentDriver
/* The Omnipay payment driver instance*/ /* The Omnipay payment driver instance*/
protected $gateway; protected $gateway;
/* The Invitation */
protected $invitation;
/* Member variables */ /* Member variables */
protected $refundable = false; protected $refundable = false;
protected $token_billing = false; protected $token_billing = false;
public function __construct(CompanyGateway $company_gateway) public function __construct(CompanyGateway $company_gateway, $invitation = false)
{ {
$this->company_gateway = $company_gateway; $this->company_gateway = $company_gateway;
//$this->invitation = $invitation; $this->invitation = $invitation;
//$this->gatewayType = $gatewayType ?: $this->gatewayTypes()[0]; //$this->gatewayType = $gatewayType ?: $this->gatewayTypes()[0];
} }
@ -67,6 +71,35 @@ class BasePaymentDriver
} }
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
*/
public function gatewayTypes()
{
return [
GatewayType::CREDIT_CARD,
];
}
public function setRefundable($value) public function setRefundable($value)
{ {

View File

@ -11,6 +11,7 @@
namespace App\PaymentDrivers; namespace App\PaymentDrivers;
use App\Models\GatewayType;
use Stripe\Stripe; use Stripe\Stripe;
class StripePaymentDriver extends BasePaymentDriver class StripePaymentDriver extends BasePaymentDriver
@ -21,6 +22,7 @@ class StripePaymentDriver extends BasePaymentDriver
protected $customer_reference = 'customerReferenceParam'; protected $customer_reference = 'customerReferenceParam';
public function boot() public function boot()
{ {
$this->setRefundable($this->refundable); $this->setRefundable($this->refundable);
@ -37,9 +39,44 @@ class StripePaymentDriver extends BasePaymentDriver
* other gateways and therefore * other gateways and therefore
* relies on direct calls to the API * relies on direct calls to the API
*/ */
/************************************** Stripe API methods **********************************************************/
public function init($api_key)
{
Stripe::setApiKey($api_key);
}
/**
* Returns the gateway types
*/
public function gatewayTypes() :array
{
$types = [
GatewayType::CREDIT_CARD,
GatewayType::TOKEN,
];
if($this->company_gateway->getSofortEnabled() && $this->invitation && $this->client() && isset($this->client()->country) && in_array($this->client()->country, ['AUT', 'BEL', 'DEU', 'ITA', 'NLD', 'ESP']))
$types[] = GatewayType::SOFORT;
if($this->company_gateway->getAchEnabled())
$types[] = GatewayType::BANK_TRANSFER;
if ($this->company_gateway->getSepaEnabled())
$types[] = GatewayType::SEPA;
if ($this->company_gateway->getBitcoinEnabled())
$types[] = GatewayType::BITCOIN;
if ($this->company_gateway->getAlipayEnabled())
$types[] = GatewayType::ALIPAY;
if ($this->company_gateway->getApplePayEnabled())
$types[] = GatewayType::APPLE_PAY;
return $types;
}
/************************************** Omnipay API methods **********************************************************/ /************************************** Omnipay API methods **********************************************************/
@ -48,11 +85,4 @@ class StripePaymentDriver extends BasePaymentDriver
/************************************** Stripe API methods **********************************************************/
public function init($api_key)
{
Stripe::setApiKey($api_key);
}
} }

View File

@ -95,7 +95,7 @@
<div class="col-sm-6 col-lg-3"> <div class="col-sm-6 col-lg-3">
<div class="card text-white bg-secondary h-100"> <div class="card text-white bg-secondary h-100">
<div class="card-body align-items-center d-flex justify-content-center"> <div class="card-body align-items-center d-flex justify-content-center">
<button class="btn btn-primary btn-lg"><i class="fa fa-plus" style="" aria-hidden="true"></i> {{ ctrans('texts.add_payment_method')}}</button> <a class="btn btn-primary btn-lg" href="{{ route('client.payment_methods.create') }}"><i class="fa fa-plus" style="" aria-hidden="true"></i> {{ ctrans('texts.add_payment_method')}}</a>
</div> </div>
</div> </div>
</div> </div>