尝试从Square SDK运行演示时,我收到以下错误:
在此
sandbox
应用程序环境中找不到卡片随机数。请 确保使用属于同一环境的应用程序ID SqPaymentForm。
当我echo '<pre>';print_r($request_body); echo '</pre>';
时,我收到以下内容:
Array
(
[card_nonce] => 123456789098765432123456789
[amount_money] => Array
(
[amount] => 100
[currency] => USD
)
[idempotency_key] => 59cd807f20ce2
)
看来nonce 是定义的。我刚用我自己的信用卡运行昨晚的代码用于测试目的,并使用沙箱位置和令牌。我该如何解决这个问题?
完整的PHP代码:
<?php
require 'vendor/autoload.php';
$access_token = 'sandbox-abcdef-ghi-j_klmnopqrstuvwxyz';
# setup authorization
\SquareConnect\Configuration::getDefaultConfiguration()->setAccessToken($access_token);
# create an instance of the Transaction API class
$transactions_api = new \SquareConnect\Api\TransactionsApi();
$location_id = '0987654321098_7654321098765432';
$nonce = '123456789012345678901234567';
$request_body = array (
"card_nonce" => $nonce,
# Monetary amounts are specified in the smallest unit of the applicable currency.
# This amount is in cents. It's also hard-coded for $1.00, which isn't very useful.
"amount_money" => array (
"amount" => 10,
"currency" => "USD"
),
# Every payment you process with the SDK must have a unique idempotency key.
# If you're unsure whether a particular payment succeeded, you can reattempt
# it with the same idempotency key without worrying about double charging
# the buyer.
"idempotency_key" => uniqid()
);
echo '<pre>';print_r($request_body); echo '</pre>';
try {
$result = $transactions_api->charge($location_id, $request_body);
print_r($result);
} catch (\SquareConnect\ApiException $e) {
echo "Exception when calling TransactionApi->charge:";
var_dump($e->getResponseBody());
}
?>
答案 0 :(得分:0)
我建议先使用Square建议的test cases,然后再将其添加到您的平台中。这里的问题是,您必须从视图中的card_nonce
生成SqPaymentForm
属性,就像documentation这样说:
从SqPaymentForm生成的随机数,代表要 收费。向该端点提供随机数的应用程序必须是 使用SqPaymentForm生成随机数的同一应用程序。 否则,nonce无效。