【问题标题】:Square payment PHP SDK returns null方支付PHP SDK返回null
【发布时间】:2020-01-19 07:23:46
【问题描述】:

我正在使用Square Payment PHP SDK付款
1. 从移动应用程序生成nonce,然后发送到我的服务器以创建付款请求。
2. 我的服务器正确接收了nonce,尽管在我运行$payments_api->createPayment($body); 之后我得到了null 异常。
这是我的代码:

        $access_token = 'MY_ACCESSS_TOKEN';
        $location_id = 'LOCATION_ID';
        $params = Yii::$app->request->post();
        $nonce = $params['nonce'];//received from post request
        # setup authorization
        $api_config = new \SquareConnect\Configuration();
        $api_config->setHost("https://connect.squareupsandbox.com");
        $api_config->setAccessToken($access_token);
        $api_client = new \SquareConnect\ApiClient($api_config);
        # create an instance of the Location API
        $locations_api = new \SquareConnect\Api\LocationsApi($api_client);

        $payments_api = new \SquareConnect\Api\PaymentsApi($api_client);
        //$payments_api = new \SquareConnect\Api\TransactionsApi($api_client);

        $body = new \SquareConnect\Model\CreatePaymentRequest();
        $amountMoney = new \SquareConnect\Model\Money();
        $amountMoney->setAmount(100);
        $amountMoney->setCurrency("USD");

        $body->setSourceId($nonce);
        $body->setAmountMoney($amountMoney);
        $body->setLocationId($location_id);

        $body->setIdempotencyKey(uniqid());

        try {
            $result = $payments_api->createPayment($body);

            $payment_data = $result->getPayment();
           return $result;
        } catch (\SquareConnect\ApiException $e) {
           //returns null
            return $e->getResponseBody();
        }

【问题讨论】:

    标签: php android square-connect


    【解决方案1】:

    故障排除后,我在发出 curl 请求时发现了错误 error setting certificate verify locations: CAfile:
    我通过以下方式解决了它:
    1.下载cacert.pem
    2.复制粘贴cacert.pem重命名为curl-ca-bundle.crt
    3. 将 php.ini 文件 curl 修改为 curl.cainfo="xammp path\apache\bin\curl-ca-bundle.crt
    注意我正在使用自签名 ssl 处理本地 xammp。

    【讨论】:

      猜你喜欢
      • 2015-04-14
      • 1970-01-01
      • 2019-02-09
      • 2015-11-17
      • 2021-02-27
      • 1970-01-01
      • 2015-10-21
      • 2016-01-20
      • 2014-11-27
      相关资源
      最近更新 更多