Javascript 如何在2checkout中以沙箱模式生成令牌
嗨,我试着在我的基于codeigniter的系统中集成2checkout。在沙盒情绪中,不会生成令牌。没有令牌怎么能测试?我还尝试使用演示令牌和Javascript 如何在2checkout中以沙箱模式生成令牌,javascript,php,codeigniter-3,2checkout,Javascript,Php,Codeigniter 3,2checkout,嗨,我试着在我的基于codeigniter的系统中集成2checkout。在沙盒情绪中,不会生成令牌。没有令牌怎么能测试?我还尝试使用演示令牌和 demo=true; 这是我传递到twocheckout库的数组。我已经在构造函数中加载了商家代码和私钥 $charge = Twocheckout_Charge::auth(array( "sellerId" => $twocheckout->merchantcod
demo=true;
这是我传递到twocheckout库的数组。我已经在构造函数中加载了商家代码和私钥
$charge = Twocheckout_Charge::auth(array(
"sellerId" => $twocheckout->merchantcode,
"merchantOrderId" => $merchantOrderID,
"token" => 'MjFiYzIzYjAtYjE4YS00ZmI0LTg4YzYtNDIzMTBlMjc0MDlk',
"currency" => $currency,
"total" => $amount,
"demo" => true,
"billingAddr" => array(
"name" => $patientdetails->name,
"addrLine1" => $patientdetails->address,
"city" => $patientdetails->address,
"state" => "Alaska",
"zipCode" => "99501",
"country" => "USA",
"email" => $patientdetails->email,
"phoneNumber" => $patientdetails->phone
);
我曾经
我的js
//$(文档).ready(函数(){
//成功创建令牌时调用。
var successCallback=函数(数据){
var myForm=document.getElementById('editPaymentForm');
//将令牌设置为令牌输入的值
//警报(data.response.token.token);
$(“#editPaymentForm”)。追加(“”);
//myForm.token.value=data.response.token.token;
//重要提示:这里我们直接在表单元素上调用'submit()',而不是使用jQuery来防止和无限令牌请求循环。
myForm.submit();
};
//当令牌创建失败时调用。
var errorCallback=函数(数据){
如果(data.errorCode==200){
令牌请求();
}否则{
警报(data.errorMsg);
}
};
var tokenRequest=函数(){
//设置令牌请求参数
var expire=$(“#expire”).val();
var expiresep=expire.split(“/”);
var dateformat=时刻(expiresep[1],“YY”);
var year=dateformat.format(“YYYY”);
变量args={
sellerId:“,
可发布密钥:“”,
ccNo:$(“#卡”).val(),
cvv:$(“#cvv”).val(),
expMonth:expiresep[0],
年份:年
};
//发出令牌请求
requestToken(successCallback、errorCallback、args);
};
// });
功能二校验输出(e){
e、 预防默认值()
//试试看{
//为我们的环境拉入公共加密密钥
TCO.loadPubKey(“生产”);
//$(“#editPaymentForm”).submit(函数(e){
//调用我们的令牌请求函数
令牌请求();
//阻止表单提交
返回false;
// });
//}捕获(e){
//警报(如toSource());
// }
}
//为我们的环境拉入公共加密密钥
//});
它总是给我错误的请求,尽管我传递了文档中显示的所有参数。根据新的api文档,我现在需要对测试情绪和生产进行哪些更改
<script type="text/javascript" src="https://www.2checkout.com/checkout/api/2co.min.js"></script>
<script>
// $(document).ready(function () {
// Called when token created successfully.
var successCallback = function (data) {
var myForm = document.getElementById('editPaymentForm');
// Set the token as the value for the token input
// alert(data.response.token.token);
$("#editPaymentForm").append("<input type='hidden' name='token' value='" + data.response.token.token + "' />");
// myForm.token.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) {
tokenRequest();
} else {
alert(data.errorMsg);
}
};
var tokenRequest = function () {
<?php $twocheckout = $this->db->get_where('paymentGateway', array('name =' => '2Checkout'))->row(); ?>
// Setup token request arguments
var expire = $("#expire").val();
var expiresep = expire.split("/");
var dateformat = moment(expiresep[1], "YY");
var year = dateformat.format("YYYY");
var args = {
sellerId: "<?php echo $twocheckout->merchantcode; ?>",
publishableKey: "<?php echo $twocheckout->publishablekey; ?>",
ccNo: $("#card").val(),
cvv: $("#cvv").val(),
expMonth: expiresep[0],
expYear: year
};
// Make the token request
TCO.requestToken(successCallback, errorCallback, args);
};
// });
// try {
// Pull in the public encryption key for our environment
TCO.loadPubKey('production');
// $("#editPaymentForm").submit(function (e) {
// Call our token request function
tokenRequest();
// Prevent form from submitting
return false;
// });
// } catch (e) {
// alert(e.toSource());
// }
}
// Pull in the public encryption key for our environment
//});
</script>