mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Refactoring Payment Drivers
This commit is contained in:
parent
e35b1b6871
commit
d58c2f05ff
23
app/PaymentDrivers/AbstractPaymentDriver.php
Normal file
23
app/PaymentDrivers/AbstractPaymentDriver.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?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;
|
||||
|
||||
abstract class AbstractPaymentDriver
|
||||
{
|
||||
|
||||
abstract public function authorize();
|
||||
|
||||
abstract public function purchase();
|
||||
|
||||
abstract public function refund();
|
||||
|
||||
}
|
66
app/PaymentDrivers/AuthorizePaymentDriver.php
Normal file
66
app/PaymentDrivers/AuthorizePaymentDriver.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?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 net\authorize\api\constants\ANetEnvironment;
|
||||
use net\authorize\api\contract\v1\CreateTransactionRequest;
|
||||
use net\authorize\api\contract\v1\MerchantAuthenticationType;
|
||||
use net\authorize\api\controller\CreateTransactionController;
|
||||
|
||||
/**
|
||||
* Class BaseDriver
|
||||
* @package App\PaymentDrivers
|
||||
*
|
||||
*/
|
||||
class AuthorizePaymentDriver extends BaseDriver
|
||||
{
|
||||
|
||||
public $anet;
|
||||
|
||||
public function init()
|
||||
{
|
||||
|
||||
$merchantAuthentication = new MerchantAuthenticationType();
|
||||
$merchantAuthentication->setName($this->company_gateway->getConfigField('apiLoginId'));
|
||||
$merchantAuthentication->setTransactionKey($this->company_gateway->getConfigField('transactionKey'));
|
||||
|
||||
|
||||
$this->anet = new CreateTransactionRequest();
|
||||
$this->anet->setMerchantAuthentication($merchantAuthentication);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function fire()
|
||||
{
|
||||
|
||||
if($this->company_gateway->getConfigField('testMode'))
|
||||
$env = ANetEnvironment::SANDBOX;
|
||||
else
|
||||
$env = ANetEnvironment::PRODUCTION;
|
||||
|
||||
$controller = new CreateTransactionController($this->anet);
|
||||
$response = $controller->executeWithApiResponse($env);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
public function authorize() {}
|
||||
|
||||
public function purchase() {}
|
||||
|
||||
public function refund() {}
|
||||
|
||||
|
||||
}
|
66
app/PaymentDrivers/BaseDriver.php
Normal file
66
app/PaymentDrivers/BaseDriver.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?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\Client;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\PaymentDrivers\AbstractPaymentDriver;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\SystemLogTrait;
|
||||
use Omnipay\Omnipay;
|
||||
|
||||
/**
|
||||
* Class BaseDriver
|
||||
* @package App\PaymentDrivers
|
||||
*
|
||||
*/
|
||||
class BaseDriver implements AbstractPaymentDriver
|
||||
{
|
||||
use SystemLogTrait;
|
||||
use MakesHash;
|
||||
|
||||
/* The company gateway instance*/
|
||||
public $company_gateway;
|
||||
|
||||
/* The Gateway Driver instance*/
|
||||
protected $gateway;
|
||||
|
||||
/* The Invitation */
|
||||
protected $invitation;
|
||||
|
||||
/* Gateway capabilities */
|
||||
protected $refundable = false;
|
||||
|
||||
/* Token billing */
|
||||
protected $token_billing = false;
|
||||
|
||||
/* Authorise payment methods */
|
||||
protected $can_authorise_credit_card = false;
|
||||
|
||||
|
||||
public function __construct(CompanyGateway $company_gateway, Client $client, $invitation = false)
|
||||
{
|
||||
$this->company_gateway = $company_gateway;
|
||||
|
||||
$this->invitation = $invitation;
|
||||
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
|
||||
public function authorize() {}
|
||||
|
||||
public function purchase() {}
|
||||
|
||||
public function refund() {}
|
||||
}
|
@ -21,6 +21,7 @@
|
||||
"php": ">=7.3",
|
||||
"ext-json": "*",
|
||||
"asgrim/ofxparser": "^1.2",
|
||||
"authorizenet/authorizenet": "^2.0",
|
||||
"beganovich/omnipay-checkout": "dev-master",
|
||||
"cleverit/ubl_invoice": "^1.3",
|
||||
"composer/composer": "^1.10",
|
||||
|
200
composer.lock
generated
200
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "e34e27d2c285356d9251ab97646caf69",
|
||||
"content-hash": "71160af87b4347c05f90402c2790540e",
|
||||
"packages": [
|
||||
{
|
||||
"name": "asgrim/ofxparser",
|
||||
@ -62,6 +62,49 @@
|
||||
],
|
||||
"time": "2018-10-29T10:10:13+00:00"
|
||||
},
|
||||
{
|
||||
"name": "authorizenet/authorizenet",
|
||||
"version": "2.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/AuthorizeNet/sdk-php.git",
|
||||
"reference": "7fa78e6397d363296e462c3b348573c17175b7a8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/AuthorizeNet/sdk-php/zipball/7fa78e6397d363296e462c3b348573c17175b7a8",
|
||||
"reference": "7fa78e6397d363296e462c3b348573c17175b7a8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"php": ">=5.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpmd/phpmd": "~2.0",
|
||||
"phpunit/phpunit": "~4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"lib"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"proprietary"
|
||||
],
|
||||
"description": "Official PHP SDK for Authorize.Net",
|
||||
"homepage": "http://developer.authorize.net",
|
||||
"keywords": [
|
||||
"authorize.net",
|
||||
"authorizenet",
|
||||
"ecommerce",
|
||||
"payment"
|
||||
],
|
||||
"time": "2019-01-14T13:32:41+00:00"
|
||||
},
|
||||
{
|
||||
"name": "aws/aws-sdk-php",
|
||||
"version": "3.138.10",
|
||||
@ -684,12 +727,6 @@
|
||||
"Xdebug",
|
||||
"performance"
|
||||
],
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://packagist.com",
|
||||
"type": "custom"
|
||||
}
|
||||
],
|
||||
"time": "2020-03-01T12:26:26+00:00"
|
||||
},
|
||||
{
|
||||
@ -1021,20 +1058,6 @@
|
||||
"sqlserver",
|
||||
"sqlsrv"
|
||||
],
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://www.doctrine-project.org/sponsorship.html",
|
||||
"type": "custom"
|
||||
},
|
||||
{
|
||||
"url": "https://www.patreon.com/phpdoctrine",
|
||||
"type": "patreon"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2020-04-20T17:19:26+00:00"
|
||||
},
|
||||
{
|
||||
@ -3840,70 +3863,6 @@
|
||||
],
|
||||
"time": "2019-11-12T18:38:48+00:00"
|
||||
},
|
||||
{
|
||||
"name": "omnipay/authorizenet",
|
||||
"version": "3.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/thephpleague/omnipay-authorizenet.git",
|
||||
"reference": "8ccce3190c00d0a129c62dc1d1451d0125bab640"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/thephpleague/omnipay-authorizenet/zipball/8ccce3190c00d0a129c62dc1d1451d0125bab640",
|
||||
"reference": "8ccce3190c00d0a129c62dc1d1451d0125bab640",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"ext-libxml": "*",
|
||||
"ext-simplexml": "*",
|
||||
"omnipay/common": "^3"
|
||||
},
|
||||
"require-dev": {
|
||||
"omnipay/tests": "^3",
|
||||
"phpro/grumphp": "^0.14",
|
||||
"squizlabs/php_codesniffer": "^3"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Omnipay\\AuthorizeNet\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Adrian Macneil",
|
||||
"email": "adrian@adrianmacneil.com"
|
||||
},
|
||||
{
|
||||
"name": "Omnipay Contributors",
|
||||
"homepage": "https://github.com/thephpleague/omnipay-authorizenet/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Authorize.Net gateway for the Omnipay payment processing library",
|
||||
"homepage": "https://github.com/thephpleague/omnipay-authorizenet",
|
||||
"keywords": [
|
||||
"authorize",
|
||||
"authorize net",
|
||||
"authorize.net",
|
||||
"gateway",
|
||||
"merchant",
|
||||
"omnipay",
|
||||
"pay",
|
||||
"payment"
|
||||
],
|
||||
"time": "2019-04-27T22:33:23+00:00"
|
||||
},
|
||||
{
|
||||
"name": "omnipay/common",
|
||||
"version": "v3.0.3",
|
||||
@ -5867,12 +5826,6 @@
|
||||
"screenshot",
|
||||
"webpage"
|
||||
],
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://www.patreon.com/spatie",
|
||||
"type": "patreon"
|
||||
}
|
||||
],
|
||||
"time": "2020-04-20T10:33:41+00:00"
|
||||
},
|
||||
{
|
||||
@ -9461,6 +9414,70 @@
|
||||
],
|
||||
"time": "2018-11-21T21:40:54+00:00"
|
||||
},
|
||||
{
|
||||
"name": "omnipay/authorizenet",
|
||||
"version": "3.3.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/thephpleague/omnipay-authorizenet.git",
|
||||
"reference": "8ccce3190c00d0a129c62dc1d1451d0125bab640"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/thephpleague/omnipay-authorizenet/zipball/8ccce3190c00d0a129c62dc1d1451d0125bab640",
|
||||
"reference": "8ccce3190c00d0a129c62dc1d1451d0125bab640",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"ext-libxml": "*",
|
||||
"ext-simplexml": "*",
|
||||
"omnipay/common": "^3"
|
||||
},
|
||||
"require-dev": {
|
||||
"omnipay/tests": "^3",
|
||||
"phpro/grumphp": "^0.14",
|
||||
"squizlabs/php_codesniffer": "^3"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.0.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Omnipay\\AuthorizeNet\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Adrian Macneil",
|
||||
"email": "adrian@adrianmacneil.com"
|
||||
},
|
||||
{
|
||||
"name": "Omnipay Contributors",
|
||||
"homepage": "https://github.com/thephpleague/omnipay-authorizenet/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Authorize.Net gateway for the Omnipay payment processing library",
|
||||
"homepage": "https://github.com/thephpleague/omnipay-authorizenet",
|
||||
"keywords": [
|
||||
"authorize",
|
||||
"authorize net",
|
||||
"authorize.net",
|
||||
"gateway",
|
||||
"merchant",
|
||||
"omnipay",
|
||||
"pay",
|
||||
"payment"
|
||||
],
|
||||
"time": "2019-04-27T22:33:23+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phar-io/manifest",
|
||||
"version": "1.0.3",
|
||||
@ -11061,7 +11078,6 @@
|
||||
"minimum-stability": "dev",
|
||||
"stability-flags": {
|
||||
"beganovich/omnipay-checkout": 20,
|
||||
"omnipay/authorizenet": 20,
|
||||
"webpatser/laravel-countries": 20
|
||||
},
|
||||
"prefer-stable": true,
|
||||
|
@ -67,6 +67,7 @@ return [
|
||||
'password' => 'password',
|
||||
'stripe' => env('STRIPE_KEYS', ''),
|
||||
'paypal' => env('PAYPAL_KEYS', ''),
|
||||
'authorize' => env('AUTHORIZE_KEYS',''),
|
||||
'checkout' => env('CHECKOUT_KEYS',''),
|
||||
'travis' => env('TRAVIS', false),
|
||||
'test_email' => env('TEST_EMAIL', 'test@example.com'),
|
||||
|
57
tests/Integration/PaymentDrivers/AuthorizeTest.php
Normal file
57
tests/Integration/PaymentDrivers/AuthorizeTest.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Integration\PaymentDrivers;
|
||||
|
||||
use Tests\TestCase;
|
||||
use net\authorize\api\constants\ANetEnvironment;
|
||||
use net\authorize\api\contract\v1 as AnetAPI;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
class AuthorizeTest extends TestCase
|
||||
{
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (! config('ninja.testvars.authorize')) {
|
||||
$this->markTestSkipped('authorize.net not configured');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function testUnpackingVars()
|
||||
{
|
||||
$vars = json_decode(config('ninja.testvars.authorize'));
|
||||
|
||||
$this->assertTrue(property_exists($vars, 'apiLoginId'));
|
||||
}
|
||||
|
||||
public function testCreatePublicClientKey()
|
||||
{
|
||||
error_reporting (E_ALL & ~E_DEPRECATED);
|
||||
|
||||
$vars = json_decode(config('ninja.testvars.authorize'));
|
||||
|
||||
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
|
||||
$merchantAuthentication->setName($vars->apiLoginId);
|
||||
$merchantAuthentication->setTransactionKey($vars->transactionKey);
|
||||
|
||||
$request = new AnetAPI\GetMerchantDetailsRequest();
|
||||
$request->setMerchantAuthentication($merchantAuthentication);
|
||||
|
||||
$controller = new GetMerchantDetailsController($request);
|
||||
|
||||
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
|
||||
|
||||
$this->assertNotNull($response->getPublicClientKey());
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user