条纹终端付款模拟器[错误不是有效的ByteString]

时间:2019-07-02 12:21:46

标签: javascript php stripe-payments

我正在尝试使用条纹终端(https://stripe.com/docs/terminal)在我的PHP应用程序上为POS付款设置读卡器

一切顺利,直到调用collectPaymentMethod。返回错误:

无法在“标头”上执行“附加”:该值不是有效的ByteString。

我已经尝试了很多方法来进行故障排除,但无法获得解决方案

我尝试使用stripe提供的示例应用程序进行调试。但没有任何日志。我也尝试手动生成客户端机密并运行collectPaymentMethod,但是没有用。

function fetchConnectionToken() {
  // Your backend should call /v1/terminal/connection_tokens and return the JSON response from Stripe
  return fetch('/stripe/connection_tokens', { method: "POST" })
    .then(response => response.json())
    .then(data => data.secret);
}

function unexpectedDisconnect() {
  console.log("Disconnected from reader")
}

var terminal = StripeTerminal.create({
  onFetchConnectionToken: fetchConnectionToken,
  onUnexpectedReaderDisconnect: unexpectedDisconnect,
});

// Handler for a "Connect Reader" button
function connectReaderHandler() {
  const config = {simulated: true};
  terminal.discoverReaders(config).then(function(discoverResult) {
    if (discoverResult.error) {
      console.log('Failed to discover: ', discoverResult.error);
    } else if (discoverResult.discoveredReaders.length === 0) {
      console.log('No available readers.');
    } else {
      // Just select the first reader here.
      console.log(discoverResult);
      var selectedReader = discoverResult.discoveredReaders[0];

      terminal.connectReader(selectedReader).then(function(connectResult) {
        if (connectResult.error) {
          console.log('Failed to connect: ', connectResult.error);
        } else {
          console.log('Connected to reader: ', connectResult.reader.label);
        }
      });
    }
  });
}

function checkout() {
    var response = fetch('/stripe/paymentIntent').then(function(response) {
      return response.json();
    }).then(function(responseJson) {
        var clientSecret = responseJson.client_secret;

        // clientSecret is the client_secret from the PaymentIntent you created in Step 1.
        terminal.collectPaymentMethod(clientSecret).then(function(result) {
            console.log(result);
            if (result.error) {
                console.log('error')
              // Placeholder for handling result.error
            } else {
                // Placeholder for processing result.paymentIntent
                console.log('test')

                terminal.processPayment(paymentIntent).then(function(result) {
                  if (result.error) {
                    // Placeholder for handling result.error
                  } else if (result.paymentIntent) {
                    // Placeholder for notifying your backend to capture result.paymentIntent.id
                  }
                });
            }
        });
    });



}

:formatted:3094 Uncaught (in promise) TypeError: Failed to execute 'append' on 'Headers': Value is not a valid ByteString.
    at t.e.get (:formatted:3094)
    at t.loadResource (:formatted:3127)
    at t.<anonymous> (:formatted:3311)
    at :formatted:3264
    at Object.next (:formatted:3277)
    at c (:formatted:3165)
e.get @ :formatted:3094
t.loadResource @ :formatted:3127
(anonymous) @ :formatted:3311
(anonymous) @ :formatted:3264
(anonymous) @ :formatted:3277
c @ :formatted:3165
Promise.then (async)
(anonymous) @ :formatted:2872
e @ :formatted:2860
e.chainCancelable @ :formatted:2878
(anonymous) @ :formatted:3664
(anonymous) @ :formatted:3454
(anonymous) @ :formatted:3467
(anonymous) @ :formatted:3373
c @ :formatted:3352
e.collectPaymentMethod @ :formatted:3638
(anonymous) @ :formatted:442
(anonymous) @ :formatted:411
(anonymous) @ :formatted:359
(anonymous) @ :formatted:372
(anonymous) @ :formatted:278
i @ :formatted:257
u @ :formatted:405
n.value @ :formatted:441
(anonymous) @ :formatted:1019
(anonymous) @ 5:278
Promise.then (async)
checkout @ 5:274
(anonymous) @ VM4080:1

0 个答案:

没有答案