2014-06-13 40 views
0

我正在完成将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); 
} 

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

回答

2

订阅完全由Stripe创建,因此不会,因为您已经编写了代码,所以不会收到Stripe_CardError。您的申请不会重新填写;条纹呢。

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

通过实施您感兴趣的Stripe webhooks的响应者 - 例如,发票付款失败的invoice.payment_failed - 您可以在应用程序内执行任何操作。发送电子邮件给用户,发送不同的电子邮件给自己,设置一个标志,以便用户在登录时看到横幅。这种可能性是无限的。