Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
622 views
in Technique[技术] by (71.8m points)

node.js - Error connecting to Stripe from Firebase Cloud Function

I am trying to process a credit card payment from my Android App using Firebase and Stripe. I have retrieved a Stripe token on my client, and I am using a database trigger in my Firebase Cloud Function to catch when a new order is posted. Here is my function code.

const stripe = require('stripe')('sk_test_XXXXXXXXXXXXXXXXXXXXXXXX');

return admin.database()
    .ref()
    .child('orders')
    .child(userId)
    .child(orderId)
    .child('token')
    .once('value')
    .then(snapshot => {
        return snapshot.val();
    })
    .then(token => {

        const amount = order.amount;
        console.log('Amount:', amount);
        console.log('token:', token.id);

        const idempotency_key = orderId;
        const source = token.id;
        const currency = 'usd';
        const charge = {amount, currency, source};

        return stripe.charges.create(charge, { idempotency_key });
    })
    .then(charge => {
        console.log('Success:', charge);
        // If the result is successful, write it back to the database
        return event.data.adminRef.set(charge);
    }, error => {
        console.log('Error:', error);

        return;
    }
);

enter code here

This is generating the following error:

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:120:13) at Error.Constructor (/user_code/node_modules/stripe/lib/utils.js:120:13) at ClientRequest. (/user_code/node_modules/stripe/lib/StripeResource.js:206:9) at emitOne (events.js:96:13) at ClientRequest.emit (events.js:188:7) at TLSSocket.socketErrorListener (_http_client.js:309:9) at emitOne (events.js:96:13) at TLSSocket.emit (events.js:188:7) at connectErrorNT (net.js:1021:8) at _combinedTickCallback (internal/process/next_tick.js:80:11) at process._tickDomainCallback (internal/process/next_tick.js:128:9)

I can't find any documentation on this error. And I have tried everything I can think of. All the variables contain valid data.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...