php SkipCash:无法过帐付款申请BytePositionInLine1

e5nszbig  于 2023-01-24  发布在  PHP
关注(0)|答案(1)|浏览(132)

我试图使用skipcash作为我的支付网关,但当我试图张贴付款,它返回和一个错误,不知道这是从哪里来的。
这是我的代码结构

$formData = [
            "uid" => Str::uuid()->toString(),
            "keyId" => $skipCashKeyId,
            "amount" => number_format($order->total_amount, 2),
            "firstName" => $order->user->first_name,
            "lastName" => $order->user->last_name,
            "phone" => $order->user->phone_number,
            "email" => $order->user->email,
            "street" => "CA",
            "city" => "TempCity",
            "state" => "00",
            "country" => "00",
            "postCode" => "01238",
            "transactionId" => $order->reference_no,
            "orderId" => $order->id
        ];

        $query = http_build_query($formData, "", ",");

        $signature = hash_hmac('sha256', json_encode($query), $skipCashSecretKey);

        $headers = [
            'Authorization: ' . base64_encode($signature),
            'Content-Type: application/json;charset=UTF-8',
            'x-client-id: ' . $skipCashClientId
        ];
        

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $skipCashUrl);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $formData);

        $response = curl_exec($ch);
        curl_close($ch);

        $data = json_decode($response);

但回应是这样的:

"data": {
        "$": [
            "'-' is invalid within a number, immediately after a sign character ('+' or '-'). Expected a digit ('0'-'9'). Path: $ | LineNumber: 0 | BytePositionInLine: 1."
        ]
    },

我不知道这个问题是在SkipCash API还是什么,但是他们的文档有点不完整,所以也许有些人有SkipCash的经验,你如何格式化你的有效载荷和授权。
谢谢

qgzx9mmu

qgzx9mmu1#

我已经修好这个了。
这里的问题是字段没有正确地与需求对齐。

// the key should me capitalize and the fields should not be empty
 $formData = [
            "Uid" => Str::uuid()->toString(),
            "KeyId" => $skipCashKeyId,
            "Amount" => "$order->total_amount",
            "FirstName" => $order->user->first_name,
            "LastName" => $order->user->last_name,
            "Phone" => $order->user->phone_number,
            "Email" => $order->user->email,
            "Street" => "CA",
            "City" => "TempCity",
            "State" => "00",
            "Country" => "00",
            "PostalCode" => "01238",
            "TransactionId" => $order->reference_no,
        ];

相关问题