/
PHP SDK Sample: Item Payment Method Restriction

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();
}

?>

Related content

PHP SDK Sample: Download specific order and extract fields
PHP SDK Sample: Download specific order and extract fields
More like this
Configure PayPal Express Checkout or PayPal Pro in UltraCart
Configure PayPal Express Checkout or PayPal Pro in UltraCart
More like this
PHP SDK Sample: Add Item to Cart (Checkout)
PHP SDK Sample: Add Item to Cart (Checkout)
More like this
PHP SDK Sample: Add item to order
PHP SDK Sample: Add item to order
More like this
PHP SDK Example: Query Auto Order for Customer Profile and Update Credit Card Information
PHP SDK Example: Query Auto Order for Customer Profile and Update Credit Card Information
More like this
PHP SDK Sample: Edit Auto Order
PHP SDK Sample: Edit Auto Order
More like this