How to Integrate PayUMoney in Laravel

In this blog, we will discuss how to integrate PayUMoney in Laravel development.

Here are the following 9 steps to show How to Integrate PayUMoney Payment Gateway in Laravel. So, let's start.

Step 1:

Create PayUMoney account

  Go to http://payumoney.com/ and sign up as a merchant account.

Step 2:

At the time of sign up use your valid email ID.

Step 3:

Fill in all required business details.

Step 4:

Add your bank account detail.

Step 5:

Create route in Web.php file

   Route::prefix('pay-with-Payumoney')->name('pay-with-Payumoney')->group(function () {
   Route::get('/','PaymentController@index')->name('.view');
   Route::post('/success','PaymentController@success')->name('.success');
   Route::get('/error','PaymentController@error')->name('.error');
});

Step 6:

PaymentController with index function

public function index(){
  return view('pay-with-Payumoney');
}

Step 7:

View page (pay-with-Payumoney.blade.php)

https://test.payu.in";
   $PAYU_BASE_URL = "https://secure.payu.in";
   $action = '';
   $txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
   $posted = array();
   $posted = array(
       'key' => $MERCHANT_KEY,
       'txnid' => $txnid,
       'amount' => 1000,
       'firstname' => Auth::user()->name,
       'email' => Auth::user()->email,
       'productinfo' => 'PHP Project Subscribe',
       'surl' => 'http://example.com/subscribe-response/',
       'furl' => 'http://example.com/subscribe-cancel/',
       'service_provider' => 'payu_paisa',
   );

   if(empty($posted['txnid'])) {
       $txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
   }
   else
   {
       $txnid = $posted['txnid'];
   }
   $hash = '';
   $hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
   if(empty($posted['hash']) && sizeof($posted) > 0) {
       $hashVarsSeq = explode('|', $hashSequence);
       $hash_string = '';
       foreach($hashVarsSeq as $hash_var) {
           $hash_string .= isset($posted[$hash_var]) ? $posted[$hash_var] : '';
           $hash_string .= '|';
       }
       $hash_string .= $SALT;
       $hash = strtolower(hash('sha512', $hash_string));
       $action = $PAYU_BASE_URL . '/_payment';
   }
   elseif(!empty($posted['hash']))
   {
       $hash = $posted['hash'];
       $action = $PAYU_BASE_URL . '/_payment';
   }
?>

 
 
 
 
   Processing.....
       








http://example.co/subscribe-response/" />
http://example.co/subscribe-cancel/" />

Step 8:

PaymentController with success function

public function success(Request $request){
  dd($request);
}

Step 9:

PaymentController with error function

public function error(){
  dd("Your Payment Has Been Cancel");
}

All the above steps are created and tested by me. It works fine for me. Hope you have read and will try all the steps. If you have any questions or suggestions, please let me know in the comment section. See you on my next blog.

Comments

We Serve clients globally in diverse industries

Stay Upto Date With Our Newsletter.