Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable SSL check with Laravel http post

Tags:

php

curl

laravel

I'm trying to make a post request in laravel to a payment endpoint with the following code

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
class AddCardController extends Controller
{
    //
    public function index()
    {
        return view("addcard");
    }
    public function requestPayment(Request $request)
    {
        $paystack_key = \config("app.paystack_key");
        $url = "https://api.paystack.co/transaction/initialize";
        $email = $request->user("distributors")->email;
        $fields = [
            "email"=>$email,
            "amount"=>50*100,
            "channels"=>["card"],
            "callback_url"=>"d"
        ];
        $query = http_build_query($fields);
        $response = Http::post($url,$fields)::withHeaders(["Authorization: Bearer $paystack_key",
        "Cache-Control: no-cache",])::withOptions(["verify"=>false]);
        return $response;
    }
}

Im geting the following error:

cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://api.paystack.co/transaction/initialize

Im running my Laravel app locally on Apache so I acknowledge the fact that there is no SSL running, but how can I bypass this error. In production ssl will be provided??

like image 580
Noble Eugene Avatar asked Dec 31 '22 14:12

Noble Eugene


1 Answers

You should use withoutVerifying() with your Post request.

  $response = Http::withoutVerifying()
        ->withHeaders(['Authorization' => 'Bearer ' . $paystack_key, 'Cache-Control' => 'no-cache'])
        ->withOptions(["verify"=>false])
        ->post($url,$fields);
like image 177
Mohammad Hosseini Avatar answered Jan 08 '23 02:01

Mohammad Hosseini