Пример #1
0
     */
    if (!checkIfRequestIsFromChargeBee()) {
        return;
    }
    $content = file_get_contents('php://input');
    /* 
     * Assigning the recieved content to ChargeBee Event object.
     */
    $event = ChargeBee_Event::deserialize($content);
    /*
     * Checking the event type as Invoice Created to add Charge for Meter Billing.
     */
    $eventType = $event->eventType;
    if ($eventType == "invoice_created") {
        $invoiceId = $event->content()->invoice()->id;
        $invoiceObj = ChargeBee_Invoice::retrieve($invoiceId)->invoice();
        if ($invoiceObj->status == "pending") {
            $meterBilling = new MeterBilling();
            $meterBilling->closePendingInvoice($invoiceObj);
            echo "Invoice has been closed successfully";
        } else {
            echo "Invoice is not in pending state";
        }
    }
}
/* Check if the request is from chargebee. 
 * You can secure the webhook either using
 *   - Basic Authentication
 *   - Or check for specific value in a parameter.
 * For demo purpose we are using the second option though 
 * basic auth is strongly preferred. Also store the key 
function invoiceAsPdf()
{
    $invoiceId = $_GET['invoice_id'];
    $invoice = ChargeBee_Invoice::retrieve($invoiceId)->invoice();
    if ($invoice->subscriptionId != getSubscriptionId()) {
        header("HTTP/1.0 400 Error");
        include $_SERVER["DOCUMENT_ROOT"] . "/error_pages/400.html";
        return;
    }
    $result = ChargeBee_Invoice::pdf($invoiceId);
    header("Location: " . $result->download()->downloadUrl);
}