简体   繁体   English

如何确认条带中的成功付款费用

[英]How to confirm successful payment charge in stripe

I want a confirmation that a charge was successful in stripe. 我想要确认条纹充电成功。 I have the following that I think works fine: 我认为以下工作正常:

 exports.chargecustomer = functions.database.ref('/Orders/{pushId}').onCreate((event) => {

     const original = event.data.val();
     const orderid = event.params.pushId;

     const token = original.paytoken;

     var orderstatus = {

         status: "charged"
     };

     var updates = {};
     updates['/Orders/' + orderid + "status"] = "charged";

     // Charge the user's card:
     stripe.charges.create({
         amount: 999,
         currency: "usd",
         description: "Example charge",
         source: token,


     }, function(err, charge) {

         console.log('error from charging', err);


         if (charge.paid === true) {

             //change status to charged
             console.log("the payment went through")
             return event.data.ref.parent.update(updates);


         } else {
             console.log("the payment did not go through")

         }

     });

 });

when I run this it says the err is null which I assumed the charge went through. 当我运行此命令时,它说err为空,我以为费用已通过。

update: I was able to retrieve the charge attribute to know if the charge went through. 更新:我能够检索到费用属性,以了解费用是否通过了。 I want to update the node that has the charge status from pending to charged but I don't know what is wrong with the code, no update is being done. 我想将具有充电状态的节点从待处理状态更新为已充电状态,但是我不知道代码出了什么问题,因此没有更新。 What am doing wrongly and how can i update the "status" attribute in this path '/Orders/' +orderid to charged? 做错了什么,如何在此路径“ / Orders /” + orderid中将“ status”属性更新为已收费?

sdk条纹通过成功回调确认您是否已成功付款,如果您想对成功付款有所了解,可以在此处添加一些提醒,例如电子邮件

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

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