Square API-无效字符'C'寻找值的开始

时间:2018-06-27 06:01:34

标签: php square square-connect

我正在使用Square Charge API,以下是我对测试卡的请求对象-

enter image description here

我正在使用Square提供的PHP客户端连接到API。我收到以下有关“充电”端点的响应-

[HTTP/1.1 400 Bad Request] {"errors":[{"category":"INVALID_REQUEST_ERROR","code":"BAD_REQUEST","detail":"invalid character 'C' looking for beginning of value (line 1, character 1)"}]}

以下是我在PHP中的代码-

public function chargeCustomerCard($userId, $custId, $cardId, $note, $billingAddres, $amount, $idempotencyKey){
        $billingAddrRequest = array("address_line_1" => $billingAddres->addr1, "address_line_2" => $billingAddres->addr2, "locality" => $billingAddres->city, "administrative_district_level_1" => $billingAddres->state, "postal_code" => $billingAddres->zip, "country" => $billingAddres->country);
        $billingAddressReq = new \SquareConnect\Model\Address($billingAddrRequest);
        $moneyRequest = array("amount" => $amount, "currency" => "USD");
        $money = new \SquareConnect\Model\Money($moneyRequest);
        $request = array("idempotency_key" => $idempotencyKey, "customer_id" => $custId, "customer_card_id" => $cardId, "delay_capture" => false, "amount_money" => $money, "billing_address" => $billingAddressReq, "note" => $note, "reference_id" => $userId);
        $charge = new \SquareConnect\Model\ChargeRequest($request);
        $response = null;

        try{
            $charge_api = new \SquareConnect\Api\TransactionsApi();
            $response = $charge_api->charge($this->authtoken, $this->locationId, $charge);
            if($response != null && count($response->getErrors()) == 0){
                $transaction = $response->getTransaction();
                $data = array();
                $data['transactionId'] = $transaction->getId();
                $data['created'] = $transaction->getCreatedAt();
                $data['referenceId'] = $transaction->getReferenceId();  //this should be equal to userid
                $tender = $transaction->getTenders()[0];    
                $data['tenderId'] = $tender->getId();
                $data['note'] = $tender->getNote();
                $data['amount'] = ($tender->getAmountMoney()->getAmount())/100;
                $data['currency'] = $tender->getAmountMoney()->getCurrency();
                $processingFee = $tender->getProcessingFeeMoney();
                if(isset($processingFee) && !empty($processingFee)){
                    $data['processingFee'] = $tender->getProcessingFeeMoney()->getAmount();
                }else{
                    $data['processingFee'] = 0;
                }
                $data['tendertype'] = $tender->getType();
                $data['cardStatus'] = $tender->getCardDetails()->getStatus();
                $data['cardBrand'] = $tender->getCardDetails()->getCard()->getCardBrand();
                $data['cardLast4'] = $tender->getCardDetails()->getCard()->getLast4();
                $data['idempotencyKey'] = $idempotencyKey;
                $data['customerPayId'] = $custId;
                $data['customerCardId'] = $cardId;
                return $this->generateReturnData(PAY_API_SUCCESS, '', $data);
            }else{
                return $this->generateReturnData(PAY_API_FAIL, '', $response->getErrors());
            }
        }catch(Exception  $e) {
            return $e->getMessage();
        }
    }

有人可以向我指出我在这里做错了什么吗?我真的被困在这里。其他API端点运行正常,例如,使用square提供的相同方法和相同的PHP客户端创建客户,创建客户卡API端点。

PS-位于沙箱中

0 个答案:

没有答案