Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/258218-how-should-i-do-this/
Share on other sites

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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.