Fleshing out payment drivers

This commit is contained in:
David Bomba 2019-09-06 09:00:23 +10:00
parent f8734db1b6
commit f72bd34483

View File

@ -21,11 +21,16 @@ use Omnipay\Omnipay;
*/ */
class BasePaymentDriver class BasePaymentDriver
{ {
/* The company gateway instance*/
protected $company_gateway; protected $company_gateway;
/* The Omnipay payment driver instance*/
protected $gateway; protected $gateway;
/* Member variables */
protected $refundable = false;
protected $token_billing = false;
public function __construct(CompanyGateway $company_gateway) public function __construct(CompanyGateway $company_gateway)
{ {
$this->company_gateway = $company_gateway; $this->company_gateway = $company_gateway;
@ -33,37 +38,74 @@ class BasePaymentDriver
//$this->gatewayType = $gatewayType ?: $this->gatewayTypes()[0]; //$this->gatewayType = $gatewayType ?: $this->gatewayTypes()[0];
} }
/* Stubbed in parent, but should never be initialized
* The boot method should be used in the superclass
* to initialize all the member variables for the
* given driver / payment gateway
*
* ie.
*
* ->gateway()
* ->setRefundable(true)
* ->setTokenBilling(true)
*
* @return Instance
*/
public function boot(){}
/** /**
* Returns the Omnipay driver * Returns the Omnipay driver
* @return object Omnipay initialized object * @return object Omnipay initialized object
*/ */
protected function gateway() protected function gateway()
{ {
if ($this->gateway)
return $this->gateway;
$this->gateway = Omnipay::create($this->company_gateway->gateway->provider); $this->gateway = Omnipay::create($this->company_gateway->gateway->provider);
$this->gateway->initialize((array) $this->company_gateway->getConfig()); $this->gateway->initialize((array) $this->company_gateway->getConfig());
return $this->gateway; return $this;
} }
public function setRefundable($value)
{
$this->refundable = $value;
return $this;
}
/** /**
* Returns whether refunds are possible with the gateway * Returns whether refunds are possible with the gateway
* @return boolean TRUE|FALSE * @return boolean TRUE|FALSE
*/ */
public function isRefundable() :bool {} public function getRefundable()
{
return $this->refundable;
}
public function setTokenBilling($value)
{
$this->token_billing = $value;
return $this;
}
/** /**
* Returns whether token billing is possible with the gateway * Returns whether token billing is possible with the gateway
* @return boolean TRUE|FALSE * @return boolean TRUE|FALSE
*/ */
public function hasTokenBilling() :bool {} public function getTokenBilling()
{
return $this->token_billing;
}
/** /**
* Refunds a given payment * Refunds a given payment
* @return void * @return void
*/ */
public function refundPayment() {} public function refundPayment()
{
}
} }