Give_Payment::update_status PHP Method

update_status() public method

Set the payment status and run any status specific changes necessary.
Since: 1.0
public update_status ( string $status = false ) : boolean
$status string The status to set the payment to.
return boolean $updated Returns if the status was successfully updated.
    public function update_status($status = false)
    {
        //standardize the 'complete(d)' status
        if ($status == 'completed' || $status == 'complete') {
            $status = 'publish';
        }
        $old_status = !empty($this->old_status) ? $this->old_status : false;
        if ($old_status === $status) {
            return false;
            // Don't permit status changes that aren't changes
        }
        $do_change = apply_filters('give_should_update_payment_status', true, $this->ID, $status, $old_status);
        $updated = false;
        if ($do_change) {
            do_action('give_before_payment_status_change', $this->ID, $status, $old_status);
            $update_fields = array('ID' => $this->ID, 'post_status' => $status, 'edit_date' => current_time('mysql'));
            $updated = wp_update_post(apply_filters('give_update_payment_status_fields', $update_fields));
            $all_payment_statuses = give_get_payment_statuses();
            $this->status_nicename = array_key_exists($status, $all_payment_statuses) ? $all_payment_statuses[$status] : ucfirst($status);
            // Process any specific status functions
            switch ($status) {
                case 'refunded':
                    $this->process_refund();
                    break;
                case 'failed':
                    $this->process_failure();
                    break;
                case 'pending':
                    $this->process_pending();
                    break;
                case 'cancelled':
                    $this->process_cancelled();
                    break;
                case 'revoked':
                    $this->process_revoked();
                    break;
            }
            do_action('give_update_payment_status', $this->ID, $status, $old_status);
        }
        return $updated;
    }

Usage Example

コード例 #1
0
 /**
  * Test Payment Status Update
  */
 public function test_payment_status_update()
 {
     $payment = new Give_Payment($this->_payment_id);
     $payment->update_status('pending');
     $this->assertEquals('pending', $payment->status);
     $this->assertEquals('Pending', $payment->status_nicename);
     // Test backwards compatibility
     give_update_payment_status($this->_payment_id, 'publish');
     // Need to get the payment again since it's been updated
     $payment = new Give_Payment($this->_payment_id);
     $this->assertEquals('publish', $payment->status);
     $this->assertEquals('Complete', $payment->status_nicename);
 }