Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

please provide paylink #1

Open
VipinVishwakarma261 opened this issue Nov 8, 2024 · 0 comments
Open

please provide paylink #1

VipinVishwakarma261 opened this issue Nov 8, 2024 · 0 comments

Comments

@VipinVishwakarma261
Copy link

amount; $userId = Auth::id(); $userEmail = Auth::user()->email; $transactionNumber = time() . '_' . strtoupper(Str::random(10)); $response = retry(3, function () use ($url, $transactionAmount, $currencyCode, $apiKey, $lifetime, $transactionNumber, $userEmail) { return Http::withHeaders([ 'Content-Type' => 'application/json', ])->post($url, [ 'merchant' => $apiKey, 'amount' => $transactionAmount, 'currency' => $currencyCode, 'lifeTime' => $lifetime, 'feePaidByPayer' => 1, 'underPaidCover' => 1, 'callbackUrl' => route('paymentCallback'), 'returnUrl' => route('user.payment.fund'), 'description' => 'Order ' . $transactionNumber, 'orderId' => $transactionNumber, 'email' => $userEmail ]); }, 1000); $response->throw(); // Throws an exception if the request was not successful if ($response->successful()) { $responseData = $response->json(); $payLink = $responseData['payLink']; Payment::create([ 'user_id' => $userId, 'amount' => $transactionAmount, 'currency' => $currencyCode, 'pay_link' => $payLink, 'track_id' => $responseData['trackId'], 'expired_at' => Carbon::createFromTimestamp($responseData['expiredAt']), 'status' => 'pending', ]); return redirect()->away($payLink); } else { return back()->with('error', 'Failed to initiate payment.'); } } catch (RequestException $e) { return back()->with('error', 'Failed to initiate payment. Please try again later.'); } } public function paymentCallback(Request $request) { // Parse the callback data $callbackData = $request->all(); // Find the payment record by track ID $payment = Payment::where('track_id', $callbackData['trackId'])->first(); if ($payment) { if ($callbackData['status'] === 'Paid') { // Find the user associated with the payment $user = User::find($payment->user_id); // Convert amount from string to float $amount = floatval($callbackData['amount']); // Increase user balance by transaction amount $user->balance += $amount; // Create a new transaction record $transaction = Txn::new( $amount, 0, $amount, "Oxapay", 'Deposit With Oxapay', TxnType::Deposit, TxnStatus::Success, $callbackData['currency'], null, $user->id, null, 'User', [] ); // Save the transaction $transaction->save(); $user->save(); } // Update payment status $payment->status = $callbackData['status']; $payment->save(); } // Return a response (if needed) return response()->json(['message' => 'Callback processed successfully']); } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant