require_once 'Vindicia/Soap/Vindicia.php';
require_once 'Vindicia/Soap/Const.php';
// This example uses an existing Account
$accountID = $argv[1];
print "accountID is {$accountID} \n";
$account = new Account();
$account->setMerchantAccountId($accountID);
// must be an existing Product
$productID = $argv[2];
print "productID is {$productID} \n";
$product = new Product();
$product->setMerchantProductId($productID);
// AutoBills may have multiple products (AutoBill Items)
$item = new AutoBillItem();
// You can apply a Campaign Code to the product here:
$item->setCampaignCode('1MonthBonusPromo');
// set the Product in the AutoBillItem
$item->setProduct($product);
// must be an existing BillingPlan
$billingplanID = $argv[3];
print "billingplanID is {$billingplanID} \n";
$billingplan = new BillingPlan();
$billingplan->setMerchantBillingPlanId($billingplanID);
// Create a random ID for our testing - This should be much more unique in a production env.
$autobillID = 'ab-random' . rand(1000, 9999999);
print "autobillID is {$autobillID} \n";
$autobill = new AutoBill();
$autobill->setItems(array($item));
$autobill->setAccount($account);
$autobill->setBillingPlan($billingplan);
$autobill->setMerchantAutoBillId($autobillID);
require_once 'Vindicia/Soap/Vindicia.php';
require_once 'Vindicia/Soap/Const.php';
$abID = $argv[1];
$remID = $argv[2];
$addID = $argv[3];
$effectiveDate = $argv[4];
$prorate = $argv[5];
$dryrun = $argv[6];
$changeBillingPlanTo = NULL;
print "Replacing product {$remID} with product {$addID} on autobill {$abID} \n";
print "dryrun is {$dryrun} \n";
$autobill = new AutoBill();
$return = $autobill->fetchByMerchantAutoBillId($abID);
$autobillVID = $return['data']->autobill->VID;
print "VID is {$autobillVID} \n";
$modAutoBill = new AutoBill();
$modAutoBill->setVID($autobillVID);
$remProduct = new Product();
$remProduct->setMerchantProductId($remID);
$remItem = new AutoBillItem();
$remItem->setProduct($remProduct);
$addProduct = new Product();
$addProduct->setMerchantProductId($addID);
$addItem = new AutoBillItem();
$addItem->setProduct($addProduct);
$addItem->setCampaignCode('promo10');
$replaceModification = new AutoBillItemModification();
$replaceModification->setRemoveAutoBillItem($remItem);
$replaceModification->setAddAutoBillItem($addItem);
$response = $modAutoBill->modify($prorate, $effectiveDate, $changeBillingPlanTo, $replaceModification, $dryrun);
print_r($response);