方形付款PHP SDK返回null

问题描述 投票:0回答:1

我正在使用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个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.