浏览代码

feat: ✨ Fixed extension routes & Added PayPal Extension Routes

IceToast 2 年之前
父节点
当前提交
16a7391372

+ 6 - 0
app/Extensions/PaymentGateways/PayPal/routes.php

@@ -0,0 +1,6 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+
+Route::get('payment/PayPalPay/{shopProduct}', [PaymentController::class, 'PaypalPay'])->name('payment.PayPalPay');
+Route::get('payment/PayPalSuccess', [PaymentController::class, 'PaypalSuccess'])->name('payment.PaypalSuccess');

+ 32 - 0
app/Helpers/ExtensionHelper.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace App\Helpers;
+
+class ExtensionHelper
+{
+    public static function getExtensionConfig($extensionName, $nameSpace)
+    {
+        $extension = app_path() . '/Extensions/' . $nameSpace . "/" . $extensionName . "/index.php";
+        // Check if extension exists
+        if (!file_exists($extension)) {
+            return null;
+        }
+
+        // call the getConfig function from the index.php file of the extension
+        $config = include_once $extension;
+
+        // Check if the getConfig function exists
+        if (!function_exists('getConfig')) {
+            return null;
+        }
+
+        $config = call_user_func('getConfig');
+
+        // Check if the getConfig function returned an array
+        if (!is_array($config)) {
+            return null;
+        }
+
+        return $config;
+    }
+}

+ 0 - 0
public/images/paypal_logo.png → public/images/Extensions/PaymentGateways/paypal_logo.png


+ 0 - 0
public/images/stripe_logo.png → public/images/Extensions/PaymentGateways/stripe_logo.png


+ 11 - 2
routes/extensions.php

@@ -3,11 +3,20 @@
 use Illuminate\Support\Facades\Route;
 use Illuminate\Support\Facades\Route;
 
 
 Route::group(['prefix' => 'extensions'], function () {
 Route::group(['prefix' => 'extensions'], function () {
-    $extensions = glob(app_path() . '/Extensions/*', GLOB_ONLYDIR);
+    
+    // get all extensions that are inside App/Extensions
+    // It is important that the extensions are inside a folder with the name of the extension
+    // while those folders are inside Folders with the name of the type of extension like PaymentGateways, Themes, etc.
+    $extensionNamespaces = glob(app_path() . '/Extensions/*', GLOB_ONLYDIR);
+    $extensions = [];
+    foreach ($extensionNamespaces as $extensionNamespace) {
+        $extensions = array_merge($extensions, glob($extensionNamespace . '/*', GLOB_ONLYDIR));
+    }
+
     foreach ($extensions as $extension) {
     foreach ($extensions as $extension) {
         $routesFile = $extension . '/routes.php';
         $routesFile = $extension . '/routes.php';
         if (file_exists($routesFile)) {
         if (file_exists($routesFile)) {
             include_once $routesFile;
             include_once $routesFile;
         }
         }
-    }
+    }        
 });
 });

+ 3 - 2
routes/web.php

@@ -85,8 +85,7 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
 
 
     #payments
     #payments
     Route::get('checkout/{shopProduct}', [PaymentController::class, 'checkOut'])->name('checkout');
     Route::get('checkout/{shopProduct}', [PaymentController::class, 'checkOut'])->name('checkout');
-    Route::get('payment/PaypalPay/{shopProduct}', [PaymentController::class, 'PaypalPay'])->name('payment.PaypalPay');
-    Route::get('payment/PaypalSuccess', [PaymentController::class, 'PaypalSuccess'])->name('payment.PaypalSuccess');
+    Route::get('payment/pay', [PaymentController::class, 'pay'])->name('payment.pay');
     Route::get('payment/StripePay/{shopProduct}', [PaymentController::class, 'StripePay'])->name('payment.StripePay');
     Route::get('payment/StripePay/{shopProduct}', [PaymentController::class, 'StripePay'])->name('payment.StripePay');
     Route::get('payment/StripeSuccess', [PaymentController::class, 'StripeSuccess'])->name('payment.StripeSuccess');
     Route::get('payment/StripeSuccess', [PaymentController::class, 'StripeSuccess'])->name('payment.StripeSuccess');
     Route::get('payment/Cancel', [PaymentController::class, 'Cancel'])->name('payment.Cancel');
     Route::get('payment/Cancel', [PaymentController::class, 'Cancel'])->name('payment.Cancel');
@@ -214,3 +213,5 @@ Route::middleware(['auth', 'checkSuspended'])->group(function () {
 
 
     Route::get('/home', [HomeController::class, 'index'])->name('home');
     Route::get('/home', [HomeController::class, 'index'])->name('home');
 });
 });
+
+require __DIR__ . '/extensions.php';