使用条带订阅付款失败时发送电子邮件

I am finishing up getting Stripe set up to go live on a website, however seeing as users are going to be subscribing I want to protect myself from cards being declined during the subscription period (i.e. anytime after the first payment) and be notified when they are. There isn't much in depth discussion on this error handling on the Stripe site so I would just like to know if the following would execute when the card declines during the subscription seeing as I don't know of any way to test this with Stripe.

try 
{
    // Try to charge the customers card here, subscription

}   


//In the event of a card error 
catch (Stripe_CardError $e) 
{

    // Card was declined.
    $e_json = $e->getJsonBody();
    $error = $e_json['error'];

    print ($error['message']);

    //Send the email to notify both parties that the payment declined.

    $to = $_POST['email'];
    $subject = 'Your card ending in'.['last4'].'has declined';
    $message = 'Please remedy the situtaion at your earliest convience, there will be another attempt to charge your card in three days';
    wordwrap($message, $width=75, "
");
    mail($to, $subject, $message);
}

I'm just unsure as to whether or not this would send and if not what should I add to get it to send. Thanks very much.

Subscriptions are handled entirely by Stripe once they're created, so no, you'll never catch a Stripe_CardError as you've written your code. Your application doesn't rebill; Stripe does.

However, Stripe provides an extensive webhook implementation for exactly this sort of purpose. If you're not familiar with webhooks, they're a simple solution to the problem of asynchronous API events: When an event occurs, the third-party service POSTs an event notification back to an endpoint you've defined.

By implementing a responder for the Stripe webhooks you're interested in—for example, invoice.payment_failed for a failed invoice payment—you can do whatever you want within your application. Send an email to the user, send a different email to yourself, set a flag so the user sees a banner whenever they log in... The possibilities are limitless.