【问题标题】:How to connect Stripe, AWS Cognito, and my RDS Postgres database all together?如何将 Stripe、AWS Cognito 和我的 RDS Postgres 数据库连接在一起?
【发布时间】:2021-01-12 23:35:57
【问题描述】:

我们的目标是拥有一个用户表,其中包含他们的 Stripe 客户 ID、他们用于身份验证的电子邮件以及他们选择从我的 Web 应用程序购买的计划。

一旦用户通过 Cognito 注册到我的 Web 应用程序,就很容易插入用户记录。在前端,我检查身份验证状态何时更改为“signUp”,然后调用后端 Express API,该 API 使用他们的电子邮件和用户名创建一个新用户。

困难的部分是当客户通过 Stripe 进行购买时。我使用了为我创建 UI 和逻辑的预构建结帐页面。我在后端设置了事件 webhook,这样每当客户购买商品时,我就可以在那里执行我的逻辑。问题是当这个 webhook 被触发时,我没有关于他们电子邮件的信息,所以我不知道如何在数据库中找到他们的记录并使用客户 ID 信息更新它。

这是我的 webhook 代码:


router.post("/webhooks", (req, res) => {
  const event = req.body;

  switch (event.type) {
    case "charge.succeeded": {
      console.log("CHARGE SUCCEEDED", event);
    }
    case "payment_intent.succeeded": {
      console.log(event);
      const paymentIntent = event.data.object;
      const customer_id = event.data.object.customer;

      console.log("PaymentIntent was successful!");

      // Cognito_User.update(
      //   {stripe_id : "test_stripe4_id"},
      //   {returning: true, where: {email: ???} }
      // )
      break;
    }
    case "payment_method.attached": {
      const paymentMethod = event.data.object;
      console.log("PaymentMethod was attached to a Customer!");
      break;
    }
    // ... handle other event types
    default: {
      // Unexpected event type
      return res.status(400).end();
    }
  }

从技术上讲,我可以使用客户在 Stripe Checkout 中提交的电子邮件来支付他们的计划,但这可能并不总是他们用来登录的电子邮件。

我想知道是否可以将其他用户信息(他们用于登录 cognito 的电子邮件)附加到 webhook 触发器,或者我是否需要放弃预构建结帐并通过代码创建 Stripe 付款结帐流程?

【问题讨论】:

    标签: postgresql amazon-cognito stripe-payments


    【解决方案1】:

    您可以在创建结帐会话 ID 后并在重定向之前保存它,或者在创建会话时提供系统中已经存在的 Client Reference ID

    任何一种方式都可以。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-27
      • 2019-11-08
      • 2021-10-14
      • 2021-11-15
      • 2016-07-08
      • 2021-04-19
      • 2021-04-06
      • 2014-12-24
      相关资源
      最近更新 更多