Hello,I have been trying to implement payment gateway into my api but am not successfull.
Payment_request_id i am able to save but payment_id i am not able to save to my db.Plz have a look.
My controller functions :
public function quotationSelection()
{
$inputs = \Input::all();
Gateway::procedurebooking()->updateProcedureBookingRecordWithQuotation(\Input::all());
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://instamojo.com/api/1.1/payment-requests/');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("X-Api-Key:afc9995c28b25711fafa197a7c0ece08",
"X-Auth-Token:1e2ee5b69a3d477d84ef75e791b9c82a"));
$payload = Array(
'purpose' => 'Advanced payment',
'amount' => $inputs['advanced_amt'],
'phone' => $inputs['patient_mob'],
'bookingid' => $inputs['booking_id'],
'redirect_url' => url('/returnurl'),
'send_email' => true,
'webhook' => 'http://instamojo.com/webhook/',
'send_sms' => false,
'email' => '[email protected]',
'allow_repeated_payments' => false
);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
$response = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($err)
{
\Session::put('error','Payment Failed, Try Again!!');
return redirect()->back();
}
else
{
$data = json_decode($response);
}
$updatedb = Gateway::procedurebooking()->updateProcedureBookingRecordWithPaymentRequestStatus($inputs['booking_id'],$data->payment_request->id);
if($data->success == true) {
return redirect($data->payment_request->longurl);
} else {
\Session::put('error','Payment Failed, Try Again!!');
return redirect()->back();
}
return 'Updated';
}
public function returnurl(Request $request)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://instamojo.com/api/1.1/payments/'.$request->get('payment_id'));
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("X-Api-Key:afc9995c28b25711fafa197a7c0ece08",
"X-Auth-Token:1e2ee5b69a3d477d84ef75e791b9c82a"));
$response = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($err) {
\Session::put('error','Payment process Failed, Try Again!!');
return redirect()->route('quotationSelection');
} else {
$data = json_decode($response);
}
if($data->success == true)
{
if($data->payment->status == 'Credit')
{
// Here Your Database Insert Login
$updatepayment = Gateway::procedurebooking()->updateProcedureBookingRecordWithPaymentIDStatus($data->payment_request->id,$data->payment_id);
\Session::put('success','Your payment has been successfully');
return redirect()->route('quotationSelection');
}
else
{
\Session::put('error','Payment soln Failed, Try Again!!');
return redirect()->route('quotationSelection');
}
}
else
{
\Session::put('error','Payment soln Failed, Try Again!!');
return redirect()->route('quotationSelection');
}
}
Routes are :
Route::post('quotationSelection', ['as' => 'quotationselection', 'uses' => 'Api\Procedure\ProcedureController@quotationSelection']);
Route::get('returnurl', ['as' => 'returnurl', 'uses' => 'Api\Procedure\ProcedureController@returnurl']);