4

I want to send user to payment gate. Normally it could be made by this form:

<form method="post" action="https://demo.moneta.ru/assistant.htm">
    <input type="hidden" name="MNT_ID" value="12345678">
    <input type="hidden" name="MNT_TRANSACTION_ID" value="000001">
    <input type="hidden" name="MNT_CURRENCY_CODE" value="USD">
    <input type="hidden" name="MNT_AMOUNT" value="123.45">
    <input type="submit" value="Pay">
</form>

User press "Pay" and redirect to payment gate.

But I want implement this workflow:

  1. User enter delivery info, payment method, etc.
  2. After that he press "Pay" and
  3. First I want to store data (I do it in my controller)...
  4. ... and after that I want redirect user to payment gate. (this is unclear for me)

The question is: how to redirect user to external resource from controller (method should be POST, and I need do send some data such as MNT_ID, etc. (see form example above)?

pupadupa
  • 1,278
  • 2
  • 15
  • 29
  • Probably already answered question: http://stackoverflow.com/questions/18770184/laravel-4-make-post-request-from-controller-to-external-url-with-data – Amarnasan Nov 04 '15 at 09:23

3 Answers3

3

I think this is what you are looking for:

call your function controller:

public function redirectPOST(){
//params
$USERNAME='username';
return view('your vie', compact('USERNAME'));}

then in your view:

<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script type="text/javascript">
 function closethisasap() {
 document.forms["redirectpost"].submit();
  }
 </script>
  </head>
 <body onload="closethisasap();">
 <form name="redirectpost" method="POST" action="http://URL">
 <input type="hidden" id="USERNAME" name="USERNAME" value="{{$USERNAME}}">
 </form>
 </body>
 </html>
a3rxander
  • 670
  • 2
  • 7
  • 14
1

It could help you use the Laravel controller as usual and redirect after to the external resource.

In your view redirect the action to your controller:

<form method="post" action={{ action('Controller@method') }}>
    <input type="hidden" name="MNT_ID" value="12345678">
    <input type="hidden" name="MNT_TRANSACTION_ID" value="000001">
    <input type="hidden" name="MNT_CURRENCY_CODE" value="USD">
    <input type="hidden" name="MNT_AMOUNT" value="123.45">
    <input type="submit" value="Pay">
</form>

In your controller:

public function method(Request $request)
{
     // Validate
     // Store
     // ...
     Redirect::away('https://demo.moneta.ru/assistant.htm')->withInputs(Input::all());

}

I didn't test it, but I'm pretty sure that it works (or is near to the solution).

You can get other suggestion from the official guide: http://laravel.com/docs/5.1/responses#redirects

Jonathan
  • 8,402
  • 8
  • 49
  • 64
Samuele Colombo
  • 675
  • 1
  • 6
  • 19
  • `return Redirect::away("https://demo.moneta.ru/assistant.htm")->withInputs(Input::all());` do not help. As I can see in browser's network explorer: request is GET and there is no data in request. BTW, I add `Input::all()` because without it there was an error. – pupadupa Nov 04 '15 at 10:10
  • you're right, this is a GET request and `withInputs()` needs `Input:all()` as parameter. Have you tried to validate the form via AJAX request (so you can validate and store your data) and redirect to the external url browser side? – Samuele Colombo Nov 04 '15 at 11:44
0

You can redirect to an external URL with Laravels's redirect. First import the Redirect to your controller and

use Illuminate\Support\Facades\Redirect;
return Redirect::away($redirectUrl)->with(['user_id'=>$user_id]);

would help you to send the request as a post with the needed params.

JON
  • 645
  • 7
  • 22
Abhi Das
  • 315
  • 6
  • 7