mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Transaction events
This commit is contained in:
parent
e4bf727711
commit
7423be043d
@ -11,12 +11,20 @@
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\TransactionEvent;
|
||||
|
||||
/**
|
||||
* MarkPaidTransaction.
|
||||
*/
|
||||
class MarkPaidTransaction
|
||||
class MarkPaidTransaction implements TransactionInterface
|
||||
{
|
||||
|
||||
public $event_id = TransactionEvent::INVOICE_MARK_PAID;
|
||||
|
||||
public array $model = [
|
||||
'client_id',
|
||||
'invoice_id',
|
||||
@ -44,6 +52,41 @@ class MarkPaidTransaction
|
||||
'credit_status',
|
||||
];
|
||||
|
||||
public function transform(array $data) :array
|
||||
{
|
||||
$invoice = $data['invoice'];
|
||||
$payment = $data['payment'];
|
||||
$client = $data['client'];
|
||||
$credit = $data['credit'];
|
||||
$payment_request = $data['payment_request'];
|
||||
$metadata = $data['metadata'];
|
||||
|
||||
return [
|
||||
'event_id' => $this->event_id,
|
||||
'client_id' => $client?->id,
|
||||
'invoice_id' => $invoice?->id,
|
||||
'payment_id' => $payment?->id,
|
||||
'credit_id' => $credit?->id,
|
||||
'client_balance' => $client?->balance,
|
||||
'client_paid_to_date' => $client?->paid_to_date,
|
||||
'client_credit_balance' => $client?->credit_balance,
|
||||
'invoice_balance' => $invoice?->balance,
|
||||
'invoice_amount' => $invoice?->amount,
|
||||
'invoice_partial' => $invoice?->partial,
|
||||
'invoice_paid_to_date' => $invoice?->paid_to_date,
|
||||
'invoice_status' => $invoice?->status_id,
|
||||
'payment_amount' => $payment?->amount,
|
||||
'payment_applied' => $payment?->applied,
|
||||
'payment_refunded' => $payment?->refunded,
|
||||
'payment_status' => $payment?->status_id,
|
||||
'paymentables' => $payment?->paymentables,
|
||||
'payment_request' => $payment_request,
|
||||
'metadata' => $metadata,
|
||||
'credit_balance' => $credit?->balance,
|
||||
'credit_amount' => $credit?->amount,
|
||||
'credit_status' => $credit?->status_id,
|
||||
'timestamp' => time(),
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
|
17
app/DataMapper/Transactions/TransactionInterface.php
Normal file
17
app/DataMapper/Transactions/TransactionInterface.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\DataMapper\Transactions;
|
||||
|
||||
interface TransactionInterface
|
||||
{
|
||||
public function transform(array $data) :array;
|
||||
}
|
@ -82,6 +82,8 @@ class UpdateInvoiceRequest extends Request
|
||||
unset($input['documents']);
|
||||
}
|
||||
|
||||
nlog($input);
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,17 @@ class Request extends FormRequest
|
||||
}
|
||||
}
|
||||
|
||||
if(request()->has('file'))
|
||||
{
|
||||
|
||||
request()->merge(['documents' => request()->file('file')]);
|
||||
|
||||
// $requestFile = request()->files->get('file');
|
||||
|
||||
// request()->files->add(['documents' => $requestFile]);
|
||||
|
||||
}
|
||||
|
||||
if (isset($input['invitations'])) {
|
||||
foreach ($input['invitations'] as $key => $value) {
|
||||
if (isset($input['invitations'][$key]['id']) && is_numeric($input['invitations'][$key]['id'])) {
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Jobs\Ninja;
|
||||
|
||||
use App\DataMapper\Transactions\MarkPaidTransaction;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\TransactionEvent;
|
||||
use App\Utils\Ninja;
|
||||
@ -29,14 +30,35 @@ class TransactionLog implements ShouldQueue
|
||||
|
||||
private string $db;
|
||||
|
||||
private array $data;
|
||||
|
||||
private $event;
|
||||
|
||||
private $event_transformer;
|
||||
|
||||
private array $transformer_array = [
|
||||
TransactionEvent::INVOICE_MARK_PAID => MarkPaidTransaction::class,
|
||||
TransactionEvent::INVOICE_UPDATED => MarkPaidTransaction::class,
|
||||
TransactionEvent::INVOICE_DELETED => MarkPaidTransaction::class,
|
||||
TransactionEvent::INVOICE_PAYMENT_APPLIED => MarkPaidTransaction::class,
|
||||
TransactionEvent::INVOICE_CANCELLED => MarkPaidTransaction::class,
|
||||
TransactionEvent::INVOICE_FEE_APPLIED => MarkPaidTransaction::class,
|
||||
TransactionEvent::PAYMENT_MADE => MarkPaidTransaction::class,
|
||||
TransactionEvent::PAYMENT_APPLIED => MarkPaidTransaction::class,
|
||||
TransactionEvent::PAYMENT_REFUND => MarkPaidTransaction::class,
|
||||
TransactionEvent::PAYMENT_FAILED => MarkPaidTransaction::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct($event, $data, $db)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->event = $event;
|
||||
$this->data = $data;
|
||||
|
||||
}
|
||||
|
||||
@ -50,7 +72,21 @@ class TransactionLog implements ShouldQueue
|
||||
if(!Ninja::isHosted())
|
||||
return;
|
||||
|
||||
|
||||
$this->setTransformer();
|
||||
|
||||
$this->payload = $this->event_transformer->transform($this->data);
|
||||
|
||||
$this->persist();
|
||||
}
|
||||
|
||||
|
||||
private function setTransformer()
|
||||
{
|
||||
$class = $this->transformer_array[$this->event];
|
||||
|
||||
$this->event_transformer = new $class();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,4 +27,17 @@ class TransactionEvent extends StaticModel
|
||||
'paymentables' => 'array',
|
||||
];
|
||||
|
||||
public const INVOICE_MARK_PAID = 1;
|
||||
public const INVOICE_UPDATED = 2;
|
||||
public const INVOICE_DELETED = 3;
|
||||
public const INVOICE_PAYMENT_APPLIED = 4;
|
||||
public const INVOICE_CANCELLED = 5;
|
||||
public const INVOICE_FEE_APPLIED = 6;
|
||||
|
||||
public const PAYMENT_MADE = 100;
|
||||
public const PAYMENT_APPLIED = 101;
|
||||
public const PAYMENT_REFUND = 102;
|
||||
public const PAYMENT_FAILED = 103;
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user