PHP SDK Sample: Cancel Auto Order

The following example will query an auto order, change the object to cancel it, and then perform the update.

<?php

require_once __DIR__ . '/vendor/autoload.php';

// Configure API key authorization: ultraCartSimpleApiKey
ultracart\v2\Configuration::getDefaultConfiguration()->setApiKey('x-ultracart-simple-key', 'YOUR API KEY HERE');

// Disable SSL verification if we're having issues with this PHP install not having the proper CA installed.  Fix your CA for a production environment!
// Set debug to true if you need more information on request/response
$client = new GuzzleHttp\Client(['verify' => false, 'debug' => false]);

$api_instance = new ultracart\v2\api\AutoOrderApi(
    $client,
    ultracart\v2\Configuration::getDefaultConfiguration(),
    new ultracart\v2\HeaderSelector("2016-10-01")
);

try {
    $auto_order_response = $api_instance->getAutoOrderByReferenceOrderId("DEMO-201230980", null);

    if ($auto_order_response->getSuccess()) {
        $auto_order = $auto_order_response->getAutoOrder();

        $auto_order->setEnabled(false);
        $auto_order->setCanceledDts(gmdate("c"));
        $auto_order->setCanceledByUser("customer"); // or the user's name

        $update_auto_order_response = $api_instance->updateAutoOrder($auto_order, $auto_order->getAutoOrderOid());

        if ($update_auto_order_response->getSuccess()) {
            echo "Successful cancel of auto order: " . $auto_order->getOriginalOrderId();
        } else {
            echo "Failed to cancel of auto order";
            var_dump($update_auto_order_response);
        }
    } else {
        echo "Failed to query of auto order";
        var_dump($auto_order_response);
    }
} catch (Exception $e) {
    echo 'Exception when calling AutoOrderApi->getAutoOrderByReferenceOrderId: ', $e->getMessage(), PHP_EOL;
}

?>