瀏覽代碼

feat: ✨ Support csrf ignoring routes for extensions & moved extension config to own file

IceToast 2 年之前
父節點
當前提交
d11bb52038

+ 12 - 0
app/Extensions/PaymentGateways/PayPal/config.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace App\Extensions\PaymentGateways\PayPal;
+
+function getConfig()
+{
+    return [
+        "name" => "PayPal",
+        "description" => "PayPal payment gateway",
+        "RoutesIgnoreCsrf" => [],
+    ];
+}

+ 0 - 38
app/Extensions/PaymentGateways/PayPal/index.php

@@ -174,41 +174,3 @@ function getPaypalClientSecret()
 {
     return env('APP_ENV') == 'local' ? config("SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET") : config("SETTINGS::PAYMENTS:PAYPAL:SECRET");
 }
-function getPayPalConfig()
-{
-    return [
-        "name" => "PayPal",
-        "description" => "PayPal payment gateway",
-        "settings" => [
-            "mode" => [
-                "type" => "select",
-                "label" => "Mode",
-                "value" => config("APP_ENV") == 'local' ? "sandbox" : "live",
-                "options" => [
-                    "sandbox" => "Sandbox",
-                    "live" => "Live",
-                ],
-            ],
-            "CLIENT_ID" => [
-                "type" => "text",
-                "label" => "PayPal Client ID",
-                "value" => config("SETTINGS::PAYMENTS:PAYPAL:CLIENT_ID"),
-            ],
-            "SECRET" => [
-                "type" => "text",
-                "label" => "PayPal Secret",
-                "value" => config("SETTINGS::PAYMENTS:PAYPAL:SECRET"),
-            ],
-            "SANDBOX_CLIENT_ID" => [
-                "type" => "text",
-                "label" => "PayPal Sandbox Client ID",
-                "value" => config("SETTINGS::PAYMENTS:PAYPAL:SANDBOX_CLIENT_ID"),
-            ],
-            "SANDBOX_SECRET" => [
-                "type" => "text",
-                "label" => "PayPal Sandbox Secret",
-                "value" => config("SETTINGS::PAYMENTS:PAYPAL:SANDBOX_SECRET"),
-            ],
-        ],
-    ];
-}

+ 14 - 0
app/Extensions/PaymentGateways/Stripe/config.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Extensions\PaymentGateways\Stripe;
+
+function getConfig()
+{
+    return [
+        "name" => "Stripe",
+        "description" => "Stripe payment gateway",
+        "RoutesIgnoreCsrf" => [
+            "payment/StripeWebhooks",
+        ],
+    ];
+}

+ 0 - 37
app/Extensions/PaymentGateways/Stripe/index.php

@@ -371,40 +371,3 @@ function checkPriceAmount($amount, $currencyCode, $payment_method)
     ];
     return $amount >= $minimums[$currencyCode][$payment_method];
 }
-
-function getStripeConfig()
-{
-    return [
-        "name" => "Stripe",
-        "description" => "Stripe payment gateway",
-        "mode" => [
-            "type" => "select",
-            "label" => "Mode",
-            "value" => config("APP_ENV") == 'local' ? "sandbox" : "live",
-            "options" => [
-                "sandbox" => "Sandbox",
-                "live" => "Live",
-            ],
-        ],
-        "TEST_SECRET" => [
-            "type" => "text",
-            "label" => "Test Secret Key",
-            "value" => config("SETTINGS::PAYMENTS:STRIPE:TEST_SECRET"),
-        ],
-        "SECRET" => [
-            "type" => "text",
-            "label" => "Live Secret Key",
-            "value" => config("SETTINGS::PAYMENTS:STRIPE:SECRET"),
-        ],
-        "ENDPOINT_TEST_SECRET" => [
-            "type" => "text",
-            "label" => "Test Endpoint Secret",
-            "value" => config("SETTINGS::PAYMENTS:STRIPE:ENDPOINT_TEST_SECRET"),
-        ],
-        "ENDPOINT_SECRET" => [
-            "type" => "text",
-            "label" => "Live Endpoint Secret",
-            "value" => config("SETTINGS::PAYMENTS:STRIPE:ENDPOINT_SECRET"),
-        ],
-    ];
-}

+ 11 - 3
app/Http/Middleware/VerifyCsrfToken.php

@@ -2,7 +2,10 @@
 
 namespace App\Http\Middleware;
 
+use App\Helpers\ExtensionHelper;
 use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
+use Illuminate\Contracts\Encryption\Encrypter;
+use Illuminate\Contracts\Foundation\Application;
 
 class VerifyCsrfToken extends Middleware
 {
@@ -11,7 +14,12 @@ class VerifyCsrfToken extends Middleware
      *
      * @var array
      */
-    protected $except = [
-        'payment/StripeWebhooks',
-    ];
+    protected $except = [];
+
+    public function __construct(Application $app, Encrypter $encrypter)
+    {
+        $this->app = $app;
+        $this->encrypter = $encrypter;
+        $this->except = ExtensionHelper::getAllCsrfIgnoredRoutes();
+    }
 }