How to integrate Razorpay payment gateway in a PHP laravel Application
|
Razorpay is a payments company that provides payment solutions to online merchants in India. Razorpay allows
online businesses to accept, process and disburse digital payments through several payment modes like debit cards, credit
cards, net banking, and prepaid digital wallets.
online businesses to accept, process and disburse digital payments through several payment modes like debit cards, credit
cards, net banking, and prepaid digital wallets.
Getting Started with Razorpay
Reference_Link: https://github.com/razorpay/razorpay-php
1.Installation:
1.Installation:
composer require razorpay/razorpay:2.*
2.Create a Config file:
2.Create a Config file:
Create custom.php in config folder. In this file set our razorpay account’s razorpay_id and razor_secret using for
our integration.
return [
‘razor_id’ => ‘test_razor_id’,
‘razor_sceret’ => ‘test razor secret’
];
3.Create route:
Open routes/web.php and create following two route.
// Get Route For Show Payment Form
Route::get('paywithrazorpay','RazorpayController@payWithRazorpay')->name('paywithrazorpay');
// Post Route For Makw Payment Request
Route::post('payment', 'RazorpayController@payment')->name('payment');
4.Create a controller:
4.Create a controller:
Create RazorpayController.php file in your app/Http/Controllers folder.
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Razorpay\Api\Api;
use Session;
use Redirect;
class RazorpayController extends Controller
{
public function payWithRazorpay()
{
return view('payWithRazorpay');
return view('payWithRazorpay');
}
public function payment()
{
{
// Input items of form
$input = Input::all();
// get API Configuration
$api = new Api(config('custom.razor_key'), config('custom.razor_secret'));
// Fetch payment information by razorpay_payment_id
$payment = $api->payment->fetch($input['razorpay_payment_id']);
if(count($input) && !empty($input['razorpay_payment_id'])) {
try {
$response = $api->payment->fetch($input['razorpay_payment_id'])
->capture(array('amount'=>$payment['amount']));
} catch (\Exception $e) {
return redirect()->back(‘error’,$e->getMessage());
}
// Do something here for store payment details in database...
}
return redirect()->back(‘’success’,’Payment Successfully.’);
} }
Checkout Form:
For standard checkout, you pass the options to checkout.js via data attributes in the script tag.
The script tag is enclosed within a form tag. Once the payment has been authorized, the
form is auto-submitted to the URL set in action by you in the form tag.
The script tag is enclosed within a form tag. Once the payment has been authorized, the
form is auto-submitted to the URL set in action by you in the form tag.
<form action="/payment" method="POST">
<!-- Note that the amount is in paise = 50 INR -->
<script
src="https://checkout.razorpay.com/v1/checkout.js"
data-key="<YOUR_KEY_ID>"
data-amount="5000"
data-buttontext="Pay with Razorpay"
data-name="Merchant Name"
data-description="Purchase Description"
data-image="https://your-awesome-site.com/your_logo.jpg"
data-prefill.name="Gaurav Kumar"
data-prefill.email="test@test.com"
data-theme.color="#F37254"
></script>
<input type="hidden" value="Hidden Element" name="hidden">
</form>
Payout:
Step 1: Go to the dashboard via login razorpay.
Step 2: Go to Route->Add Account.
The transaction amount is routed via the created account to Razorpay’s acquiring banking partners.
$transfer = $api->payment->fetch($input['razorpay_payment_id'])->transfer(
array('transfers' => [
[
'account' => 'acc_6koWN7bvxujzxM',
'amount' => $payment['amount'],
'currency' => 'INR'
],
[
'account' => 'acc_6koWN7bvxujzdE',
'amount' => $payment['amount'],
'currency' => 'INR'
]
])
);
Conclusion:
In short, Razorpay is one of the most interesting payment methods on the market. Among the
keys to its success are the presence of a support team committed to customers and companies, with a
transparent and close way of working, in constant contact with the problems and needs of the online
payment sector.
keys to its success are the presence of a support team committed to customers and companies, with a
transparent and close way of working, in constant contact with the problems and needs of the online
payment sector.
In short, what are Razorpay’s strengths? Let’s see:
⇾ Their checkouts are aesthetically effective and easy to integrate.
⇾ They require only one line of JavaScript and are clear and intuitive for eCommerce customers.
⇾ Their checkouts are aesthetically effective and easy to integrate.
⇾ They require only one line of JavaScript and are clear and intuitive for eCommerce customers.
⇾ Its multiple payment methods make Razorpay a very attractive option for e-commerce, who can
receive payments by credit card and debit card, bank transfers and by the main eWallets, without
forgetting UPI payments.
receive payments by credit card and debit card, bank transfers and by the main eWallets, without
forgetting UPI payments.
⇾ Razorpay’s 2% and 3% commissions are very competitive, with two plans to choose from
(Standard Plan and Enterprise Plan) that adapt to the needs of each company.
(Standard Plan and Enterprise Plan) that adapt to the needs of each company.
⇾ From the point of view of the developers, Razorpay is a very friendly platform.
It has a large number of manuals and informative documents related to SDK codes, APIs, etc.,
which speed up its integration for programming and web development professionals.
It has a large number of manuals and informative documents related to SDK codes, APIs, etc.,
which speed up its integration for programming and web development professionals.
Comments
Post a Comment