简体   繁体   English

条带连接错误

[英]Stripe Connection Error

I have the follow backend Node.js code to connect to my Stripe account to make a Charge.我有以下后端 Node.js 代码连接到我的 Stripe 帐户以进行收费。 But I'm getting this error.但我收到这个错误。 I'm using Firebase Functions, and this functionality used to work before, so I doubt this is anything to do with Firebase access restrictions.我正在使用 Firebase 函数,这个功能以前可以使用,所以我怀疑这与 Firebase 访问限制有关。 Any ideas and help on this will be greatly appreciated!对此的任何想法和帮助将不胜感激!

var functions = require('firebase-functions');
var stripe = require('stripe')('sk_test');
var express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors');

exports.stripePay = functions.https.onRequest((request, response) => {
  if (request.method === 'POST') {
    var app = express();
    var router = express.Router();

    app.use(bodyParser.urlencoded({ extended: false }));
    app.use(cors());

    var stripetoken = request.body.cardToken;
    var amountpayable = request.body.amount;

    var charge = stripe.charges.create({
      amount: amountpayable,
      currency: 'usd',
      source: stripetoken,
      description: 'Sample transaction'
    }, function (err, charge) {
      console.log("ST4");
      if (err) {
        response.send("Failed!");
      }
      else {
        response.send({ success: true });
      }
    })
  }

{ Error: An error occurred with our connection to Stripe
    at Error._Error (/user_code/node_modules/stripe/lib/Error.js:12:17)
    at Error.Constructor (/user_code/node_modules/stripe/lib/utils.js:98:13)
    at Error.Constructor (/user_code/node_modules/stripe/lib/utils.js:98:13)
    at ClientRequest.<anonymous> (/user_code/node_modules/stripe/lib/StripeResource.js:192:9)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:188:7)
    at TLSSocket.socketErrorListener (_http_client.js:310:9)
    at emitOne (events.js:96:13)
    at TLSSocket.emit (events.js:188:7)
    at connectErrorNT (net.js:1020:8)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickDomainCallback (internal/process/next_tick.js:122:9)   type: 'StripeConnectionError', stack: 'Error: An error occurred with our connection to Stripe\n    at Error._Error (/user_code/node_modules/stripe/lib/Error.js:12:17)\n    at Error.Constructor (/user_code/node_modules/stripe/lib/utils.js:98:13)\n    at Error.Constructor (/user_code/node_modules/stripe/lib/utils.js:98:13)\n    at ClientRequest.<anonymous> (/user_code/node_modules/stripe/lib/StripeResource.js:192:9)\n    at emitOne (events.js:96:13)\n    at ClientRequest.emit (events.js:188:7)\n    at TLSSocket.socketErrorListener (_http_client.js:310:9)\n    at emitOne (events.js:96:13)\n    at TLSSocket.emit (events.js:188:7)\n    at connectErrorNT (net.js:1020:8)\n    at _combinedTickCallback (internal/process/next_tick.js:74:11)\n    at process._tickDomainCallback (internal/process/next_tick.js:122:9)',   rawType: undefined,   code: undefined,   param: undefined,   message: 'An error occurred with our connection to Stripe',   detail:     { Error: getaddrinfo ENOTFOUND api.stripe.com api.stripe.com:443
       at errnoException (dns.js:28:10)
       at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
     code: 'ENOTFOUND',
     errno: 'ENOTFOUND',
     syscall: 'getaddrinfo',
     hostname: 'api.stripe.com',
     host: 'api.stripe.com',
     port: '443' },   raw:     { message: 'An error occurred with our connection to Stripe',
     detail: 
      { Error: getaddrinfo ENOTFOUND api.stripe.com api.stripe.com:443
          at errnoException (dns.js:28:10)
          at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
        code: 'ENOTFOUND',
        errno: 'ENOTFOUND',
        syscall: 'getaddrinfo',
        hostname: 'api.stripe.com',
        host: 'api.stripe.com',
        port: '443' } },   requestId: undefined,   statusCode: undefined } Reply

this is a good one!这个不错! Firebase blocks external API connections for Free accounts, just get any paid account and this will work! Firebase 阻止免费帐户的外部 API 连接,只需获取任何付费帐户即可!

Dimitris 的回答是正确的,用更外行的术语来说,只需进入 blaze 计划,您就可以从 Firebase 函数调用 stripe api。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM