I am trying to create a wordpress plugin which hits an API and get redirects to the paypal link for transaction. I am using curl request for hitting the API I am able to redirect the user to the paypal link but now I want to know weather the payment is successful or not and then if we are getting the successful transaction then I will hit another API. My issue is that I don't know how to do that.
Here is my code till What I did:
$(document).on('click','#addautolikesbtn',function (e) {
var package = $('#package').val();
jQuery.post(
ajaxlink.ajax_url,
{
'action': 'addorderautolike',
'data':{
'package':package
}
},
function (response){
var res = JSON.parse(response);
if(res.status == 200){
console.log(res.url);
window.location.replace(res.url);
}
return true;
}
);
});
add_action('wp_ajax_nopriv_addorderautolike', 'addorderautolike');
add_action('wp_ajax_addorderautolike', 'addorderautolike');
function addorderautolike(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://********/recurringPayment?package_id='.$_POST['data']['package']);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
echo $res;
die();
}