【问题标题】:Balanced-Payments Try Catch responseBalanced-Payments Try Catch 响应
【发布时间】: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


    【解决方案1】:

    尝试检查 balance-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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-22
      • 1970-01-01
      • 2017-05-01
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      • 2020-03-13
      相关资源
      最近更新 更多