Jump to content

How should I do this?


Samuz

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.