【问题标题】:The delivery of emails when a subscription payment fails using stripe使用条带订阅付款失败时发送电子邮件
【发布时间】:2014-08-03 22:23:34
【问题描述】:

我正在完成设置 Stripe 以在网站上上线,但是看到用户将要订阅,我想保护自己免受在订阅期间(即第一次付款后的任何时间)被拒绝的卡和通知他们。在 Stripe 网站上没有关于这个错误处理的深入讨论,所以我想知道当卡在订阅期间拒绝时是否会执行以下操作,因为我不知道有什么方法可以用 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, "\n");
    mail($to, $subject, $message);
}

我只是不确定这是否会发送,如果不是,我应该添加什么才能发送。非常感谢。

【问题讨论】:

    标签: php stripe-payments subscription


    【解决方案1】:

    订阅一旦创建就完全由 Stripe 处理,所以不,您在编写代码时永远不会收到Stripe_CardError。您的应用程序不会重新计费;条纹可以。

    然而,Stripe 提供an extensive webhook implementation 正是为了这种目的。如果您不熟悉 webhooks,它们是异步 API 事件问题的简单解决方案:当事件发生时,第三方服务会将事件通知 POST 回您定义的端点。

    通过为您感兴趣的 Stripe webhook 实现响应器(例如,invoice.payment_failed 用于失败的发票支付),您可以在应用程序中做任何您想做的事情。向用户发送电子邮件,向自己发送不同的电子邮件,设置标志以便用户在登录时看到横幅......可能性是无限的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 2019-12-08
      • 2012-03-04
      • 2022-01-19
      • 2014-01-26
      相关资源
      最近更新 更多