【发布时间】:2018-05-19 08:08:59
【问题描述】:
我在index.js 中有一些从本教程中获得的代码:https://angularfirebase.com/lessons/angular-stripe-payments-part-2-firebase-cloud-functions-backend/
代码如下:
const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase);
const stripe = require('stripe')(functions.config().stripe.testkey)
exports.stripeCharge = functions.database
.ref('/payments/{userId}/{paymentId}')
.onWrite(event => {
const payment = event.data.val();
const userId = event.params.userId;
const paymentId = event.params.paymentId;
// checks if payment exists or if it has already been charged
if (!payment || payment.charge) return;
return admin.database()
.ref(`/users/${userId}`)
.once('value')
.then(snapshot => {
return snapshot.val();
})
.then(customer => {
const amount = payment.amount;
const idempotency_key = paymentId; // prevent duplicate charges
const source = payment.token.id;
const currency = 'usd';
const charge = {amount, currency, source};
return stripe.charges.create(charge, { idempotency_key });
})
.then(charge => {
admin.database()
.ref(`/payments/${userId}/${paymentId}/charge`)
.set(charge)
})
});
如何将“SUCCESS”消息传递给我的组件,例如:make-payment.component.ts,在 TypeScript 中。
【问题讨论】:
标签: javascript angular typescript firebase angular-cli