Balanced-Payments Try Catch 响应
Balanced-Payments Try Catch response
我一直在尝试学习如何设置信用卡支付以及如何使用平衡支付测试市场。我以前从未设置过 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();
}
});
成功处理测试卡后,一切正常,成功消息出现在我的视图中。但是,当我使用被拒绝的测试卡时,没有消息发送到我的视图。有人看到我做错了什么吗?
尝试检查 balanced-php 客户端测试套件,看看他们如何使用来自 here
的 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->category_code;
return Response::json($this->arrResponse);
}
$invoice->save();
// send email function...
//redirect
$this->arrResponse['status'] = SUCCESS;
return Response::json($this->arrResponse);
$e->category_code
将是 funding-destination-declined
或 authorization-failed
或 card-declined
我一直在尝试学习如何设置信用卡支付以及如何使用平衡支付测试市场。我以前从未设置过 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();
}
});
成功处理测试卡后,一切正常,成功消息出现在我的视图中。但是,当我使用被拒绝的测试卡时,没有消息发送到我的视图。有人看到我做错了什么吗?
尝试检查 balanced-php 客户端测试套件,看看他们如何使用来自 here
的 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->category_code;
return Response::json($this->arrResponse);
}
$invoice->save();
// send email function...
//redirect
$this->arrResponse['status'] = SUCCESS;
return Response::json($this->arrResponse);
$e->category_code
将是 funding-destination-declined
或 authorization-failed
或 card-declined