AutoBill.modify call to change both the Products and the Billing Plan for an AutoBill simultaneously.
$abill = new AutoBill();
$abill->setMerchantAutoBillId('vin_test_abill1391560836975');
// This is ID of the AutoBill you want to modify.
$productRemoved = new Product(); // Product we want to remove.
$productRemoved->setMerchantProductId('monthlySub');
// Simply identify the Product by its ID. No need to fetch it.
$itemRemoved = new AutoBillItem();
$itemRemoved->setProduct($productRemoved);
$productAdded = new Product(); // Product we want to add
$productAdded->setMerchantProductId('AnnualSubProduct');
// Simply identify the Product by its ID. No need to fetch it.
$itemAdded = new AutoBillItem();
$itemAdded->setProduct($productAdded);
$itemAdded->setMerchantAutoBillItemId('item-425304'); // Unique item ID.
$itemAdded->setCampaignCode('ANNUALPROMO');
// To apply a Promo to the Product being added.
$modification = new AutoBillItemModification();
$modification->setRemoveAutoBillItem($itemRemoved);
$modification->setAddAutoBillItem($itemAdded);
// We want to change to the annual plan.
$newPlan = new BillingPlan();
$newPlan->setMerchantBillingPlanId('annual-plan-2');
$modifications = [ $modification ];
$abmr = abill.modify(
true, // Bill prorated period.
'today', // Make the change effective today.
$newPlan, // 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: ');
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);
}
}
}

