我正在尝试使用stripe
云功能实现firestore
收费功能,并且在stackoverflow线程上发现了此功能。我从未使用过使用条纹触发器的函数,所以我正努力用postman
测试此函数。有什么方法可以使用postman
测试此功能?如果是,那么请告诉我该怎么做,但是如果我不能这样做,那么我想知道如何在包含名为PaymentRequest的组件的angular
应用程序中使用此功能。这是函数
exports.stripeCharge = functions.firestore
.document('/users/{userId}/payments/{paymentId}')
.onWrite(event => {
const payment = event.data.data()
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.firestore()
.doc(`/users/${userId}`)
.get()
.then(snapshot => {
return snapshot
})
.then(customer => {
const amount = payment.price * 100 // amount must be in cents
const idempotency_key = paymentId // prevent duplicate charges
const source = payment.token.id
const currency = 'usd'
const description = 'irl Map Fine Print'
const charge = {amount, currency, source}
return stripe.charges.create(charge, { idempotency_key })
})
.then(charge => {
admin.firestore()
.doc(`/users/${userId}/payments/${paymentId}`)
.set({
charge: charge
}, { merge: true })
})
});
邮递员无法直接调用Firestore触发器。它只能使用其端点URL调用HTTP类型的函数。
如果要调用此功能,请使用Firebase控制台或您编写的其他代码来创建或修改与文档模式匹配的文档。