Curl executing twice

I’m using curl in my stripe webhook. When a payment if complete, my function will run a curl to pull data from an api URL. here is my curl code

$curl = new Curl();
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, (YII_ENV == 'dev') ? false : true);
$curl->setOpt(CURLOPT_SSL_VERIFYHOST, (YII_ENV == 'dev') ? false : 2);
//$curl->setOpt(CURLOPT_RETURNTRANSFER, false);
//$curl->setOpt(CURLOPT_URL, $apiURL);

if ($curl->error) {
} else {
    $response = $curl->response;

In general the code works fine, but once in a while it will pull data from $apiURL twice. Any idea how to fix this, or prevent it?

Could it be a race condition issue? I was looking into mutex, but not sure how to even implement it here.

PHP is not multithreading AFAIK, so racing stuffs are out of question, if that is true.
It must be something to do with the callback doing things twice.

I suggest you have mark on your model to see if the payment is already being processed and ignore the request to process. If not then call API. Simple and effective IMHO