Samuz Posted March 4, 2012 Share Posted March 4, 2012 Okay so basically i'm working with codeigniter with some paypal integration. Anyway to cut a long story short, when someone makes a payment and it is approved. I have a method that is run which updates the 'amount paid' value in my table, then another method that is run that updates the 'percentage paid' value. Now my problem is that now the the 'percentage paid' method runs before the 'amount paid' method, which means the 'percentage paid' value stays the same as it was before (because the amount paid value hasn't been updated yet) and the amount paid value updates after. How would I get it so that the percentage value is updated after the paid value is updated? I tried using sleep, but that didn't seem to work.. $this->endaproblem->update($xploded[1], $xploded[2], $update_paid); sleep(1); $this->endaproblem->update($xploded[1], $xploded[2], $update_percent); Anyone have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/258218-how-should-i-do-this/ Share on other sites More sharing options...
darkfreaks Posted March 4, 2012 Share Posted March 4, 2012 might look into using a cronjob instead of the sleep command. http://net.tutsplus.com/tutorials/php/managing-cron-jobs-with-php-2/ Quote Link to comment https://forums.phpfreaks.com/topic/258218-how-should-i-do-this/#findComment-1323716 Share on other sites More sharing options...
freelance84 Posted March 4, 2012 Share Posted March 4, 2012 I don't think you should have to use either sleep or cron for this... Where are the two variables set (update and percentage)? Are they derived from the info posted to your IPN scripts from paypal? Quote Link to comment https://forums.phpfreaks.com/topic/258218-how-should-i-do-this/#findComment-1323737 Share on other sites More sharing options...
Samuz Posted March 4, 2012 Author Share Posted March 4, 2012 Actually it's sorted now, I just wasn't thinking logically. I just had to calculate the percentage before actually inserting the paid value. Here's my updated code: $xploded = explode('_', $this->input->post('custom')); $paypal_array = array( 'userid' => $xploded[0], //database user id 'amount' => $this->input->post('mc_gross'), 'type' => $xploded[1], // table name 'pid' => $xploded[2], // problem id in that table 'created' => $this->input->post('payment_date'), 'fname' => $this->input->post('first_name'), 'lname' => $this->input->post('last_name'), 'country' => $this->input->post('address_country'), 'payer_id' => $this->input->post('payer_id'), 'verify_sign' => $this->input->post('verify_sign'), 'txn_id' => $this->input->post('txn_id'), 'item_name' => $this->input->post('item_name') ); $curpaid = $this->endaproblem->get_cur_paid($xploded[1], $xploded[2]); $curamount = $this->input->post('mc_gross') + $curpaid->paid; $update_paid = array( 'paid' => $curamount, 'percent' => $curamount / $curpaid->cost ); //$update_percent = array('percent' => $curpaid->paid / $curpaid->cost); $this->endaproblem->add('donations', $paypal_array); $this->endaproblem->update($xploded[1], $xploded[2], $update_paid); Quote Link to comment https://forums.phpfreaks.com/topic/258218-how-should-i-do-this/#findComment-1323776 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.