【发布时间】:2019-01-29 19:47:08
【问题描述】:
我正在尝试使用 Sandbox 2checkout API,但遇到了一些问题。 我使用 Laravel 作为 php 框架和 2co.min.js 来生成令牌。 当我填写输入并按提交时,我得到了“未经授权”。
我从我的沙盒帐户和公钥、私钥中获取卖家 ID 为 API 并检查了它们,但我仍然收到此错误:
卖家ID、公钥和私钥
HTML 代码
<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.log(data);
} else {
console.log(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;
});
});
我需要帮助
【问题讨论】:
-
尝试替换 TCO.loadPubKey('production');使用 TCO.loadPubKey('sandbox');
标签: javascript php jquery laravel 2checkout