Browse Source

feat: ✨ Create Invoiceable Trait & Fix routing Extension

IceToast 2 years ago
parent
commit
8a03a7b16b

+ 3 - 5
app/Extensions/PaymentGateways/PayPal/index.php

@@ -1,5 +1,6 @@
 <?php
 
+use App\Events\PaymentEvent;
 use App\Events\UserUpdateCreditsEvent;
 use App\Models\PartnerDiscount;
 use App\Models\Payment;
@@ -151,11 +152,8 @@ function PaypalSuccess(Request $laravelRequest)
                     'shop_item_product_id' => $shopProduct->id,
             ]);
             event(new UserUpdateCreditsEvent($user));
-            //only create invoice if SETTINGS::INVOICE:ENABLED is true
-            if (config('SETTINGS::INVOICE:ENABLED') == 'true') {
-                // use the createInvoice method that is defined in the Invoiceable trait
-                $payment->createInvoice($user, $payment, 'paid', $shopProduct->currency_code);
-            }
+            event(new PaymentEvent($payment));
+            
             //redirect back to home
             return redirect()->route('home')->with('success', __('Your credit balance has been increased!'));
         }

+ 1 - 1
app/Extensions/PaymentGateways/PayPal/routes.php

@@ -3,4 +3,4 @@
 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');
+Route::get('payment/PayPalSuccess', [PaymentController::class, 'PaypalSuccess'])->name('payment.PayPalSuccess');

+ 4 - 4
app/Traits/Invoiceable.php

@@ -14,7 +14,7 @@ use Symfony\Component\Intl\Currencies;
 
 trait Invoiceable
 {
-    public function createInvoice($user, $payment, $paymentStatus, $currencyCode)
+    public function createInvoice($user, $payment)
     {
         $shopProduct = ShopProduct::where('id', $payment->shop_item_product_id)->first();
         //create invoice
@@ -60,13 +60,13 @@ trait Invoiceable
             ->taxRate(floatval($shopProduct->getTaxPercent()))
             ->shipping(0)
             ->addItem($item)
-            ->status(__($paymentStatus))
+            ->status(__($payment->status))
             ->series(now()->format('mY'))
             ->delimiter("-")
             ->sequence($newInvoiceID)
             ->serialNumberFormat(config("SETTINGS::INVOICE:PREFIX") . '{DELIMITER}{SERIES}{SEQUENCE}')
-            ->currencyCode($currencyCode)
-            ->currencySymbol(Currencies::getSymbol($currencyCode))
+            ->currencyCode($payment->currency_code)
+            ->currencySymbol(Currencies::getSymbol($payment->currency_code))
             ->notes($notes);
 
         if (file_exists($logoPath)) {