feat: Create Invoiceable Trait & Fix routing Extension

This commit is contained in:
IceToast 2023-01-14 22:38:13 +01:00
parent 10f7e2688e
commit 8a03a7b16b
3 changed files with 8 additions and 10 deletions

View file

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

View file

@ -3,4 +3,4 @@
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::get('payment/PayPalPay/{shopProduct}', [PaymentController::class, 'PaypalPay'])->name('payment.PayPalPay'); 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');

View file

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