首页 > 解决方案 > 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) {

标签: javascriptsquare-connectsquare

解决方案


澄清,

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) {.


推荐阅读