1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-09 20:52:56 +01:00

Added additional custom gateways #1858

This commit is contained in:
Hillel Coren 2018-04-13 13:50:38 +03:00
parent 3d9f000fd1
commit 4002b755d1
15 changed files with 83 additions and 71 deletions

View File

@ -299,9 +299,11 @@ if (! defined('APP_NAME')) {
define('GATEWAY_PAYTRACE', 56);
define('GATEWAY_WEPAY', 60);
define('GATEWAY_BRAINTREE', 61);
define('GATEWAY_CUSTOM', 62);
define('GATEWAY_CUSTOM1', 62);
define('GATEWAY_GOCARDLESS', 64);
define('GATEWAY_PAYMILL', 66);
define('GATEWAY_CUSTOM2', 67);
define('GATEWAY_CUSTOM3', 68);
// The customer exists, but only as a local concept
// The remote gateway doesn't understand the concept of customers
@ -451,12 +453,14 @@ if (! defined('APP_NAME')) {
define('GATEWAY_TYPE_PAYPAL', 3);
define('GATEWAY_TYPE_BITCOIN', 4);
define('GATEWAY_TYPE_DWOLLA', 5);
define('GATEWAY_TYPE_CUSTOM', 6);
define('GATEWAY_TYPE_CUSTOM1', 6);
define('GATEWAY_TYPE_ALIPAY', 7);
define('GATEWAY_TYPE_SOFORT', 8);
define('GATEWAY_TYPE_SEPA', 9);
define('GATEWAY_TYPE_GOCARDLESS', 10);
define('GATEWAY_TYPE_APPLE_PAY', 11);
define('GATEWAY_TYPE_CUSTOM2', 12);
define('GATEWAY_TYPE_CUSTOM3', 13);
define('GATEWAY_TYPE_TOKEN', 'token');
define('TEMPLATE_INVOICE', 'invoice');

View File

@ -52,7 +52,7 @@ class AccountGatewayController extends BaseController
$accountGateway = AccountGateway::scope($publicId)->firstOrFail();
$config = $accountGateway->getConfig();
if ($accountGateway->gateway_id != GATEWAY_CUSTOM) {
if (! $accountGateway->isCustom()) {
foreach ($config as $field => $value) {
$config->$field = str_repeat('*', strlen($value));
}
@ -257,8 +257,6 @@ class AccountGatewayController extends BaseController
}
if (! $value && in_array($field, ['testMode', 'developerMode', 'sandbox'])) {
// do nothing
} elseif ($gatewayId == GATEWAY_CUSTOM) {
$config->$field = Utils::isNinjaProd() ? strip_tags($value) : $value;
} else {
$config->$field = $value;
}

View File

@ -128,7 +128,7 @@ class ClientPortalController extends BaseController
$paymentURL = '';
if (count($paymentTypes) == 1) {
$paymentURL = $paymentTypes[0]['url'];
if ($paymentTypes[0]['gatewayTypeId'] == GATEWAY_TYPE_CUSTOM) {
if (in_array($paymentTypes[0]['gatewayTypeId'], [GATEWAY_TYPE_CUSTOM1, GATEWAY_TYPE_CUSTOM2, GATEWAY_TYPE_CUSTOM3])) {
// do nothing
} elseif (! $account->isGatewayConfigured(GATEWAY_PAYPAL_EXPRESS)) {
$paymentURL = URL::to($paymentURL);
@ -170,13 +170,6 @@ class ClientPortalController extends BaseController
'accountGateway' => $paymentDriver->accountGateway,
];
}
if ($accountGateway = $account->getGatewayByType(GATEWAY_TYPE_CUSTOM)) {
$data += [
'customGatewayName' => $accountGateway->getConfigField('name'),
'customGatewayText' => $accountGateway->getConfigField('text'),
];
}
}
if ($account->hasFeature(FEATURE_DOCUMENTS) && $this->canCreateZip()) {

View File

@ -891,8 +891,10 @@ class Account extends Eloquent
$gatewayTypes = [];
$gatewayIds = [];
$usedGatewayIds = [];
foreach ($this->account_gateways as $accountGateway) {
$usedGatewayIds[] = $accountGateway->gateway_id;
$paymentDriver = $accountGateway->paymentDriver();
$gatewayTypes = array_unique(array_merge($gatewayTypes, $paymentDriver->gatewayTypes()));
}

View File

@ -107,6 +107,11 @@ class AccountGateway extends EntityModel
}
}
public function isCustom()
{
return in_array($this->gateway_id, [GATEWAY_CUSTOM1, GATEWAY_CUSTOM2, GATEWAY_CUSTOM3]);
}
/**
* @param $config
*/

View File

@ -48,7 +48,9 @@ class Gateway extends Eloquent
GATEWAY_AUTHORIZE_NET,
GATEWAY_MOLLIE,
GATEWAY_GOCARDLESS,
GATEWAY_CUSTOM,
GATEWAY_CUSTOM1,
GATEWAY_CUSTOM2,
GATEWAY_CUSTOM3,
];
// allow adding these gateway if another gateway
@ -61,7 +63,9 @@ class Gateway extends Eloquent
GATEWAY_GOCARDLESS,
GATEWAY_BITPAY,
GATEWAY_DWOLLA,
GATEWAY_CUSTOM,
GATEWAY_CUSTOM1,
GATEWAY_CUSTOM2,
GATEWAY_CUSTOM3,
];
/**
@ -209,6 +213,6 @@ class Gateway extends Eloquent
public function isCustom()
{
return $this->id === GATEWAY_CUSTOM;
return in_array($this->id, [GATEWAY_CUSTOM1, GATEWAY_CUSTOM2, GATEWAY_CUSTOM3]);
}
}

View File

@ -25,7 +25,7 @@ class AccountGatewayDatatable extends EntityDatatable
$accountGateway = $this->getAccountGateway($model->id);
if ($model->deleted_at) {
return $model->name;
} elseif ($model->gateway_id == GATEWAY_CUSTOM) {
} elseif (in_array($model->gateway_id, [GATEWAY_CUSTOM1, GATEWAY_CUSTOM2, GATEWAY_CUSTOM3])) {
$name = $accountGateway->getConfigField('name') . ' [' . trans('texts.custom') . ']';
return link_to("gateways/{$model->public_id}/edit", $name)->toHtml();
} elseif ($model->gateway_id != GATEWAY_WEPAY) {
@ -191,8 +191,12 @@ class AccountGatewayDatatable extends EntityDatatable
},
function ($model) use ($gatewayType) {
// Only show this action if the given gateway supports this gateway type
if ($model->gateway_id == GATEWAY_CUSTOM) {
return $gatewayType->id == GATEWAY_TYPE_CUSTOM;
if ($model->gateway_id == GATEWAY_CUSTOM1) {
return $gatewayType->id == GATEWAY_TYPE_CUSTOM1;
} elseif ($model->gateway_id == GATEWAY_CUSTOM2) {
return $gatewayType->id == GATEWAY_TYPE_CUSTOM2;
} elseif ($model->gateway_id == GATEWAY_CUSTOM3) {
return $gatewayType->id == GATEWAY_TYPE_CUSTOM3;
} else {
$accountGateway = $this->getAccountGateway($model->id);
return $accountGateway->paymentDriver()->supportsGatewayType($gatewayType->id);
@ -229,8 +233,12 @@ class AccountGatewayDatatable extends EntityDatatable
private function getGatewayTypes($id, $gatewayId)
{
if ($gatewayId == GATEWAY_CUSTOM) {
$gatewayTypes = [GATEWAY_TYPE_CUSTOM];
if ($gatewayId == GATEWAY_CUSTOM1) {
$gatewayTypes = [GATEWAY_TYPE_CUSTOM1];
} elseif ($gatewayId == GATEWAY_CUSTOM2) {
$gatewayTypes = [GATEWAY_TYPE_CUSTOM2];
} elseif ($gatewayId == GATEWAY_CUSTOM3) {
$gatewayTypes = [GATEWAY_TYPE_CUSTOM3];
} else {
$accountGateway = $this->getAccountGateway($id);
$paymentDriver = $accountGateway->paymentDriver();

View File

@ -977,8 +977,14 @@ class BasePaymentDriver
$gatewayTypeAlias = GatewayType::getAliasFromId($gatewayTypeId);
if ($gatewayTypeId == GATEWAY_TYPE_CUSTOM) {
$url = 'javascript:showCustomModal();';
if ($gatewayTypeId == GATEWAY_TYPE_CUSTOM1) {
$url = 'javascript:showCustom1Modal();';
$label = e($this->accountGateway->getConfigField('name'));
} elseif ($gatewayTypeId == GATEWAY_TYPE_CUSTOM2) {
$url = 'javascript:showCustom2Modal();';
$label = e($this->accountGateway->getConfigField('name'));
} elseif ($gatewayTypeId == GATEWAY_TYPE_CUSTOM3) {
$url = 'javascript:showCustom3Modal();';
$label = e($this->accountGateway->getConfigField('name'));
} else {
$url = $this->paymentUrl($gatewayTypeAlias);

View File

@ -1,13 +0,0 @@
<?php
namespace App\Ninja\PaymentDrivers;
class CustomPaymentDriver extends BasePaymentDriver
{
public function gatewayTypes()
{
return [
GATEWAY_TYPE_CUSTOM,
];
}
}

View File

@ -136,6 +136,8 @@ class AddMoreCustomFields extends Migration
$table->string('ip')->nullable();
});
DB::statement('UPDATE gateways SET provider = "Custom1" WHERE id = 62');
DB::statement('UPDATE gateway_types SET alias = "custom1", name = "Custom 1" WHERE id = 6');
}
/**

View File

@ -14,12 +14,14 @@ class GatewayTypesSeeder extends Seeder
['alias' => 'paypal', 'name' => 'PayPal'],
['alias' => 'bitcoin', 'name' => 'Bitcoin'],
['alias' => 'dwolla', 'name' => 'Dwolla'],
['alias' => 'custom', 'name' => 'Custom'],
['alias' => 'custom1', 'name' => 'Custom 1'],
['alias' => 'alipay', 'name' => 'Alipay'],
['alias' => 'sofort', 'name' => 'Sofort'],
['alias' => 'sepa', 'name' => 'SEPA'],
['alias' => 'gocardless', 'name' => 'GoCardless'],
['alias' => 'apple_pay', 'name' => 'Apple Pay'],
['alias' => 'custom2', 'name' => 'Custom 2'],
['alias' => 'custom3', 'name' => 'Custom 3'],
];
foreach ($gateway_types as $gateway_type) {

View File

@ -70,11 +70,13 @@ class PaymentLibrariesSeeder extends Seeder
['name' => 'WeChat Express', 'provider' => 'WeChat_Express', 'payment_library_id' => 2],
['name' => 'WePay', 'provider' => 'WePay', 'is_offsite' => false, 'sort_order' => 3],
['name' => 'Braintree', 'provider' => 'Braintree', 'sort_order' => 3],
['name' => 'Custom', 'provider' => 'Custom', 'is_offsite' => true, 'sort_order' => 20],
['name' => 'Custom', 'provider' => 'Custom1', 'is_offsite' => true, 'sort_order' => 20],
['name' => 'FirstData Payeezy', 'provider' => 'FirstData_Payeezy'],
['name' => 'GoCardless', 'provider' => 'GoCardlessV2\Redirect', 'sort_order' => 9, 'is_offsite' => true],
['name' => 'PagSeguro', 'provider' => 'PagSeguro'],
['name' => 'PAYMILL', 'provider' => 'Paymill'],
['name' => 'Custom', 'provider' => 'Custom2', 'is_offsite' => true, 'sort_order' => 21],
['name' => 'Custom', 'provider' => 'Custom3', 'is_offsite' => true, 'sort_order' => 22],
];
foreach ($gateways as $gateway) {

File diff suppressed because one or more lines are too long

View File

@ -263,7 +263,10 @@
updateFeeSample();
if (gateway_type_id == {{ GATEWAY_TYPE_CUSTOM }} || {{ $account->gateway_fee_enabled ? '0' : '1' }}) {
if (gateway_type_id == {{ GATEWAY_TYPE_CUSTOM1 }} ||
gateway_type_id == {{ GATEWAY_TYPE_CUSTOM2 }} ||
gateway_type_id == {{ GATEWAY_TYPE_CUSTOM3 }} ||
{{ $account->gateway_fee_enabled ? '0' : '1' }}) {
$('#feesEnabled').hide();
$('#feesDisabled').show();
} else {

View File

@ -332,8 +332,16 @@
}
}
function showCustomModal() {
$('#customGatewayModal').modal('show');
function showCustom1Modal() {
$('#custom1GatewayModal').modal('show');
}
function showCustom2Modal() {
$('#custom2GatewayModal').modal('show');
}
function showCustom3Modal() {
$('#custom3GatewayModal').modal('show');
}
function onModalPayNowClick() {
@ -394,30 +402,18 @@
</div>
@if (isset($customGatewayName))
<div class="modal fade" id="customGatewayModal" tabindex="-1" role="dialog" aria-labelledby="customGatewayModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">{{ $customGatewayName }}</h4>
</div>
@if ($customGateway = $account->getGatewayByType(GATEWAY_TYPE_CUSTOM1))
@include('invited.custom_gateway', ['customGateway' => $customGateway, 'number' => 1])
@endif
<div class="panel-body">
@if (Utils::isNinjaProd())
{!! nl2br(e($customGatewayText)) !!}
@else
{!! $customGatewayText !!}
@endif
</div>
@if ($customGateway = $account->getGatewayByType(GATEWAY_TYPE_CUSTOM2))
@include('invited.custom_gateway', ['customGateway' => $customGateway, 'number' => 2])
@endif
@if ($customGateway = $account->getGatewayByType(GATEWAY_TYPE_CUSTOM3))
@include('invited.custom_gateway', ['customGateway' => $customGateway, 'number' => 3])
@endif
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('texts.close') }}</button>
</div>
</div>
</div>
</div>
@endif
@if ($account->requiresAuthorization($invoice))
<div class="modal fade" id="authorizationModal" tabindex="-1" role="dialog" aria-labelledby="authorizationModalLabel" aria-hidden="true">