2016-12-30 61 views
0

我使用Laravel Cashier进行身份验证注册,并使用try catch块来处理它。Laravel - 用户注册加试试catch块中的条纹支付

try { 
    // Process the credit card through Stripe 
    // Register the user in the system 
} catch (\Exception $e) { 
    // Throw exception with error message 
} 

这工作得很好,但我想知道是否该卡的处理工作会发生什么,但登记失败。

他们会收取费用,并没有帐户。

如果发生某些事情失败,您将如何采取逆转措施?

+0

你就不能注册帐户处于禁用状态,使后来在付款的时候是我们可以还原这个成功?如果没有再次注册,那么它们是否会让他们更容易重试付款?对我而言,注册似乎是您控制的事情,因此验证等应在开始付款流程之前完成。 – Robert

+0

首先,如果付款成功将其更新为活动状态,那么首先必须注册处于非活动状态的用户 – DsRaj

回答

1

您应该使用不同模式的try/catch为每个进程:

try { 
    // Process the credit card through Stripe 
} catch (\Exception $e) { 
    // Throw exception with error message 
} 

,第二个寄存器:

try { 
    // Register the user in the system 
} catch (\Exception $e) { 
    // Throw exception with error message 
} 

你确切地知道失败这种方式。

+0

嘿,感谢您的回答,但即使在这种情况下,如果分条过程成功,然后注册失败,它仍然会处理卡并不签署用户,不会吗? – BigJobbies

+0

您可以添加状态,例如:'预注册','未付款','付款','注册'等,并在每次完成一个步骤时更改它们。 – Peon

0

你应该尝试先注册过程,因为它在我们的手,如果任何事情出错

try { 
    // Register the user in the system 
    // Process the credit card through Stripe 
    // If process fails throw custom exception 
}catch(CustomException $e) { 
    //revert the Register process 
    //Throw exception 
} catch (\Exception $e) { 
    // Throw exception with error message 
}