namespace App\Listeners; use App\Events\PaymentCompleted; use App\Models\DeliveredGiftCard; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Mail; use App\Mail\GiftCardDelivered; use Illuminate\Support\Facades\Log; class ProcessApiGiftCard { public function handle(PaymentCompleted $event) { $order = $event->order; foreach ($order->products as $product) { // Check karein if product requires API fetch (digital gift card) if ($product->is_digital) { try { // 1. Vendor API ko Request Bhejein (e.g., PSN, Steam card supplier) $response = Http::withHeaders([ 'Authorization' => 'Bearer ' . env('VENDOR_API_KEY'), 'Accept' => 'application/json', ])->post('https://vendor-api.com/api/v1/purchase', [ 'vendor_product_id' => $product->sku, // Martfury me product k SKU me vendor ka ID rakh sakte hain 'quantity' => 1 ]); if ($response->successful()) { $apiData = $response->json(); $giftCardCode = $apiData['secret_code']; // Vendor ki API ka response field // 2. Database me log store karein (Dashboard me dikhane ke liye) DeliveredGiftCard::create([ 'order_id' => $order->id, 'product_id' => $product->id, 'vendor_transaction_id' => $apiData['transaction_id'] ?? null, 'delivered_code' => $giftCardCode, 'customer_email' => $order->user->email, 'status' => 'success' ]); // 3. Customer ko automatically email send karein Mail::to($order->user->email)->queue(new GiftCardDelivered($giftCardCode, $order)); } else { // Agar vendor API balance khatam ho ya error de $this->logFailedDelivery($order, $product, 'Vendor API Error: ' . $response->body()); } } catch (\Exception $e) { // Network issue ya koi aur system error $this->logFailedDelivery($order, $product, $e->getMessage()); } } } } private function logFailedDelivery($order, $product, $errorMsg) { DeliveredGiftCard::create([ 'order_id' => $order->id, 'product_id' => $product->id, 'delivered_code' => 'FAILED', 'customer_email' => $order->user->email, 'status' => 'failed' ]); Log::error("Gift Card API Failed for Order {$order->id}: " . $errorMsg); // Yahan aap apne Admin ko bhi alert email bhej sakte hain } } Razer Gold Global MR - 100 USD - PAK GIFT CARD SUPPLY
00
0
No products in the cart.

Shopping Cart

Razer Gold Global MR - 100 USD

Brand: Razer Gold

Rs.31,350.00 Rs.33,000.00

Razer Gold Global MR
(Available)
Quantity

SKU:REL-10309-100

Categories:Mobile Gaming & In-Game


Add your review

Your email address will not be published. Required fields are marked *

Please login to write review!

Upload photos

Looks like there are no reviews yet.

Related products

Your experience on this site will be improved by allowing cookies Cookie Policy