1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Jobs/Ninja/TransactionLog.php

113 lines
3.6 KiB
PHP
Raw Normal View History

2022-03-09 08:40:45 +01:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2022-04-27 05:20:41 +02:00
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
2022-03-09 08:40:45 +01:00
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Jobs\Ninja;
2022-03-10 01:32:04 +01:00
use App\DataMapper\Transactions\ClientStatusTransaction;
use App\DataMapper\Transactions\GatewayPaymentMadeTransaction;
use App\DataMapper\Transactions\InvoiceCancelledTransaction;
use App\DataMapper\Transactions\InvoiceDeletedTransaction;
use App\DataMapper\Transactions\InvoiceFeeAppliedTransaction;
use App\DataMapper\Transactions\InvoicePaymentTransaction;
2022-03-10 02:17:05 +01:00
use App\DataMapper\Transactions\InvoiceReversalTransaction;
2022-03-10 01:32:04 +01:00
use App\DataMapper\Transactions\InvoiceUpdatedTransaction;
2022-03-09 10:32:46 +01:00
use App\DataMapper\Transactions\MarkPaidTransaction;
2022-03-10 01:32:04 +01:00
use App\DataMapper\Transactions\PaymentAppliedTransaction;
use App\DataMapper\Transactions\PaymentDeletedTransaction;
use App\DataMapper\Transactions\PaymentFailedTransaction;
use App\DataMapper\Transactions\PaymentMadeTransaction;
use App\DataMapper\Transactions\PaymentRefundedTransaction;
2022-03-09 08:40:45 +01:00
use App\Libraries\MultiDB;
use App\Models\TransactionEvent;
use App\Utils\Ninja;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class TransactionLog implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private array $payload;
private string $db;
2022-03-09 10:32:46 +01:00
private array $data;
private $event;
private $event_transformer;
private array $transformer_array = [
2022-03-10 03:27:31 +01:00
TransactionEvent::INVOICE_MARK_PAID => MarkPaidTransaction::class, //
TransactionEvent::INVOICE_UPDATED => InvoiceUpdatedTransaction::class, //
TransactionEvent::INVOICE_DELETED => InvoiceDeletedTransaction::class, //
2022-03-10 01:32:04 +01:00
TransactionEvent::INVOICE_PAYMENT_APPLIED => InvoicePaymentTransaction::class,
TransactionEvent::INVOICE_CANCELLED => InvoiceCancelledTransaction::class,
2022-03-10 03:27:31 +01:00
TransactionEvent::INVOICE_REVERSED => InvoiceReversalTransaction::class, //
TransactionEvent::INVOICE_FEE_APPLIED => InvoiceFeeAppliedTransaction::class, //
2022-03-10 03:44:53 +01:00
TransactionEvent::PAYMENT_MADE => PaymentMadeTransaction::class, //
TransactionEvent::GATEWAY_PAYMENT_MADE => GatewayPaymentMadeTransaction::class, //
2022-03-10 01:32:04 +01:00
TransactionEvent::PAYMENT_APPLIED => PaymentAppliedTransaction::class,
2022-03-10 03:44:53 +01:00
TransactionEvent::PAYMENT_REFUND => PaymentRefundedTransaction::class, //
2022-03-10 01:32:04 +01:00
TransactionEvent::PAYMENT_FAILED => PaymentFailedTransaction::class,
2022-03-10 03:27:31 +01:00
TransactionEvent::PAYMENT_DELETED => PaymentDeletedTransaction::class, //
2022-03-10 03:44:53 +01:00
TransactionEvent::CLIENT_STATUS => ClientStatusTransaction::class, //
2022-03-09 10:32:46 +01:00
];
2022-03-09 08:40:45 +01:00
/**
* Create a new job instance.
*
* @return void
*/
2022-03-09 10:32:46 +01:00
public function __construct($event, $data, $db)
2022-03-09 08:40:45 +01:00
{
$this->db = $db;
2022-03-09 10:32:46 +01:00
$this->event = $event;
$this->data = $data;
2022-03-09 08:40:45 +01:00
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
// if(!Ninja::isHosted())
// return;
2022-03-09 08:40:45 +01:00
2022-03-09 10:32:46 +01:00
$this->setTransformer();
$this->payload = $this->event_transformer->transform($this->data);
2022-03-09 10:32:46 +01:00
$this->persist();
}
private function setTransformer()
{
$class = $this->transformer_array[$this->event];
$this->event_transformer = new $class();
return $this;
2022-03-09 08:40:45 +01:00
}
private function persist()
{
MultiDB::setDB($this->db);
TransactionEvent::create($this->payload);
}
}