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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…