javascript - Square SCA 验证买家
问题描述
我正在尝试在 SCA 的 Square 支付表单 JS 中更新 cardNonceResponseReceived(我们位于英国),并且正在使用当前的连接版本并遵循 Square 提供的代码示例,但在控制台和表单无法按预期加载。我看不到我错过了什么 - 任何帮助表示赞赏。
我已经检查了最新的 JS 示例的当前 connect-api php-payment,但问题仍然存在于我们的现场以及https://github.com/square/connect-api-examples/blob/master/connect-examples /v2/php_payment/js/sq-payment-form.js示例,无论调用沙箱还是实时环境。该错误发生在食谱中所有 Square 的更新 cardNonceResponseReceived 示例的示例中。我提供 locationId 并已更新代码如下(形成提供的示例):
/*
* callback function: cardNonceResponseReceived
* Triggered when: SqPaymentForm completes a card nonce request
*/
cardNonceResponseReceived: function (errors, nonce, cardData) {
// Assign the nonce value to the hidden form field
document.getElementById('card-nonce').value = nonce;
const verificationDetails = {
amount: '100.00',
intent: "CHARGE", //Allowed values: "CHARGE", "STORE"
billingContact: {
familyName: "Smith",
givenName: "John",
email: "jsmith@example.com",
country: "GB",
city: "London",
postalCode: "SW7 4JA",
phone: "020 7946 0532"
}
};
try {
paymentform.verifyBuyer(
nonce,
verificationDetails,
callback(err,verification) {
if (err == null) {
document.getElementById('buyerVerification-token').value = verification;
}
});
// POST the nonce form to the payment processing page
document.getElementById('nonce-form').submit();
} catch (typeError) {
//TypeError thrown if illegal arguments are passed
}
}
控制台报SyntaxError: Expected ')'
(Edge)
SyntaxError: missing ) after argument list
(Firefox)就行
callback(err,verification) {
解决方案
澄清,
paymentform.verifyBuyer(
nonce,
verificationDetails,
callback(err,verification) {
//--------------------------^
函数调用的 Javascript 语法是这样的callback(err,verification)
;匿名函数定义的语法类似于function(err,verification) {...}
,命名函数定义的语法类似于function callback(err,verification) {...}
. 所以这就是说你想调用一个名为“callback”的现有函数作为第三个参数,然后你有{
,这没有意义。最常见的情况是缺少结束字符时发生这种情况,这就是所有 Javascript 引擎都建议)
缺少结束字符的原因。
它应该说function(err,verification) {
而不是callback(err,verification) {
.
推荐阅读
- sql - Oracle Sql 在匹配存在时检索总和
- postgresql - 如何使用光标打印我添加到 postgresql 表中的新内容?
- reactjs - 使用 Storybook 进行 React-table[v7] 渲染
- reactjs - 如何使用钩子更新数组 React Native 中一个对象的状态
- visual-studio-code - vs code C++ 包含路径列表
- php - Laravel 6 Paypal 订阅 srmklive/paypal 问题
- google-cloud-dataflow - 如何将 tab(\t) 指定为数据流模板中文本的分隔符?
- azure - Azure CosmosDB REST API 省略了数据资源管理器返回的结果
- c# - C# UWP How to set the background behind the application to black
- haskell - 流上的这种折叠/扫描概念是什么?