简体   繁体   English

如何从 Stripe webhook/Payment Intent 获取更多数据

[英]How to get more data from Stripe webhook/Payment Intent

I'm testing Stripe webhooks on my localhost using the Stripe CLI, and so far I've managed to use it to successfully return a PaymentIntent object that contains most of the data I need to capture and persist to my database, but I'm still not able to get a few details that the documentation says should be in the Payment Intent , namely:我正在使用 Stripe CLI 在我的本地主机上测试 Stripe webhooks,到目前为止,我已经成功地使用它成功返回了一个 PaymentIntent object,其中包含我需要捕获并保存到我的数据库中的大部分数据,但我仍然无法获得文档说应该在 Payment Intent 中的一些细节,即:

  • The payment method type that the user paid with用户支付的支付方式类型
  • The postcode entered by the user in the Stripe Payment Element form用户在 Stripe Payment Element 表单中输入的邮政编码

I'm using the following code to get these two pieces of information, which are also the only lines in the function that don't work when the payment_intent.succeeded webhook is triggered:我正在使用以下代码获取这两条信息,这也是 function 中唯一在触发payment_intent.succeeded webhook 时不起作用的行:

// Webhooks by default return an Event object that is stored in 
// $payload object, so ["data"]["object"] should return the 
// PaymentIntent object corresponding to the retrieved Event object

$paymentIntent = $this->webhookCall->payload["data"]["object"]; 

...

$transaction->payment_method = $paymentIntent["charges"]["data"]["payment_method_details"]["type"]; 
$transaction->postcode = $paymentIntent["charges"]["data"]["billing_details"]["address"]["postal_code"];

These lines result in "undefined index" errors in the Laravel log file, which seems to indicate they either don't exist in the PaymentIntent or something is wrong with how I'm accessing them.这些行导致 Laravel 日志文件中出现“未定义索引”错误,这似乎表明它们在 PaymentIntent 中不存在或者我访问它们的方式有问题。

I haven't used stripe but what I see from there documentation link you shared.我没有使用过 stripe,但我从您共享的文档链接中看到了什么。 The ["data"] property is not an object but an array which means you've to access it like an array. ["data"] 属性不是 object 而是一个数组,这意味着您必须像访问数组一样访问它。 So your code should look something like this.所以你的代码应该看起来像这样。

$transaction->payment_method = $paymentIntent["charges"]["data"][0]["payment_method_details"]["type"]; 
$transaction->postcode = $paymentIntent["charges"]["data"][0]["billing_details"]["address"]["postal_code"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Stripe API,如何获取创建 payment_intent Object 的 Checkout Session 的 session_id,来自 payment_intent.succeeded Webhook - With Stripe API, How To Get session_id of Checkout Session That Created a payment_intent Object, From payment_intent.succeeded Webhook 如何从 Stripe Payment Element 获取支付数据 - How to capture payment data from Stripe Payment Element 从Stripe不正确的层次结构中的invoice.payment_failed Webhook获取订阅ID - Get subscription id from invoice.payment_failed webhook in Stripe incorrect Hierarchy Stripe - 如何在 webhook 中获取价格? - Stripe - how to get the price in the webhook? 使用 PHP 从 Stripe Webhook JSON 获取数据 - Get Data from Stripe Webhook JSON using PHP 如何使用 symfony 和意图支付 API 完成我的条带支付? - How to complete my stripe payment with symfony and intent payment API? 如何使用“条带化付款”获取付款明细? - how to get detail of payment on using 'stripe payment'? 如何从 webhook 获取数据? - how to get the data from a webhook? 使用条带,是否可以使用“result.setupIntent.payment_method”从付款方式 object 中获取所有数据? - Using stripe, is it possible to get all of the data from the Payment Method object using “result.setupIntent.payment_method”? 可以从条带标准中检索付款意图吗? - It's possible to retrieve a payment intent from stripe standard?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM