function closePendingInvoice($invoiceObj) { $invoiceId = $invoiceObj->id; $subscriptionId = $invoiceObj->subscriptionId; $startDate = $invoiceObj->startDate; $endDate = $invoiceObj->endDate; $chargeInCents = MeterBilling::getUsageCharge($startDate, $endDate, $subscriptionId); $addChargeParam = array("amount" => $chargeInCents, "description" => "monthly usage"); /* * Calling ChargeBee Add Charge Invoice API and add Charge to invoice * based on the usage made by customer. */ ChargeBee_Invoice::addCharge($invoiceId, $addChargeParam); $addonQuantity = MeterBilling::getQuantityUsed($startDate, $endDate, $subscriptionId); $addAddonCharge = array("addonId" => "wallpapers", "addonQuantity" => $addonQuantity); /* * Calling the ChargeBee Add Addon Charge Invoice API and add the no of * addons used by customers to the invoice. */ ChargeBee_Invoice::addAddonCharge($invoiceId, $addAddonCharge); /* * Closing the invoice and Collecting the payment(if auto collection is on) * by calling the ChargeBee Collect Invoice API. */ ChargeBee_Invoice::collect($invoiceId); }