2020-06-09 13:17:26 +02:00
|
|
|
<?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;
|
|
|
|
|
2020-06-10 03:06:37 +02:00
|
|
|
use App\Models\ClientGatewayToken;
|
2020-06-10 10:05:30 +02:00
|
|
|
use App\Models\GatewayType;
|
2020-06-10 03:06:37 +02:00
|
|
|
use App\PaymentDrivers\Authorize\AuthorizeCreditCard;
|
2020-06-10 10:05:30 +02:00
|
|
|
use App\PaymentDrivers\Authorize\AuthorizePaymentMethod;
|
2020-06-09 13:17:26 +02:00
|
|
|
use net\authorize\api\constants\ANetEnvironment;
|
|
|
|
use net\authorize\api\contract\v1\CreateTransactionRequest;
|
2020-06-09 13:53:23 +02:00
|
|
|
use net\authorize\api\contract\v1\GetMerchantDetailsRequest;
|
2020-06-09 13:17:26 +02:00
|
|
|
use net\authorize\api\contract\v1\MerchantAuthenticationType;
|
|
|
|
use net\authorize\api\controller\CreateTransactionController;
|
2020-06-09 13:53:23 +02:00
|
|
|
use net\authorize\api\controller\GetMerchantDetailsController;
|
2020-06-09 13:17:26 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class BaseDriver
|
|
|
|
* @package App\PaymentDrivers
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class AuthorizePaymentDriver extends BaseDriver
|
|
|
|
{
|
|
|
|
|
2020-06-09 13:53:23 +02:00
|
|
|
public $merchant_authentication;
|
2020-06-09 13:17:26 +02:00
|
|
|
|
2020-06-10 10:05:30 +02:00
|
|
|
/**
|
|
|
|
* Returns the gateway types
|
|
|
|
*/
|
|
|
|
public function gatewayTypes() :array
|
|
|
|
{
|
|
|
|
$types = [
|
|
|
|
GatewayType::CREDIT_CARD,
|
|
|
|
];
|
|
|
|
|
|
|
|
return $types;
|
|
|
|
}
|
2020-06-10 10:11:53 +02:00
|
|
|
|
2020-06-09 13:17:26 +02:00
|
|
|
public function init()
|
|
|
|
{
|
2020-06-09 13:53:23 +02:00
|
|
|
error_reporting (E_ALL & ~E_DEPRECATED);
|
2020-06-09 13:17:26 +02:00
|
|
|
|
2020-06-09 13:53:23 +02:00
|
|
|
$this->merchant_authentication = new MerchantAuthenticationType();
|
|
|
|
$this->merchant_authentication->setName($this->company_gateway->getConfigField('apiLoginId'));
|
|
|
|
$this->merchant_authentication->setTransactionKey($this->company_gateway->getConfigField('transactionKey'));
|
2020-06-09 13:17:26 +02:00
|
|
|
|
2020-06-09 13:53:23 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2020-06-09 13:17:26 +02:00
|
|
|
|
2020-06-09 13:53:23 +02:00
|
|
|
public function getPublicClientKey()
|
|
|
|
{
|
|
|
|
|
|
|
|
$request = new GetMerchantDetailsRequest();
|
|
|
|
$request->setMerchantAuthentication($this->merchant_authentication);
|
|
|
|
|
|
|
|
$controller = new GetMerchantDetailsController($request);
|
|
|
|
$response = $controller->executeWithApiResponse($this->mode());
|
|
|
|
|
|
|
|
return $response->getPublicClientKey();
|
2020-06-09 13:17:26 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-10 10:11:53 +02:00
|
|
|
public function mode()
|
2020-06-09 13:17:26 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
if($this->company_gateway->getConfigField('testMode'))
|
2020-06-09 13:53:23 +02:00
|
|
|
return ANetEnvironment::SANDBOX;
|
|
|
|
|
|
|
|
return $env = ANetEnvironment::PRODUCTION;
|
2020-06-09 13:17:26 +02:00
|
|
|
|
2020-06-09 13:53:23 +02:00
|
|
|
}
|
|
|
|
|
2020-06-10 03:06:37 +02:00
|
|
|
public function authorizeView($payment_method)
|
2020-06-09 13:53:23 +02:00
|
|
|
{
|
2020-06-10 03:06:37 +02:00
|
|
|
return (new AuthorizePaymentMethod($this))->authorizeView($payment_method);
|
|
|
|
}
|
|
|
|
|
2020-06-10 10:05:30 +02:00
|
|
|
public function authorizeResponseView(array $data)
|
2020-06-10 03:06:37 +02:00
|
|
|
{
|
|
|
|
|
2020-06-10 10:05:30 +02:00
|
|
|
return (new AuthorizePaymentMethod($this))->authorizeResponseView($data['gateway_type_id'], $data);
|
2020-06-09 13:17:26 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-10 03:06:37 +02:00
|
|
|
public function authorize($payment_method)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2020-06-09 13:17:26 +02:00
|
|
|
|
2020-06-10 03:06:37 +02:00
|
|
|
public function purchase()
|
|
|
|
{
|
2020-06-09 13:17:26 +02:00
|
|
|
|
2020-06-10 03:06:37 +02:00
|
|
|
}
|
2020-06-09 13:17:26 +02:00
|
|
|
|
2020-06-10 03:06:37 +02:00
|
|
|
public function refund()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-10 10:11:53 +02:00
|
|
|
public function findClientGatewayRecord() :?ClientGatewayToken
|
2020-06-10 03:06:37 +02:00
|
|
|
{
|
|
|
|
return ClientGatewayToken::where('client_id', $this->client->id)
|
|
|
|
->where('company_gateway_id', $this->company_gateway->id)
|
|
|
|
->first();
|
|
|
|
}
|
2020-06-09 13:17:26 +02:00
|
|
|
}
|