问题
I am receiving the following error when trying to run the demonstration from the Square SDK:
Card nonce not found in this
sandbox
application environment. Please ensure an application ID belonging to the same environment is used for the SqPaymentForm.
When I echo '<pre>';print_r($request_body); echo '</pre>';
I receive the following:
Array
(
[card_nonce] => 123456789098765432123456789
[amount_money] => Array
(
[amount] => 100
[currency] => USD
)
[idempotency_key] => 59cd807f20ce2
)
It appears that the nonce is defined. I just ran last night's code with my own credit card for testing purposes and am using the sandbox location and token. How do I resolve this problem?
The full PHP code:
<?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());
}
?>
回答1:
I recommend to use the test cases that Square proposes at first and then add to your platform. The issue here is that you must generate the card_nonce
attribute from SqPaymentForm
in the view, just as the documentation say:
A nonce generated from the SqPaymentForm that represents the card to charge. The application that provides a nonce to this endpoint must be the same application that generated the nonce with the SqPaymentForm. Otherwise, the nonce is invalid.
来源:https://stackoverflow.com/questions/46479573/square-card-nonce-not-found-in-this-sandbox-application-environment