php - Stripe Checkout webhook 不传递客户电子邮件?

标签 php stripe-payments

我在测试模式下使用 Stripe 的 Checkout。我试图在 Stripe 中获取客户的 ID 以及他们在结账时提供的电子邮件以更新我的数据库。

我为 checkout.session.completed 设置了一个 webhook。如果我发送一个测试 webhook,id 是填写的,但 customer_email 不是。

我想也许测试 webhook 不会通过该信息,所以我填写了结帐表格。我的 id 很好,但 customer_email 为空。

我猜我只是不明白与 Stripe 交互的正确方式。


// straight from Stripe's documentation
try {
  $event = \Stripe\Webhook::constructEvent(
    $payload, $sig_header, $endpoint_secret
  );
} catch(\UnexpectedValueException $e) {
  // Invalid payload
  http_response_code(400);
  exit();
} catch(\Stripe\Exception\SignatureVerificationException $e) {
  // Invalid signature
  http_response_code(400);
  exit();
}

// Handle the checkout.session.completed event
if ($event->type == 'checkout.session.completed') {
  $session = $event->data->object;

  // Fulfill the purchase...
  handle_checkout_session($session);
}

http_response_code(200);

// my simple function
function handle_checkout_session($session){
  $stripeID=$session['id'];
  $userEmail=$session['customer_email'];
  print 'Email: ' . $userEmail . '\n'; // works
  print 'Stripe ID: ' . $stripeID . '\n'; // empty
}

最佳答案

我也花了很长时间才弄清楚这一点。
customer_email checkout.session.completed 中的字段如果您在结帐前已经知道用户的电子邮件,则该对象仅用于将电子邮件传递到 Stripe 生成的结帐表单。

要在交易后通过您的 webhook 提取用户的电子邮件,请将您的 webhook 设置为发送 customer.created事件(您可以从 webhook 事件选项中选择)。用户在 Checkout 付款表单中输入的电子邮件将可在该对象上访问。但是,请注意它被称为 email ,而不是 customer_email , 在 customer.created事件。

关于php - Stripe Checkout webhook 不传递客户电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61579146/

相关文章:

stripe-payments - Stripe Token and Charge Api vs Stripe paymentIntent api

stripe-payments - 在发票到期前多少天会调用 invoice.upcoming webhook?

javascript - 需要指导尝试使用 Node js 设置带有 strip 的可变数量

php - 在 Stripe 上测试订阅续订

php - 是否可以在不关闭两步验证的情况下使用 PHPMailer?

php - 使用 simpleXML 自动重复结构?

javascript - html代码中div标签的错误消息

php - 是否可以在 CodeIgniter 中对 View 进行单元测试?

php - 如何访问mysql_fetch_array返回值的元素?

python - 似乎无法使用 python 检索 Stripe 电荷