Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions Events/DiscordWebhook/DiscordWebhook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace App\Extensions\Events\DiscordWebhook;

use App\Classes\Extensions\Event;


class DiscordWebhook extends Event
{

public function getConfig()
{
return [
[
'name' => 'webhook_url',
'type' => 'text',
'friendlyName' => 'Webhook URL',
'required' => true,
],
[
'name' => 'ping_type',
'type' => 'dropdown',
'friendlyName' => 'Ping Type',
'description' => 'The type of user/role to ping',
'required' => false,
'options' => [
[
'name' => 'None',
'value' => 'none',
],
[
'name' => 'User',
'value' => 'user',
],
[
'name' => 'Role',
'value' => 'role',
],
],
],
[
'name' => 'ping_id',
'type' => 'text',
'friendlyName' => 'Ping ID',
'description' => 'The ID of the user/role to ping',
'required' => false,
],
];
}
}
197 changes: 197 additions & 0 deletions Events/DiscordWebhook/DiscordWebhookListeners.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
<?php

namespace App\Extensions\Events\DiscordWebhook;

use App\Events\Invoice\InvoiceCreated;
use App\Events\Invoice\InvoicePaid;
use App\Events\Ticket\TicketCreated;
use App\Events\Ticket\TicketMessageCreated;
use App\Events\User\UserCreated;
use App\Helpers\ExtensionHelper;

class DiscordWebhookListeners
{
private function sendWebhook(string $title, string $message, array $fields = [], string $color = '00ff00'): void
{
$data = [
'embeds' => [
[
'title' => $title,
'description' => $message,
'color' => hexdec($color),
'fields' => $fields,
],
],
];
$url = ExtensionHelper::getConfig('DiscordWebhook', 'webhook_url');
if (!$url) {
return;
}
if (ExtensionHelper::getConfig('DiscordWebhook', 'ping_type') == 'user') {
$data['content'] = '<@' . ExtensionHelper::getConfig('DiscordWebhook', 'ping_id') . '>';
} else if (ExtensionHelper::getConfig('DiscordWebhook', 'ping_type') == 'role') {
$data['content'] = '<@&' . ExtensionHelper::getConfig('DiscordWebhook', 'ping_id') . '>';
}
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_exec($curl);
curl_close($curl);
}

/**
* Handle the Invoice created event.
*/
public function handleInvoiceCreated(InvoiceCreated $event): void
{
$invoice = $event->invoice;
$message = " ";
$fields = [
[
'name' => 'Invoice ID',
'value' => '[#' . $invoice->id . '](' . route('admin.invoices.show', $invoice->id) . ')',
'inline' => true,
],
[
'name' => 'Invoice total',
'value' => config('settings::currency_sign') . $invoice->total(),
'inline' => true,
],
[
'name' => 'Invoice status',
'value' => $invoice->status,
'inline' => true,
],
[
'name' => 'Invoice user',
'value' => '[' . $invoice->user->name . '](' . route('admin.clients.edit', $invoice->user->id) . ')',
'inline' => true,
],
];
$this->sendWebhook('New invoice created', $message, $fields);
}

/**
* Handle the Invoice paid event.
*/
public function handleInvoicePaid(InvoicePaid $event): void
{
$invoice = $event->invoice;
$message = "Invoice paid: {$invoice->id} - {$invoice->user->name} - " . config('settings::currency_sign') . "{$invoice->total()}";
$this->sendWebhook('Invoice paid', $message);
}


public function newTicketMessage($event)
{
$ticket = $event->ticket;
$message = $event->message;
$dcmessage = "{$message->message}\n";
$fields = [
[
'name' => 'Ticket ID',
'value' => '[#' . $ticket->id . '](' . route('admin.tickets.show', $ticket->id) . ')',
'inline' => true,
],
[
'name' => 'Ticket status',
'value' => $ticket->status,
'inline' => true,
],
[
'name' => 'Ticket priority',
'value' => $ticket->priority,
'inline' => true,
],
[
'name' => 'Ticket subject',
'value' => $ticket->title,
'inline' => true,
],
[
'name' => 'Ticket user',
'value' => '[' . $message->user->name . '](' . route('admin.clients.edit', $message->user->id) . ')',
'inline' => true,
],
];
$this->sendWebhook('New ticket message', $dcmessage, $fields);
}

public function newUser($event)
{
$user = $event->user;
$message = " ";
$fields = [
[
'name' => 'User ID',
'value' => '[#' . $user->id . '](' . route('admin.clients.edit', $user->id) . ')',
'inline' => true,
],
[
'name' => 'User name',
'value' => $user->name,
'inline' => true,
],
[
'name' => 'User email',
'value' => $user->email,
'inline' => true,
],
];
$this->sendWebhook('New user', $message, $fields);
}

public function newTicket($event)
{
$ticket = $event->ticket;
$message = " ";
$fields = [
[
'name' => 'Ticket ID',
'value' => '[#' . $ticket->id . '](' . route('admin.tickets.show', $ticket->id) . ')',
'inline' => true,
],
[
'name' => 'Ticket status',
'value' => $ticket->status,
'inline' => true,
],
[
'name' => 'Ticket priority',
'value' => $ticket->priority,
'inline' => true,
],
[
'name' => 'Ticket subject',
'value' => $ticket->title,
'inline' => true,
],
[
'name' => 'Ticket user',
'value' => '[' . $ticket->user->name . '](' . route('admin.clients.edit', $ticket->user->id) . ')',
'inline' => true,
],
];
$this->sendWebhook('New ticket', $message, $fields);
}

/**
* Register the listeners for the subscriber.
*
* @return array<string, string>
*/
public function subscribe(): array
{
return [
InvoiceCreated::class => 'handleInvoiceCreated',
InvoicePaid::class => 'handleInvoicePaid',
TicketMessageCreated::class => 'newTicketMessage',
UserCreated::class => 'newUser',
TicketCreated::class => 'newTicket',
];
}
}
70 changes: 70 additions & 0 deletions Gateways/LitePay/LitePay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace App\Extensions\Gateways\LitePay;

use App\Classes\Extensions\Gateway;
use App\Helpers\ExtensionHelper;
use Illuminate\Http\Request;
use App\Extensions\Gateways\LitePay\litepayclass;

class LitePay extends Gateway
{
public function getMetadata()
{
return [
'display_name' => 'LitePay',
'version' => '1.0.0',
'author' => 'Paymenter',
'website' => 'https://paymenter.org',
];
}

public function getConfig()
{
return [
[
'name' => 'secret',
'friendlyName' => 'Secret',
'type' => 'text',
'required' => true,
],
[
'name' => 'merchant_id',
'friendlyName' => 'VENDOR ID',
'type' => 'text',
'required' => true,
],
];
}

public function pay($total, $products, $invoiceId)
{
$litepay = new litepayclass('merchant');
$req = $litepay->__call('pay', [[
'vendor' => ExtensionHelper::getConfig('LitePay', 'merchant_id'),
'secret' => ExtensionHelper::getConfig('LitePay', 'secret'),
'invoice' => $invoiceId,
'price' => number_format($total, 2, '.', ''),
'currency' => ExtensionHelper::getCurrency(),
'callbackUrl' => url('/extensions/litepay/webhook') . '?invoiceId=' . $invoiceId . '&secret=' . ExtensionHelper::getConfig('LitePay', 'secret'),
'returnUrl' => route('clients.invoice.show', $invoiceId),
]]);

return $req->url;
}

public function webhook(Request $request)
{
$input = $request->all();
$invoiceId = $input['invoiceId'];
$secret = $input['secret'];
if (!isset($invoiceId) || !isset($secret))
return;
if ($secret !== ExtensionHelper::getConfig('LitePay', 'secret'))
return;
ExtensionHelper::paymentDone($invoiceId);

// Return *ok*
return response('*ok*');
}
}
55 changes: 0 additions & 55 deletions Gateways/LitePay/index.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

namespace App\Extensions\Gateways\LitePay;

if (!extension_loaded('curl')) {
throw new \Exception('cURL extension seems not to be installed');
}

class litepay
class litepayclass
{

/**
Expand Down
Loading