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
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!'));
}

View file

@ -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');

View file

@ -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)) {