为什么 Stripe Checkout 不将客户名称添加到客户记录中? [英] Why Doesn't Stripe Checkout Add Customer Name to Customer Record?

查看:27
本文介绍了为什么 Stripe Checkout 不将客户名称添加到客户记录中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Stripe Checkout 表单提交中检索各种数据,我只是使用 Stripe 仪表板中提供的 Stripe Checkout 代码.

I am trying to retrieve various pieces of data from a Stripe Checkout form submission, where I am just using the Stripe Checkout code provided in my Stripe Dashboard.

在我的 checkout_submission_completed 事件中,我有 webhook,我试图在其中检索 emailname,以便在成功购买后我可以采取其他操作.

In my checkout_submission_completed event I have webhook where I am trying to retrieve email, name so that after successful purchase I can take other actions.

出奇的困难.

这是我如何检索电子邮件(其中 payload 是我的 webhook 收到的响应):

Here is how I can retrieve email (where payload is the response my webhook receives):

 $cust = $payload['data']['object']['customer'];
 $custdata = \Stripe\Customer::retrieve($cust);
 $email=$custdata->email;

好吧,没什么大不了的.

Ok, not a big deal.

名字怎么样?好吧,这就是事情变得非常有趣的地方.点击表单支付提交按钮后,Stripe 创建一个客户,完成一次成功的收费.但是在 Customer 对象中没有名称.是的,没有名字.在今天与 Stripe 的聊天中,他们没有解释,并表示他们会进一步调查.

How about Name? Well, here is where things get really fun. After hitting the form payment submit button Stripe creates a customer, completes a successful charge. But in the Customer object there is no name. Yes, no name. During a chat today with Stripe they had no explanation and said they would look into it more.

事实证明,表单上输入的名称出现在 Stripe 对象中的唯一地方是 Payment Intent 对象中的 Payment Details 对象.

Turns out the only place where the name entered on the form shows up in a Stripe object is the Payment Details Object within the Payment Intent object.

我是认真的.所以这就是我如何获取名称(使用以前代码中的 cust :

I am serious. So here is how I am getting the name (using cust from previous code:

   $piid = $cust = $payload['data']['object']['payment_intent'];
   $pi = \Stripe\PaymentIntent::retrieve($piid);
   $name = $pi['charges']['data'][0]['billing_details']['name'];

有没有更好的方法来做到这一点?

Is there a better way for me to do this?

谢谢,布莱恩

推荐答案

我认为这个想法是收集的名称是一个 持卡人 名称并且与卡片 [0] 相关联,而不是 Customer.客户最终可能会拥有多张卡或其他付款方式,而且他们可能都有不同的持卡人姓名.因此,默认情况下,该信息不会传递给客户.

I think the idea is that the name collected is a cardholder name and is associated with the card [0] , not the Customer. A Customer might end up with multiple cards or other payment methods, and they might reasonably all have different cardholder names. So that information isn't transposed up to the Customer by default.

您的方法总体上看起来不错 — 我个人会使用 API 的扩展功能 [1],因此您可以通过在一次调用中检索结帐会话及其付款和客户的完整上下文来跳过一堆 API 调用网络钩子处理程序.

Your approach looks generally good — I would personally use the expand feature [1] of the API so you can skip a bunch of API calls by retrieving the full context of the Checkout Session and its payment and customer in one call from the webhook handler.

$session  = \Stripe\Checkout\Session::retrieve(
  $payload['data']['object']['id'],
  ["expand" => ["payment_intent", "customer"]]);

$cardholderName = $session['payment_intent']['charges']['data'][0]['billing_details']['name'];
\Stripe\Customer::update($session['customer'].id,
  ["name" => $cardholderName]);

[0] - https://stripe.com/docs/api/payment_methods/object?lang=php#payment_method_object-billing_details-name

[1] - https://stripe.com/docs/api/expanding_objects?lang=php

这篇关于为什么 Stripe Checkout 不将客户名称添加到客户记录中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆