首页 > 解决方案 > 方支付PHP SDK返回null

问题描述

我正在使用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();
        }

标签: phpandroidsquare-connect

解决方案


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


推荐阅读