douyoupingji7238 2014-06-13 11:11
浏览 55
已采纳

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

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.

  • 写回答

1条回答 默认 最新

  • douyi2798 2014-06-13 15:43
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我的数据无法存进链表里
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端