用于 React 的 MailChimp 和 Stripe 集成

MailChimp and Stripe Integration for React

我想在我的网站上构建一个自定义 React 表单,当有人使用 Stripe 支付一次性费用时,如果成功,那么他们应该被添加到我的 MailChimp 电子邮件列表中。有谁知道如何做到这一点?

这将是您可以使用 payment_intent.succeeded 网络钩子“after the payment”执行的操作。

您可以使用该电子邮件地址创建一个 customer(推荐)或简单地将其作为 metadata 附加到付款意向。然后你 build a webhook endpoint and set it up to receive these payment_intent.succeeded events. When you receive events, you'd get the email address (either by retrieving the Customer or inspecting the metadata) and call MailChimp's API to add a member to your list:

curl -X POST \
  'https://${dc}.api.mailchimp.com/3.0/lists/{list_id}/members?skip_merge_validation=<SOME_BOOLEAN_VALUE>' \
  --user "anystring:${apikey}"' \
  -d '{"email_address":"","email_type":"","status":"subscribed","merge_fields":{},"interests":{},"language":"","vip":false,"location":{"latitude":0,"longitude":0},"marketing_permissions":[],"ip_signup":"","timestamp_signup":"","ip_opt":"","timestamp_opt":"","tags":[]}'

或使用 Node 客户端:

const response = await client.lists.addListMember("list_id", {
    email_address: "joe@example.com",
    status: "pending",
  });