$response = "";
$status = "";
if ($rule1 && $rule2) {
    if (strtoupper($request['mode']) != 'LIVE') {
        $response = "TSOK";
    } else {
        $class_payone = new payone();
        $payi = new payone_invoice('payone_txid', $payone_txid);
        $response = "TSOK";
        $set_order_as_paid = false;
        switch ($txaction) {
            case 'appointed':
                $payi->confirmAppointed();
                break;
            case 'capture':
                $payi->confirmCaptured();
                if ($request['balance'] <= 0) {
                    if ($request['balance'] == 0) {
                        if ($payi->detail['invoice_complete_status'] == 'F') {
                            //set as refund processed for refund
                            $status = 'D';
                        } elseif ($payi->detail['invoice_complete_status'] == 'A') {
                            //if user not paid yet then returned all products, set as invoice cancelled
                            $status = '3';
                        } else {
                            //set as paid for non-refund
                            $status = 'P';
                        }
                        if ($payi->getBalance() < 0) {
                            /* If refund was processed on captured while invoice_amount_paid > invoice_amount
                             * (means we not prepared return container for this),