As I mentioned in the title I am trying to capture paypal transactions from cron once a condition is met. So imagine there are 25 orders (all of them authorized waiting for capturing) and now I need to capture them. I have used curl and cron in order to do so automatically. But the case is that this process is overloading the server it might take too much time to be completed (if there are 250 orders for example). Just wanted to ask maybe there is an alternative easier way to make it happen. Am I doing this wrong? cronjob php file code is below:
function get_content($URL){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $URL);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
if ($db->total_records($rs) > 0) {//this is the condition which we are checking here
while($resultset = $db->fetch($rs)){
$data = get_content('https://'.$_SERVER['SERVER_NAME'].'/api/paypal/paypal_acts.php?capture_order_id='.$resultset['id']);
$data = json_decode($data);
$status = $data->status;
if ($status === 'COMPLETED' ) {
// success
//we are inserting the data into the DB and so on..
}
Everything works with this flow but for instance let's say there are 5 orders. It takes 3-5 seconds to complete. Just imagine how much would it take if there would be more than 100 orders? There should be a more convenient way. I can't capture immediately at checkout time as I need to verify some things before capture.
CodePudding user response:
What you describe is perfectly normal for a batch capture of so many authorizations.
In fact, PayPal recommends that you sleep for 5 seconds (5000ms) between each call, as there are rate limits.