Balanced-Payments尝试Catch响应

时间:2015-01-04 18:15:55

标签: try-catch balanced-payments

我试图了解如何设置信用卡付款和使用平衡付款测试市场。我以前从未设置过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();
            }
        });

成功处理测试卡后,一切正常,我的视图中会显示成功消息。但是,当我使用被拒绝的测试卡时,没有消息发送到我的视图。有谁看到我做错了什么?

1 个答案:

答案 0 :(得分:2)

尝试检查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-declinedauthorization-failedcard-declined