Make sure that you add the webhook endpoint to your VerifyCsrfToken middleware class, in the except array, because whenever PayStack sends a POST request, Laravel will deny the request:
Dec 15, 2019
8
Level 1
How to Use Webhook Url and save data in Database with Paystack
I am using https://github.com/iamraphson/vue-paystack in my laravel+vue SPA project. I can receive payments perfectly but now need to hit a webhook url so that I can update database and give value to user. I have set up the route and added the url on my paystack dashboard. What should I do next? How do I get the charge events and other details in my controller method and send to database? Here's Paystack's documentation largely done in php: https://developers.paystack.co/v2.0/docs/events
I have tried the following in my controller:
public function payme(Request $request){
//This receives the webhook
//$email = json_decode($input['data']['customer']['email']);
$email = $request->input('data.customer.email');
$bankname = $request->input('data.gateway_response');
//$bankname = json_decode($input['data']['gateway_response']);
$user = User::where('email', $email);
$user->bankname = $bankname;
$user->save();
return response()->json('processed', 200);
Level 1
This worked:
public function payme(Request $request){
//This receives the webhook
//amount //email prevent multiple pending payments
$email = $request->input('data.customer.email');
$amountpaid = ($request->input('data.amount'))/100;
$user_id = User::where('email', $email)->firstOrFail()->id;
$user = User::find($user_id);
Please or to participate in this conversation.