Vpa
Vpa

Reputation: 737

Missing required parameters for Route after razorpay response in laravel

I try to redirect to some route:url to capture my payment, and I have to passed the payment_id and amount to capture from controller, but the routes gives error like below

Thanks in advance

Errors I got

ErrorException (E_ERROR)
  Missing required parameters for [Route: razorpay.standard.success] [URI: razorpay/standard/success/{rzpId}/{amount}]. (View: /home/valpuia/projects/bagisto/packages/Vaube/Razorpay/src/Resources/views/standard-redirect.blade.php)

My Route

Route::prefix('razorpay/standard')->group(function () {
    Route::get('/success/{rzpId}/{amount}', 'RazorPayController@success')->name('razorpay.standard.success');
}

Controller

public function success($rzpId, $amt)
{
    dd($rzpId);
}

Blade.php after razorpay completed

"handler": function (response){
            // alert(response.razorpay_payment_id);
            if (typeof response.razorpay_payment_id == 'undefined' || response.razorpay_payment_id < 1) {
                redirect_url = '{{ route('razorpay.standard.cancel') }}';
            } else {
                redirect_url = '{{ route('razorpay.standard.success', [ "rzp_id" => 'response.razorpay_payment_id', "amount" => '$total_amount * 100']) }}';
            }
            location.href = redirect_url;
        },

Upvotes: 1

Views: 539

Answers (2)

Farid M
Farid M

Reputation: 63

You can't use the javascript variables inside PHP

try this solution:

Route::prefix('razorpay/standard')->group(function () {
    Route::get('/success/{rzpId?}/{amount?}', 'RazorPayController@success')->name('razorpay.standard.success');
}

and then change the route to

"handler": function (response){
            // alert(response.razorpay_payment_id);
            if (typeof response.razorpay_payment_id == 'undefined' || response.razorpay_payment_id < 1) {
                redirect_url = '{{ route('razorpay.standard.cancel') }}';
            } else {
                redirect_url = '{{ route("razorpay.standard.success")}}/'+response.razorpay_payment_id+'/'+'{{$total_amount * 100}}';
            }
            location.href = redirect_url;
        },

Upvotes: 2

Nauphal
Nauphal

Reputation: 6192

I think you have a typo in parameter name.

Please replace

"rzp_id" => 'response.razorpay_payment_id'

with

"rzpId" => 'response.razorpay_payment_id'

and try

Upvotes: 0

Related Questions