relocating
This commit is contained in:
@@ -8,6 +8,9 @@ use App\Models\OrderItem;
|
||||
use App\Models\Product;
|
||||
use App\Models\PrintStock;
|
||||
use App\Services\ShippingService;
|
||||
use App\Services\InvoiceService;
|
||||
use App\Mail\InvoiceEmail;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class OrderController extends Controller
|
||||
@@ -186,8 +189,7 @@ class OrderController extends Controller
|
||||
$orderItems[$itemKey] = [
|
||||
'product_id' => $productId,
|
||||
'quantity' => $quantity,
|
||||
'price' => $product->price,
|
||||
'stock_cost' => $stockCost,
|
||||
'price' => $subtotal / $quantity,
|
||||
'print_stock_id' => $printStockId,
|
||||
'type' => $type,
|
||||
'is_sample' => $isSample,
|
||||
@@ -572,6 +574,27 @@ class OrderController extends Controller
|
||||
$product->save();
|
||||
}
|
||||
|
||||
// Generate invoice PDF
|
||||
try {
|
||||
$invoicePath = InvoiceService::generateInvoice($order);
|
||||
|
||||
// Send invoice email via Mailjet
|
||||
Mail::to($order->customer_email)
|
||||
->send(new InvoiceEmail($order, $invoicePath));
|
||||
|
||||
\Log::info('Yoco Webhook: Invoice generated and email sent', [
|
||||
'order_uuid' => $orderUuid,
|
||||
'order_id' => $order->id,
|
||||
'invoice_path' => $invoicePath,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error('Yoco Webhook: Invoice generation or email failed', [
|
||||
'order_uuid' => $orderUuid,
|
||||
'order_id' => $order->id,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
\Log::info('Yoco Webhook: Order updated for successful payment', [
|
||||
'order_uuid' => $orderUuid,
|
||||
'order_id' => $order->id,
|
||||
@@ -652,4 +675,45 @@ class OrderController extends Controller
|
||||
|
||||
return response()->json(['status' => 'success']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the track order search form
|
||||
*/
|
||||
public function trackForm()
|
||||
{
|
||||
return view('track-order');
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for an order by order number and email
|
||||
*/
|
||||
public function trackSearch(Request $request)
|
||||
{
|
||||
$key = 'track-order:' . $request->ip();
|
||||
|
||||
// Check if IP has already exceeded rate limit from previous failed attempts
|
||||
if (\Illuminate\Support\Facades\RateLimiter::tooManyAttempts($key, 5)) {
|
||||
return redirect()->route('track-order-form')
|
||||
->withErrors(['error' => 'Too many search attempts. Please try again later.']);
|
||||
}
|
||||
|
||||
$request->validate([
|
||||
'order_number' => 'required|string',
|
||||
'email' => 'required|email',
|
||||
]);
|
||||
|
||||
$order = Order::where('order_number', strtoupper($request->input('order_number')))
|
||||
->where('customer_email', strtolower($request->input('email')))
|
||||
->first();
|
||||
|
||||
if (!$order) {
|
||||
// Only increment rate limit on failed searches
|
||||
\Illuminate\Support\Facades\RateLimiter::hit($key, 600); // 10 minutes
|
||||
return redirect()->route('track-order-form')
|
||||
->withErrors(['error' => 'No order found with the provided information.']);
|
||||
}
|
||||
|
||||
// Successful search - no rate limit increment
|
||||
return view('track-order-result', ['order' => $order]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user