AutoBill.modify call to change Products on an AutoBill, replacing an existing Product with a new Product, to which a Campaign discount has been applied.
$abill = new AutoBill();
$abill->setMerchantAutoBillId('vin_test_abill1391561675069');
// This is ID of the AutoBill you want to modify.
$productRemoved = new Product(); // Product we want to remove.
$productRemoved->setMerchantProductId('regular-avataxed-product');
// Identify the Product by its ID. There is no need to fetch it.
$itemRemoved = new AutoBillItem();
$itemRemoved->setProduct($productRemoved);
$productAdded = new Product(); // Product we want to add.
$productAdded->setMerchantProductId('avataxed-ott-product');
// Identify the Product by its ID. There is no need to fetch it.
$itemAdded = new AutoBillItem();
$itemAdded->setProduct($productAdded);
$itemAdded->setMerchantAutoBillItemId('item-987654'); // Unique item ID.
$itemAdded->setCampaignCode('OTT');
// To apply a promo to the Product being added.
$modification = new AutoBillItemModification();
$modification->setRemoveAutoBillItem($itemRemoved);
$modification->setAddAutoBillItem($itemAdded);
$modifications = [ $modification ];
$abmr = abill.modify(
true, // bill prorated period
'today', // make the change effective today
null, // not changing the billing plan
$modifications,
false // no dry run
);
if ($abmr->getReturnCode == 200) {
// We got a 200 response code back
// The modification may result a net refund or net charge
// to the customer.
$refunds = $abmr->getRefunds();
$tx = $abmr->getTransaction();
if ($refunds != null && $refunds->length > 0 ) {
// Modification resulted into net refund
// In most cases there should be only one refund
$the_refund = $refunds[0];
print('Total refund amount due to modification: '
. $refunds[0]->getAmount()
. ' . See break down below: ');
// To give the customer a break down of how we reached
// the refund amount, we must parse the $0 transaction
// that accompanies this.
if ($tx != null ) {
printTxDetails($tx);
}
}
else {
// Refund is null, so there must be net cost to the customer
if ($tx != null ) {
print('Total charge processed during modification: $'
. $tx->getAmount()
. ' - see break down below:');
printTxDetails($tx);
}
}
}

