How to notify members of new invoices by email

Fabman can make it easy for you to bill your members. Charges and invoices are generated automatically and can also be debited directly from your members’ credit card if required.

With this little PHP script you can automatically inform your members via email as soon as a new invoice has been created. It is called via a webhook:

<?php

	// Add a webhook for Invoice events in Fabman
	// Call the webhook like this:
	// https://yourserver.com/InvoiceNotification.php?secret=jeKEGHx34kjDFab

	$token = "jeKEGHx34kjDFab";
	if ($_GET['secret'] != $token) {
		print "Webhook not executed due to wrong token (url?secret=token)";
		exit;
	}

	$obj = json_decode(file_get_contents("php://input"));	
	//var_dump($obj);

	$url = "https://fabman.io/members/".$obj->{'details'}->{'member'}->{'account'}."/billing/invoices/".$obj->{'details'}->{'invoice'}->{'id'};

	$email_to = $obj->{'details'}->{'member'}->{'emailAddress'};
	$subject = "New Fabman invoice available";
	$content = "Download invoice here: ".$url;
	$email_from = "sender@yourdomain.com"; // set your sender email address!
	mail($email_to, $subject, $content, $email_from);
	
?>

Log in to Fabman, go to “Configure / Integrations & API” and add a new Webhook:

Further technical details on Fabman webhooks can be found here: https://github.com/FabmanHQ/fabman-api/blob/master/sections/webhooks.md

1 Like