Skip to content

Commit

Permalink
added laravel pint
Browse files Browse the repository at this point in the history
  • Loading branch information
alifaraun committed Dec 27, 2023
1 parent 31f06a9 commit 5a6b41d
Show file tree
Hide file tree
Showing 27 changed files with 372 additions and 343 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"nunomaduro/larastan": "^2.4",
"guzzlehttp/guzzle": "7.5.x-dev",
"nunomaduro/collision": "^7.0",
"laravel/legacy-factories": "1.x-dev"
"laravel/legacy-factories": "1.x-dev",
"laravel/pint": "dev-main"
}
}
69 changes: 68 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/Events/ApprovedRefundTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MoamalatPay\Events;


class ApprovedRefundTransaction extends BaseTransactionEvent
{
//
Expand Down
1 change: 0 additions & 1 deletion src/Events/ApprovedSaleTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MoamalatPay\Events;


class ApprovedSaleTransaction extends BaseTransactionEvent
{
//
Expand Down
1 change: 0 additions & 1 deletion src/Events/ApprovedTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MoamalatPay\Events;


class ApprovedTransaction extends BaseTransactionEvent
{
//
Expand Down
1 change: 0 additions & 1 deletion src/Events/ApprovedVoidRefundTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MoamalatPay\Events;


class ApprovedVoidRefundTransaction extends BaseTransactionEvent
{
//
Expand Down
1 change: 0 additions & 1 deletion src/Events/ApprovedVoidSaleTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MoamalatPay\Events;


class ApprovedVoidSaleTransaction extends BaseTransactionEvent
{
//
Expand Down
4 changes: 0 additions & 4 deletions src/Events/BaseTransactionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,16 @@ abstract class BaseTransactionEvent
{
use Dispatchable, InteractsWithSockets, SerializesModels;



/**
* The notification instance.
*
* @var MoamalatPayNotification
*/
public $notification;


/**
* Create a new event instance.
*
* @param MoamalatPayNotification $notification
* @return void
*/
public function __construct(MoamalatPayNotification $notification)
Expand Down
2 changes: 0 additions & 2 deletions src/Events/DisallowedRequestEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
namespace MoamalatPay\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class DisallowedRequestEvent
{

use Dispatchable, InteractsWithSockets, SerializesModels;
}
1 change: 0 additions & 1 deletion src/Events/UnverfiedTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MoamalatPay\Events;


class UnverfiedTransaction extends BaseTransactionEvent
{
//
Expand Down
1 change: 0 additions & 1 deletion src/Events/VerfiedTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace MoamalatPay\Events;


class VerfiedTransaction extends BaseTransactionEvent
{
//
Expand Down
11 changes: 4 additions & 7 deletions src/Http/Controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
/**
* Class ConfigController
*/

class ConfigController extends BaseController
{

/**
* Genearte SecureHash for use in payment transaction
*
* @param GenerateSecureKeyRequest $request
* @return \Illuminate\Http\JsonResponse
*/
public function generateSecureKey(GenerateSecureKeyRequest $request)
Expand All @@ -24,13 +21,13 @@ public function generateSecureKey(GenerateSecureKeyRequest $request)
$MerchantId = config('moamalat-pay.merchant_id');
$amount = $request->amount;
$merchantReference = $request->merchantReference;
$key = pack("H*", config('moamalat-pay.key'));
$DateTimeLocalTrxn = time();
$key = pack('H*', config('moamalat-pay.key'));
$DateTimeLocalTrxn = time();
$encode_data = "Amount={$amount}&DateTimeLocalTrxn={$DateTimeLocalTrxn}&MerchantId={$MerchantId}&MerchantReference={$merchantReference}&TerminalId={$TerminalId}";

return response()->json([
'secureHash' => hash_hmac('sha256', $encode_data, $key),
'DateTimeLocalTrxn' => $DateTimeLocalTrxn
'secureHash' => hash_hmac('sha256', $encode_data, $key),
'DateTimeLocalTrxn' => $DateTimeLocalTrxn,
]);
}
}
23 changes: 11 additions & 12 deletions src/Http/Controllers/NotificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

namespace MoamalatPay\Http\Controllers;

use Exception;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Exception;
use MoamalatPay\Events\UnverfiedTransaction;
use MoamalatPay\Events\VerfiedTransaction;
use MoamalatPay\Events\ApprovedTransaction;
use MoamalatPay\Events\ApprovedSaleTransaction;
use MoamalatPay\Events\ApprovedRefundTransaction;
use MoamalatPay\Events\ApprovedVoidSaleTransaction;
use MoamalatPay\Events\ApprovedSaleTransaction;
use MoamalatPay\Events\ApprovedTransaction;
use MoamalatPay\Events\ApprovedVoidRefundTransaction;
use MoamalatPay\Events\ApprovedVoidSaleTransaction;
use MoamalatPay\Events\UnverfiedTransaction;
use MoamalatPay\Events\VerfiedTransaction;
use MoamalatPay\Models\MoamalatPayNotification;

/**
* Class NotificationController
*/

class NotificationController extends BaseController
{
public function store(Request $request)
Expand All @@ -39,7 +38,6 @@ public function store(Request $request)
'ActionCode' => 'nullable',
]);


$data['ip'] = $request->ip();
$data['request'] = json_encode($request->all());
$data['verified'] = $this->validateSecureHas(
Expand All @@ -51,18 +49,18 @@ public function store(Request $request)
$request->input('TerminalId')
);

$notification = MoamalatPayNotification::create($data);
$notification = MoamalatPayNotification::create($data);

$this->dispatchEvents($notification);

return response()->json(["Message" => 'Success', 'Success' => true]);
return response()->json(['Message' => 'Success', 'Success' => true]);
}

protected function dispatchEvents(MoamalatPayNotification $notification)
{
if ($notification->verified) {
VerfiedTransaction::dispatch($notification);
if (/* $notification->Message == 'Approved' && */$notification->ActionCode === '00') { // aproved
if (/* $notification->Message == 'Approved' && */ $notification->ActionCode === '00') { // aproved
ApprovedTransaction::dispatch($notification);
switch ($notification->TxnType) {
case '1':
Expand Down Expand Up @@ -91,7 +89,8 @@ protected function validateSecureHas($secureHash, $Amount, $Currency, $DateTimeL
{
try {
$encode_data = "Amount=$Amount&Currency=$Currency&DateTimeLocalTrxn=$DateTimeLocalTrxn&MerchantId=$MerchantId&TerminalId=$TerminalId";
$key = pack("H*", config('moamalat-pay.notification.key'));
$key = pack('H*', config('moamalat-pay.notification.key'));

return strtoupper(hash_hmac('sha256', $encode_data, $key)) === strtoupper($secureHash);
} catch (Exception $e) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/AllowedIps.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AllowedIps
public function handle($request, Closure $next)
{
$allowed = config('moamalat-pay.notification.allowed_ips');
if (!in_array('*', $allowed) && !in_array($request->ip(), $allowed)) {
if (! in_array('*', $allowed) && ! in_array($request->ip(), $allowed)) {
DisallowedRequestEvent::dispatch();
abort(403);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Http/Requests/GenerateSecureKeyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class GenerateSecureKeyRequest extends FormRequest
public function rules(): array
{
return [
"MID" => "required",
"TID" => "required",
'MID' => 'required',
'TID' => 'required',
'amount' => 'required|integer|min:1',
'merchantReference' => 'nullable',
];
Expand All @@ -30,14 +30,14 @@ public function after(): array
return [
function (Validator $validator) {

if (!$validator->errors()->has('MID') && $this->MID != config('moamalat-pay.merchant_id')) {
if (! $validator->errors()->has('MID') && $this->MID != config('moamalat-pay.merchant_id')) {
$validator->errors()->add('MID', 'The MID is incorrect');
}

if (!$validator->errors()->has('TID') && $this->TID != config('moamalat-pay.terminal_id')) {
if (! $validator->errors()->has('TID') && $this->TID != config('moamalat-pay.terminal_id')) {
$validator->errors()->add('TID', 'The TID is incorrect');
}
}
},
];
}

Expand Down
12 changes: 4 additions & 8 deletions src/Models/MoamalatPayNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

use Illuminate\Database\Eloquent\Model;


/**
* Class MoamalatPayNotification
* @package MoamalatPay\Models
*
* @version Sep 17, 2022, 5:12 pm UTC
*
* @property integer $id
* @property int $id
* @property string $MerchantId
* @property string $TerminalId
* @property string $DateTimeLocalTrxn
Expand All @@ -26,12 +25,11 @@
* @property string $PayerName
* @property string $ActionCode
* @property string $request
* @property boolean $verified
* @property bool $verified
* @property string $ip
*/
class MoamalatPayNotification extends Model
{

public $fillable = [
'MerchantId',
'TerminalId',
Expand All @@ -49,7 +47,7 @@ class MoamalatPayNotification extends Model
'ActionCode',
'request',
'verified',
'ip'
'ip',
];

protected $casts = [
Expand Down Expand Up @@ -81,8 +79,6 @@ public function getTable()
return config('moamalat-pay.notification.table', parent::getTable());
}



/**
* Scope a query to only include approved transactions.
*
Expand Down
1 change: 0 additions & 1 deletion src/Pay.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class Pay
{

public function init()
{
return view('moamalat-pay::pay')->render();
Expand Down
Loading

0 comments on commit 5a6b41d

Please sign in to comment.