Home > Software design >  Capture Paypal orders with the cronjob
Capture Paypal orders with the cronjob

Time:04-11

As I mentioned in the title I am trying to capture paypal transactions with the cronjob file once the 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 cronjob in order to make it 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 codes are 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 workflow but for instance let's say there are 5 orders. It takes 3-5 seconds to be completed. I just imagine how much would it take if there would be more than 100 orders? There should be much convenient way. I can't capture immediately as I need to verify some things before capturing the order.

CodePudding user response:

What you describe is perfectly normal for a batch capture of so many orders.

In fact, PayPal recommends that you sleep for 5 seconds (5000ms) between each call, as there are rate limits.

  • Related