Laravel / Payment Gateway / Razor Payment
Razor Payment
-
Package Installation
1.composer.json
"require": { "razorpay/razorpay": "^2.8" } 2. run composer update
-
Coding
1. add key and secret in .env
RAZOR_KEY_ID=rzp_test_iOJPLwtl4LNoTD RAZOR_KEY_SECRET=JK8q8JCGjYClBJ4DBrxUfy1F 2. add razor pay script in the view
3. insert payment request into payment_requests table and return id
$payment=PaymentRequest::create($input); $arr = ['payment_id'=>$payment->id]; echo json_encode($arr); 4. verify and capture the razor payment
use Razorpay\Api\Api; ... . ..... try { $api = new Api(env('RAZOR_KEY_ID'), env('RAZOR_KEY_SECRET')); $payment_details = $api->payment->fetch($input['razorpay_payment_id'])->capture(array('amount'=>intval($paymentRequest->amount*100),'currency' => 'INR')); } catch (exception $e) { return response()->json([ 'status' => 'error', 'message' =>'invalid payment.', 'code' => 'RAF' ], 500); }