【问题标题】:Stripe Node JS integration no error callbackStripe Node JS 集成无错误回调
【发布时间】:2020-09-19 18:42:03
【问题描述】:

我一直在尝试将 Stripe 与 Node JS 集成,但我无法让 Stripe 返回错误。我故意传递了格式错误的数据,但我仍然无法恢复错误。

我是 Node JS 的新手。

这是 Stripe 的官方文档: https://stripe.com/docs/api/charges/create

这是我的代码:

Parse.Cloud.define("addCredit", (request) => {
// Use stripe API and your own 'secret key'
var stripe = require('stripe')('xdsewew');

// Charge user's card
stripe.charges.create({
    amount: request.params.amount,
    currency: 'usd',
    source: request.params.token,
    description: request.params.userId,
  }, function(error, charge) {
      return(error);
  });

});

当我尝试返回错误时,也许我做得不对?

【问题讨论】:

    标签: node.js parsing stripe-payments


    【解决方案1】:

    我尝试了同样的方法,我能够记录错误

      var stripe = require("stripe")("sk_test_4eC39HqLyjWDarjtT1zdp7d");
    
        stripe.charges.create(
          {
            amount: 2000,
            currency: "usd",
            source: "tok_mastercard",
            description: "My First Test Charge (created for API docs)",
          },
          function (err, charge) {
            if (err) {
              // different ways to log error 
              console.log("error message -> ", err.message);
              console.log("error type - >", err.type);
              console.log("eror raw -> ", err.raw);
              return err;
            }
            console.log(charge);
          }
        );
    

    希望这对你有用:)

    【讨论】:

    • 非常感谢。可能是 Parse Server 的问题。
    猜你喜欢
    • 1970-01-01
    • 2017-04-03
    • 2017-04-26
    • 2018-06-30
    • 2019-05-14
    • 1970-01-01
    • 2021-08-02
    • 2019-01-20
    • 1970-01-01
    相关资源
    最近更新 更多