PHP SDK Sample: Item Payment Method Restriction

This tutorial queries an item and restricts the payment method of PayPal.

<?php

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

// 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]);

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

$api_instance = new ultracart\v2\api\ItemApi(
    $client,
    $config,
    new ultracart\v2\HeaderSelector("2016-10-01")
);

$_expand = "payment_processing";
$get_item_response =  $api_instance->getItemByMerchantItemId("sample", $_expand, false);

if ($get_item_response->getSuccess()) {
    // Grab the item
    $item = $get_item_response->getItem();

    // Init the payment processing object if it doesn't exist
    if ($item->getPaymentProcessing() == null) {
        $item->setPaymentProcessing(new ultracart\v2\models\ItemPaymentProcessing());
    }

    // Init the payment method validity array if it's null
    if ($item->getPaymentProcessing()->getPaymentMethodValidity() == null) {
        $item->getPaymentProcessing()->setPaymentMethodValidity(array());
    }

    $paymentMethodValidity = $item->getPaymentProcessing()->getPaymentMethodValidity();
    if (!in_array("-PayPal", $paymentMethodValidity)) {
        array_push($paymentMethodValidity, "-PayPal");
        $item->getPaymentProcessing()->setPaymentMethodValidity($paymentMethodValidity);

        $api_instance->updateItem($item, $item->getMerchantItemOid(), $_expand, false);
        echo "Added restriction to item.";
    } else {
        echo "Item already restricted";
    }
} else {
    echo "Failed to get item " . $get_item_response->getError();
}

?>