T
T
TimurKov122022-03-26 06:33:47
Software design
TimurKov12, 2022-03-26 06:33:47

How to get Laravel authorized user details?

I am developing a project on Laravel 8. I ran into the following problem: I am working with a payment system to receive payments. When a user makes a payment, a callback from the payment system comes to a certain address, then it is processed and comes by the POST method to my site. I then track this in web.php and pass it to the controller. In the controller, I need to change the data about the user who made the payment, but when I try to find out about him through Auth::user() , nothing works. Also tried to track user id via Auth::id() , but also to no avail. When I check Auth::check() says that the user is not authorized. How can this problem be solved?
web.php

Route::post('/payment', [RateController::class, 'payment'])->name('payment');

RateController:
public function payment(Request $request) {
    if($request->input('status') == 'done') {
        $user = Auth::user();
        $user->rate = $request->input('rate');
        $user->save();
    }
}

Callback reception:
<?php
    $str = file_get_contents('php://input');
    $object = json_decode($str, true);
    $url = 'https://findinvestor.me/payment';
    $params = array(
        'rate' => 'bronze',
        'status' => $object['status'],
    );
    $result = file_get_contents($url, false, stream_context_create(array(
        'http' => array(
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => http_build_query($params)
        )
    )));
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JhaoDa, 2022-03-26
@JhaoDa

Save information about the order with you, with reference to the user, and then redirect it to payment. Or, if the payment API can be used to transfer additional. parameters, then pass it there (with the understanding that this is a potential hole).

S
Sanes, 2022-03-26
@Sanes

Something you just do not go there. Or I did not understand your cunning plan.
Auth::user()this is an authorized user. In the response from the payment system, you have a transaction ID. It must be previously recorded in the database in due time and matched with the user id. There is also the status of the payment.
auth()->user()->idReturns the id of the authorized user.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question