Я пытаюсь использовать API Sandbox 2checkout, но столкнулся с некоторыми проблемами. Я использую Laravel в качестве фреймворка для php и 2co.min.js для генерации токена. Когда я заполняю поля и нажимаю «Отправить», я получил «неавторизованный».
Я получаю идентификатор продавца из своей учетной записи в песочнице и открытый закрытый ключ для API и проверил их, но я все равно получаю эту ошибку:
Идентификатор продавца, открытый и закрытый ключи

<form id = "myCCForm" class = "col-md-6" action = "{{ route('pay') }}" method = "post">
@csrf
<input id = "token1" name = "token1" type = "hidden" value = "">
<div>
<label>
<span>Card Number</span>
</label>
<input id = "ccNo" type = "text" size = "20" value = "" autocomplete = "off" required/>
</div>
<div>
<label>
<span>Expiration Date (MM/YYYY)</span>
</label>
<input type = "text" size = "2" id = "expMonth" required/>
<span> / </span>
<input type = "text" size = "2" id = "expYear" required/>
</div>
<div>
<label>
<span>CVC</span>
</label>
<input id = "cvv" size = "4" type = "text" value = "" autocomplete = "off" required/>
<input type = "text" id = "billingAddr" name = "billingAddr" placeholder = "Billing Adr ">
</div>
<input type = "submit" value = "Submit Payment">
</form>
Код JS
<script src = "//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src = "https://www.2checkout.com/checkout/api/2co.min.js"></script>
<script>
// Pull in the public encryption key for our environment
// Called when token created successfully.
var successCallback = function (data) {
var myTokenInput = document.getElementById('token1');
// Set the token as the value for the token input
myTokenInput.value = data.response.token.token;
// IMPORTANT: Here we call `submit()` on the form element directly instead of using jQuery to prevent and infinite token request loop.
myForm.submit();
};
// Called when token creation fails.
var errorCallback = function (data) {
if (data.errorCode === 200) {
console.info(data);
} else {
console.info(data);
}
};
var tokenRequest = function () {
// Setup token request arguments
var args = {
sellerId: "203840804",
publishableKey: "ACC02BE7-70FC-4AEF-9F75-D592E299DEDA",
ccNo: $("#ccNo").val(),
cvv: $("#cvv").val(),
expMonth: $("#expMonth").val(),
expYear: $("#expYear").val(),
billingAddr: $("#billingAddr").val()
};
// Make the token request
TCO.requestToken(successCallback, errorCallback, args);
};
$(function () {
// Pull in the public encryption key for our environment
TCO.loadPubKey('production');
$("#myCCForm").submit(function (e) {
e.preventDefault();
// Call our token request function
tokenRequest();
// Prevent form from submitting
return false;
});
});



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Вам нужно изменить senderId и publishableKey в своем скрипте.
Измените функцию tokenRequest на эту:
var tokenRequest = function () {
// Setup token request arguments
var args = {
sellerId: "901389630",
publishableKey: "A4B8A470-61A2-470E-9DCB-013A033FD206",
ccNo: $("#ccNo").val(),
cvv: $("#cvv").val(),
expMonth: $("#expMonth").val(),
expYear: $("#expYear").val(),
billingAddr: $("#billingAddr").val()
};
// Make the token request
TCO.requestToken(successCallback, errorCallback, args);
};
И, как писал @LahiruTM, замените TCO.loadPubKey('production'); на TCO.loadPubKey('sandbox');
Попробуйте заменить TCO.loadPubKey ('production'); с TCO.loadPubKey («песочница»);