2019-09-05 09:00:12 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\PaymentDrivers;
|
|
|
|
|
2019-09-16 06:59:59 +02:00
|
|
|
use App\Models\Client;
|
2019-09-25 07:55:52 +02:00
|
|
|
use App\Models\ClientContact;
|
2019-09-05 14:42:26 +02:00
|
|
|
use App\Models\CompanyGateway;
|
2019-09-08 14:13:55 +02:00
|
|
|
use App\Models\GatewayType;
|
2019-09-25 07:55:52 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2019-09-05 14:42:26 +02:00
|
|
|
use Omnipay\Omnipay;
|
|
|
|
|
2019-09-05 09:00:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class BasePaymentDriver
|
|
|
|
* @package App\PaymentDrivers
|
|
|
|
*/
|
2019-09-05 14:42:26 +02:00
|
|
|
class BasePaymentDriver
|
2019-09-05 09:00:12 +02:00
|
|
|
{
|
2019-09-06 01:00:23 +02:00
|
|
|
/* The company gateway instance*/
|
2019-09-05 14:42:26 +02:00
|
|
|
protected $company_gateway;
|
|
|
|
|
2019-09-06 01:00:23 +02:00
|
|
|
/* The Omnipay payment driver instance*/
|
2019-09-05 14:42:26 +02:00
|
|
|
protected $gateway;
|
|
|
|
|
2019-09-08 14:13:55 +02:00
|
|
|
/* The Invitation */
|
|
|
|
protected $invitation;
|
|
|
|
|
2019-09-06 01:00:23 +02:00
|
|
|
/* Member variables */
|
|
|
|
protected $refundable = false;
|
2019-09-13 07:52:01 +02:00
|
|
|
|
2019-09-06 01:00:23 +02:00
|
|
|
protected $token_billing = false;
|
|
|
|
|
2019-09-15 13:40:46 +02:00
|
|
|
protected $can_authorise_credit_card = false;
|
|
|
|
|
|
|
|
|
2019-09-16 06:59:59 +02:00
|
|
|
public function __construct(CompanyGateway $company_gateway, Client $client, $invitation = false)
|
2019-09-05 14:42:26 +02:00
|
|
|
{
|
|
|
|
$this->company_gateway = $company_gateway;
|
2019-09-08 14:13:55 +02:00
|
|
|
$this->invitation = $invitation;
|
2019-09-16 06:59:59 +02:00
|
|
|
$this->client = $client;
|
2019-09-05 14:42:26 +02:00
|
|
|
//$this->gatewayType = $gatewayType ?: $this->gatewayTypes()[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the Omnipay driver
|
|
|
|
* @return object Omnipay initialized object
|
|
|
|
*/
|
|
|
|
protected function gateway()
|
|
|
|
{
|
2019-09-06 01:00:23 +02:00
|
|
|
|
2019-09-05 14:42:26 +02:00
|
|
|
$this->gateway = Omnipay::create($this->company_gateway->gateway->provider);
|
|
|
|
$this->gateway->initialize((array) $this->company_gateway->getConfig());
|
|
|
|
|
2019-09-06 01:00:23 +02:00
|
|
|
return $this;
|
2019-09-05 14:42:26 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-14 14:34:05 +02:00
|
|
|
/**
|
|
|
|
* Return the configuration fields for the
|
|
|
|
* Gatway
|
|
|
|
* @return array The configuration fields
|
|
|
|
*/
|
|
|
|
public function getFields()
|
|
|
|
{
|
|
|
|
return $this->gateway->getDefaultParameters();
|
|
|
|
}
|
|
|
|
|
2019-09-08 14:13:55 +02:00
|
|
|
/**
|
|
|
|
* Returns the default gateway type
|
|
|
|
*/
|
|
|
|
public function gatewayTypes()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
GatewayType::CREDIT_CARD,
|
|
|
|
];
|
|
|
|
}
|
2019-09-06 01:00:23 +02:00
|
|
|
|
2019-09-25 06:03:28 +02:00
|
|
|
public function getCompanyGatewayId()
|
|
|
|
{
|
|
|
|
return $this->company_gateway->id;
|
|
|
|
}
|
2019-09-05 09:00:12 +02:00
|
|
|
/**
|
|
|
|
* Returns whether refunds are possible with the gateway
|
|
|
|
* @return boolean TRUE|FALSE
|
|
|
|
*/
|
2019-09-06 01:00:23 +02:00
|
|
|
public function getRefundable()
|
|
|
|
{
|
|
|
|
return $this->refundable;
|
|
|
|
}
|
|
|
|
|
2019-09-05 09:00:12 +02:00
|
|
|
/**
|
|
|
|
* Returns whether token billing is possible with the gateway
|
|
|
|
* @return boolean TRUE|FALSE
|
|
|
|
*/
|
2019-09-06 01:00:23 +02:00
|
|
|
public function getTokenBilling()
|
|
|
|
{
|
|
|
|
return $this->token_billing;
|
|
|
|
}
|
2019-09-05 09:00:12 +02:00
|
|
|
|
2019-09-16 06:59:59 +02:00
|
|
|
public function canAuthoriseCreditCard()
|
|
|
|
{
|
|
|
|
return $this->can_authorise_credit_card;
|
|
|
|
}
|
|
|
|
|
2019-09-05 09:00:12 +02:00
|
|
|
/**
|
2019-09-05 14:42:26 +02:00
|
|
|
* Refunds a given payment
|
|
|
|
* @return void
|
2019-09-05 09:00:12 +02:00
|
|
|
*/
|
2019-09-16 13:03:25 +02:00
|
|
|
public function refundPayment() {}
|
2019-09-06 01:00:23 +02:00
|
|
|
|
2019-09-25 06:03:28 +02:00
|
|
|
public function authorizeCreditCardView(array $data) {}
|
2019-09-16 13:03:25 +02:00
|
|
|
|
|
|
|
public function authorizeCreditCardResponse($request) {}
|
2019-09-06 07:22:05 +02:00
|
|
|
|
2019-09-25 06:03:28 +02:00
|
|
|
public function processPaymentView(array $data) {}
|
|
|
|
|
|
|
|
public function processPaymentResponse($request) {}
|
|
|
|
|
2019-09-25 07:55:52 +02:00
|
|
|
public function getContact()
|
|
|
|
{
|
|
|
|
if($this->invitation)
|
|
|
|
return ClientContact::find($this->invitation->client_contact_id);
|
|
|
|
elseif(auth()->guard('contact')->user())
|
|
|
|
return auth()->user();
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-06 07:22:05 +02:00
|
|
|
/************************************* Omnipay ******************************************
|
|
|
|
authorize($options) - authorize an amount on the customer's card
|
|
|
|
completeAuthorize($options) - handle return from off-site gateways after authorization
|
|
|
|
capture($options) - capture an amount you have previously authorized
|
|
|
|
purchase($options) - authorize and immediately capture an amount on the customer's card
|
|
|
|
completePurchase($options) - handle return from off-site gateways after purchase
|
|
|
|
refund($options) - refund an already processed transaction
|
|
|
|
void($options) - generally can only be called up to 24 hours after submitting a transaction
|
|
|
|
acceptNotification() - convert an incoming request from an off-site gateway to a generic notification object for further processing
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function purchase($data, $items)
|
|
|
|
{
|
|
|
|
$response = $this->gateway
|
|
|
|
->purchase($data)
|
|
|
|
->setItems($items)
|
|
|
|
->send();
|
|
|
|
|
|
|
|
|
|
|
|
if ($response->isRedirect()) {
|
|
|
|
// redirect to offsite payment gateway
|
|
|
|
$response->redirect();
|
|
|
|
} elseif ($response->isSuccessful()) {
|
|
|
|
// payment was successful: update database
|
|
|
|
print_r($response);
|
|
|
|
} else {
|
|
|
|
// payment failed: display message to customer
|
|
|
|
echo $response->getMessage();
|
2019-09-10 12:30:55 +02:00
|
|
|
}
|
2019-09-06 07:22:05 +02:00
|
|
|
/*
|
|
|
|
$this->purchaseResponse = (array)$response->getData();*/
|
|
|
|
}
|
2019-09-14 14:34:05 +02:00
|
|
|
|
|
|
|
|
2019-09-05 09:00:12 +02:00
|
|
|
}
|