15

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??

SEYED BABAK ASHRAFI
  • 4,093
  • 4
  • 22
  • 32
Noble Eugene
  • 523
  • 1
  • 5
  • 15

1 Answers1

46

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);
Mohammad Hosseini
  • 1,649
  • 1
  • 16
  • 31