1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00
invoiceninja/app/PaymentDrivers/AuthorizePaymentDriver.php
2020-06-10 18:11:53 +10:00

126 lines
3.1 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\PaymentDrivers;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\PaymentDrivers\Authorize\AuthorizeCreditCard;
use App\PaymentDrivers\Authorize\AuthorizePaymentMethod;
use net\authorize\api\constants\ANetEnvironment;
use net\authorize\api\contract\v1\CreateTransactionRequest;
use net\authorize\api\contract\v1\GetMerchantDetailsRequest;
use net\authorize\api\contract\v1\MerchantAuthenticationType;
use net\authorize\api\controller\CreateTransactionController;
use net\authorize\api\controller\GetMerchantDetailsController;
/**
* Class BaseDriver
* @package App\PaymentDrivers
*
*/
class AuthorizePaymentDriver extends BaseDriver
{
public $merchant_authentication;
/**
* Returns the gateway types
*/
public function gatewayTypes() :array
{
$types = [
GatewayType::CREDIT_CARD,
];
return $types;
}
public function init()
{
error_reporting (E_ALL & ~E_DEPRECATED);
$this->merchant_authentication = new MerchantAuthenticationType();
$this->merchant_authentication->setName($this->company_gateway->getConfigField('apiLoginId'));
$this->merchant_authentication->setTransactionKey($this->company_gateway->getConfigField('transactionKey'));
return $this;
}
public function getPublicClientKey()
{
$request = new GetMerchantDetailsRequest();
$request->setMerchantAuthentication($this->merchant_authentication);
$controller = new GetMerchantDetailsController($request);
$response = $controller->executeWithApiResponse($this->mode());
return $response->getPublicClientKey();
}
public function mode()
{
if($this->company_gateway->getConfigField('testMode'))
return ANetEnvironment::SANDBOX;
return $env = ANetEnvironment::PRODUCTION;
}
public function authorizeView($payment_method)
{
return (new AuthorizePaymentMethod($this))->authorizeView($payment_method);
}
public function authorizeResponseView(array $data)
{
return (new AuthorizePaymentMethod($this))->authorizeResponseView($data['gateway_type_id'], $data);
}
// public function fire()
// {
// $controller = new CreateTransactionController($this->anet);
// $response = $controller->executeWithApiResponse($env);
// return $response;
// }
public function authorize($payment_method)
{
}
public function purchase()
{
}
public function refund()
{
}
public function findClientGatewayRecord() :?ClientGatewayToken
{
return ClientGatewayToken::where('client_id', $this->client->id)
->where('company_gateway_id', $this->company_gateway->id)
->first();
}
}