Square: Card nonce not found in this `sandbox` application environment

流过昼夜 提交于 2019-12-24 20:29:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!