-
-
Save NeilVicente/60207f66cd4f3fc29e16 to your computer and use it in GitHub Desktop.
Sends email when a Stripe subscription payment fails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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