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

Support variables in custom gateways #1701

This commit is contained in:
Hillel Coren 2018-04-13 14:11:57 +03:00
parent 4002b755d1
commit e4f0cf06b0
6 changed files with 84 additions and 7 deletions

View File

@ -2,6 +2,8 @@
namespace App\Models; namespace App\Models;
use Utils;
use HTMLUtils;
use Crypt; use Crypt;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Laracasts\Presenter\PresentableTrait; use Laracasts\Presenter\PresentableTrait;
@ -291,4 +293,22 @@ class AccountGateway extends EntityModel
return $this->getConfigField('testMode'); return $this->getConfigField('testMode');
} }
} }
public function getCustomHtml($invitation)
{
$text = $this->getConfigField('text');
if ($text == strip_tags($text)) {
$text = nl2br($text);
}
if (Utils::isNinja()) {
$text = HTMLUtils::sanitizeHTML($text);
}
$templateService = app('App\Services\TemplateService');
$text = $templateService->processVariables($text, ['invitation' => $invitation]);
return $text;
}
} }

View File

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

View File

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

View File

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

View File

@ -18,15 +18,17 @@ class TemplateService
*/ */
public function processVariables($template, array $data) public function processVariables($template, array $data)
{ {
/** @var \App\Models\Account $account */
$account = $data['account'];
/** @var \App\Models\Client $client */
$client = $data['client'];
/** @var \App\Models\Invitation $invitation */ /** @var \App\Models\Invitation $invitation */
$invitation = $data['invitation']; $invitation = $data['invitation'];
/** @var \App\Models\Account $account */
$account = ! empty($data['account']) ? $data['account'] : $invitation->account;
/** @var \App\Models\Client $client */
$client = ! empty($data['client']) ? $data['client'] : $invitation->invoice->client;
$amount = ! empty($data['amount']) ? $data['amount'] : $invitation->invoice->getRequestedAmount();
// check if it's a proposal // check if it's a proposal
if ($invitation->proposal) { if ($invitation->proposal) {
$invoice = $invitation->proposal->invoice; $invoice = $invitation->proposal->invoice;
@ -59,7 +61,7 @@ class TemplateService
'$invoiceDate' => $account->formatDate($invoice->invoice_date), '$invoiceDate' => $account->formatDate($invoice->invoice_date),
'$contact' => $contact->getDisplayName(), '$contact' => $contact->getDisplayName(),
'$firstName' => $contact->first_name, '$firstName' => $contact->first_name,
'$amount' => $account->formatMoney($data['amount'], $client), '$amount' => $account->formatMoney($amount, $client),
'$total' => $invoice->present()->amount, '$total' => $invoice->present()->amount,
'$balance' => $invoice->present()->balance, '$balance' => $invoice->present()->balance,
'$invoice' => $invoice->invoice_number, '$invoice' => $invoice->invoice_number,

View File

@ -0,0 +1,16 @@
<div class="modal fade" id="custom{{ $number }}GatewayModal" tabindex="-1" role="dialog" aria-labelledby="custom{{ $number }}GatewayModalLabel" 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">{{ $customGateway->getConfigField('name') }}</h4>
</div>
<div class="panel-body">
{!! $customGateway->getCustomHtml($invitation) !!}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('texts.close') }}</button>
</div>
</div>
</div>
</div>