//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),
                  * after we received captured from payone: balance = 0, getBalance < 0
                  * so we need to save the difference as overPaymentAmount
                  */
                 $payi->overPaymentAmount($payi->getBalance());
             } elseif ($payi->getBalance() > 0) {
                 /* If there any adjusted to closed small amount on capture,
                  * after received captured from payone: balance = 0, getBalance > 0
                  * so we need to save the difference as reduceAmount
                  */
                 $payi->reduceAmount($payi->getBalance());
             }
         } else {
             $status = 'O';
         }
         $payi->updateCompleteStatus($status);
     }
     $payi->payoneSaldo($request['balance']);
     break;
 case 'paid':
 case 'underpaid':
     $prev_balance = $payi->getBalance();
     if ($request['clearingtype'] == 'vor') {
         //if paid/underpaid, payone returns negative balance and balance = total_amount_has_paid_by_user
         $request['balance'] = $payi->detail['invoice_amount'] + $request['balance'];
     }
             $class_plog->add('S', $process_time, $process_method, $request, $response);
             if (is_array($response)) {
                 if ($response['status'] == 'APPROVED') {
                     $class_pi->saveUsedSequenceNumber($nextsequencenumber);
                     if ($invoice_complete_status == 'A') {
                         $successA[] = $invoice_id;
                     } else {
                         $successU[] = $invoice_id;
                     }
                     $return_hist['status'] = 1;
                     $return_hist['submitted_date'] = $process_time;
                     $class_payone->payoneReturnItemHistory($return_hist);
                     /* We still need to do reduceAmount and finesCanceledAmount here,
                      * this needed to exactly know its caused by the closed small payment process.
                      */
                     $class_pi->reduceAmount(($amount_small_returned - $amount_fines) / 100);
                     $class_pi->finesCanceledAmount(($amount_fines - $amount_fines_canceled) / 100);
                 } else {
                     if ($invoice_complete_status == 'A') {
                         $failedA[] = $invoice_id;
                     } else {
                         $failedU[] = $invoice_id;
                     }
                 }
             }
         }
     } else {
         $counter_returns_no_txid++;
     }
 }
 echo "\nTotal Small Amount Return : {$counter_small_amount} \n";