【发布时间】:2015-01-04 18:15:54
【问题描述】:
我正在尝试学习如何设置信用卡支付和使用平衡支付测试市场。我以前从未设置过 try catch 语句,并且在处理响应时遇到了一些麻烦。
这是我的控制器 try/catch 语句:
try{
$card->debits->create(array(
"amount" => $amount,
"appears_on_statement_as" => "test",
"description" => $invoiceId,
"order" => $order,
));
} catch (Balanced\Errors\Declined $e) {
$this->arrResponse['status'] = $e->getMessage();
return Response::json($this->arrResponse);
}
$invoice->save();
// send email function...
//redirect
$this->arrResponse['status'] = SUCCESS;
return Response::json($this->arrResponse);
我可以在 chrome 开发者工具上看到错误,但我无法让它出现在我的视图中。
Chrome 开发工具 500 内部服务器错误声明:
error: {type: "Balanced\Errors\Declined", message: "",…}
file: "/Applications/MAMP/htdocs/testcc/vendor/balanced/balanced/src/Balanced/Errors/Error.php"
line: 42
message: ""
type: "Balanced\Errors\Declined
processpayment.js 文件:
jQuery.post(baseURL+'/processPayment', {
uri: fundingInstrument.href,
amount: amount,
invoiceId: invoiceId,
}, function(r) {
// backend response
if (r.status === 200) {
$('#msgSection').empty().removeClass('alert-error alert-success').addClass('alert-success').text(' payment has been received').show();
} else {
// failure from backend
$('#msgSection').empty().removeClass('alert-success').addClass('alert-warning').text('error').show();
}
});
成功处理测试卡后,一切正常,成功消息出现在我的视图中。但是,当我使用被拒绝的测试卡时,不会向我的视图发送任何消息。有人看到我做错了吗?
【问题讨论】:
标签: try-catch balanced-payments