function testWebhookSerializing() { $event = ChargeBee_Event::deserialize(ChargeBee_SampleData::webhookData()); $content = $event->content(); $this->assertNotEqual($content->customer(), null); $this->assertNotEqual($content->subscription(), null); $this->assertNotEqual($content->card(), null); $this->assertNotEqual($content->invoice(), null); }
/* * Demo on how to add charge for meter billing customer after * receiving Invoice Created event through webhook. */ if (isset($_POST)) { /* * Getting the json content from the request. */ 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"; } }