Skip to content

Instantly share code, notes, and snippets.

@NeilVicente
Last active October 31, 2015 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NeilVicente/60207f66cd4f3fc29e16 to your computer and use it in GitHub Desktop.
Save NeilVicente/60207f66cd4f3fc29e16 to your computer and use it in GitHub Desktop.
Sends email when a Stripe subscription payment fails
<?php
if (!isset($_POST)) {
die("Request cannot be empty.");
}
$input = @file_get_contents("php://input");
$event_json = json_decode($input, 1);
$data = $event_json["data"]["object"];
if ($event_json['type'] == "invoice.payment_failed") {
$amount_due = strtoupper($data["currency"]) . " " . $data["amount_due"];
$customer_id = $data["customer"];
$subject = "Subscription payment failed";
$to = "email@domain.com"; // replace with your email;
$message = "<p style='font-size: 1em'> Subscription payment ($amount_due) for customer $customer_id has failed.<p>";
mail($to, $subject, $message, "Content-Type: text/html; charset=\"UTF-8\"\r\n");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment