<?php

require_once __DIR__ . '/../RemoteService.php';
try {
    $service = new RemoteService();
    if (!isset($argv[1])) {
        die("Please provide an Order ID\n");
    }
    $orderId = $argv[1];
    $filters = array('filter' => array(array('key' => 'order_id', 'value' => $orderId)));
    // Get a sales order list by the applied filters
    $result = $service->salesOrderInvoiceList(array('filters' => $filters));
    print_r($result);
} catch (SoapFault $e) {
    echo "Exception '" . get_class($e) . "':\n";
    print_r($e);
}
<?php

require_once __DIR__ . '/../RemoteService.php';
if (!isset($argv[1])) {
    die('Please provide order increment ID' . PHP_EOL);
}
$orderIncrementId = $argv[1];
try {
    $service = new RemoteService();
    $order = $service->salesOrderInfo(array('orderIncrementId' => $orderIncrementId));
    $invoice = $service->salesOrderInvoiceList(['filters' => ['filter' => [['key' => 'order_id', 'value' => $order->result->order_id]]]]);
    $invoiceIncrementId = $invoice->result->complexObjectArray->increment_id;
    $items = array();
    foreach ($order->result->items->complexObjectArray as $item) {
        echo "[{$item->sku}] {$item->name} £{$item->row_invoiced} - ";
        $qty = (int) $service->ask("Qty to Refund [{$item->qty_invoiced}]", 'text', $item->qty_invoiced);
        if ($qty > $item->qty_invoiced || $qty < 0) {
            die('Invalid Quantity' . PHP_EOL);
        }
        if ($qty >= 0) {
            $cmItem = new stdClass();
            $cmItem->order_item_id = $item->item_id;
            $cmItem->qty = $qty;
            $items[] = $cmItem;
            $rrItem = new stdClass();
            $rrItem->order_item_id = $item->item_id;
            $rrItem->return_code = 1;
            $rrs[] = $rrItem;
        }
    }
    if (empty($items)) {