- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试设置一个 Stripe webhook,它会在发生“charge.succeeded”事件后发送电子邮件。当我在 Stripe 上测试 webhook 时,我不断收到通用的“错误 500”。我对 Stripe 很陌生,我真的被困在这里。
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
require_once('stripe/lib/Stripe.php');
Stripe::setApiKey("XXXYYYZZZ");
// retrieve the request's body and parse it as JSON
$body = @file_get_contents('php://input');
$event_json = json_decode($body);
// for extra security, retrieve from the Stripe API
$event_id = $event_json->id;
$event = Stripe_Event::retrieve($event_id);
// This will send receipts on successful charges
if ($event_json->type == 'charge.succeeded') {
// This is where we e-mail the invoice.
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'abc@gmail.com'; // SMTP username
$mail->Password = 'password!'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
$mail->From = 'abc@gmail.com';
$mail->FromName = 'John Doe';
$mail->addAddress('email@stanford.edu, John Doe'); // Add a recipient
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Your webhook works!!!!!';
$mail->Body = "The message sent!";
if(!$mail->send()) {
echo 'Message could not be sent. Contact us at hello@beerboy.co.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
}
?>
最佳答案
检查此代码:
// retrieve the request's body and parse it as JSON
$body = @file_get_contents('php://input');
$event_json = json_decode($body);
// for extra security, retrieve from the Stripe API
$event_id = $event_json->id;
$event = Stripe_Event::retrieve($event_id);
$body
使用
php://input
定义,它想从提交给你的页面的 POST 或 GET 信息中读取,而不是 Stripe 。
See here . POST 或 GET 中的任何内容显然都是无效的 JSON 或包含无效的
id
.
json_decode($body)
,您正在尝试对 POST 或 GET 中的内容进行 json_decode,而不是从 Stripe 获得的内容。
$event_json->id
不存在或无效,所以
$event_id
不存在或无效,因此当您调用
Stripe_Event::retrieve($event_id);
时,Stripe 会翻转.
var_dump($event_json); die();
在您制作
Stripe_Event
之前打电话看看你的要求是什么。
id
参数等)。
关于php - Stripe Webhook 错误 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20055002/
我可以在不使用收款人信用卡号的情况下将资金从我的 Stripe 账户发送到另一个 Stripe 账户吗?在我的网站中,我希望管理员将资金从他的帐户转移到用户的条纹帐户(而不是用户的银行帐户)。用户的
我曾经有 Angular Stripe Checkout 表单,我正在尝试将表单更新为新的 Stripe Card Elements这是最近推出的。 删除表单输入字段并将其替换为条纹卡片元素后,我的表
我的目标是为产品创建一个简单的支付页面。 在官方文档中,它说在服务器端需要生成 token 才能创建交易,使用: stripe.paymentIntents.create({ amount: re
我是 strip 的新手,打算使用 strip token /收费 api,但 strip 文档说 paymentIntent api 是新的方法。我可以使用任何人吗或 PaymentIntent 是
我正在开发一个项目,我们正在为 Node 使用 Stripe 库。我们还想在这个项目上使用 TypeScript。 我发现 Stripe 没有提供官方 TypeScript 定义,但我找到了一些社区定
通常在使用 stripe 时我可以创建产品并添加税率、运费。付款后我可以创建发票。我想在使用连接帐户时做同样的事情。在我的应用程序中,我希望用户创建商店,并且该商店的产品将保存到他们连接的 Strip
假设我们已经设置了一个 Stripe 订阅计划。即 30 美元/月。 (注意:账单/账户信息存储在 Stripe 上。) 假设我们想为客户提供提前购买一年服务的选项,如果他们这样做,他们只需支付 25
我们知道 Stripe 支持多张信用卡。一个是 default_card。关于这张 Stripe 多张卡片,我需要知道一些答案。 假设我想向我的客户收费,他的 Stripe 个人资料中有 3 张信用卡
有没有办法根据为特定客户生成的最后一张发票过滤发票结果? 穿过 Stripe documentation我可以看到有可能获得即将到来的发票,但我找不到获得最后生成的发票的方法。 最佳答案 如果您使用
我正在使用 Stripe 为客户订阅月度计划。中途客户可能会减少计划数量。所以,在即将开出的发票有时会是负数。 带有负金额的发票行是否意味着客户将这些金额退还到他们的卡中? 谢谢 最佳答案 是的,负发
我正在使用定期计划和电子邮件地址在 Stripe(使用测试模式)中创建客户。到目前为止,一切都按我的预期工作:当客户创建并注册到定期计划时,他们会自动在计划的第一期收费。我所拥有的几乎是逐字逐句wha
我正在尝试使用 Stripe checkout.js 订阅,然后使用 PHP 订阅客户。我的问题是获取他们的电子邮件地址。在文档中找不到任何有用的东西。 文档在这里:https://stripe.co
我在两部分付款过程中使用 Stripe。 IE。 使用 capture = false 对调用 Charge 对象的卡进行预授权 做一些数据库工作 使用电荷捕获为卡充电 如果第 2 步失败(即数据库工
我们使用 Stripe 作为支付网关,我们有一个年度计划,即该计划的计费周期为 1 年。 在计费周期内,用户可以更新选择更多席位,这将导致增加订阅计划的数量。 Subscription subscri
我正在使用 PHP Stripe Payment 表单来收款。付款似乎通过 OK 并在成功完成后将用户带到确认页面。我处于测试模式,能够看到显示在仪表板“付款”部分的付款。但是,当我单击仪表板的“主页
我正在构建一个市场应用程序。我正在使用 Stripe 接受买家付款并将百分比转移给卖家。但是,stripe 只能让您从 Stripe 余额中转移。因此,如果我接受需要 2 个工作日才能显示在我的 st
正如我们所知,Stripe 每张信用卡收费 2.9% + 30 美分。因此,对于每 1 美元的交易,Stripe 大约需要 33 美分。有没有办法批量处理多个 1 美元的交易(由同一客户)并完全收费?
我有一个关于 Stripe 的订阅计划,并将其用于按座位定价。 具体用例是: 客户之前已付款,因此数据库中的客户 ID 和订阅 ID 他们在一个月内删除了所有用户 下个月他们又添加了一个用户 我希望结
在Stripe API文档中,它们显示您可以在客户上应用优惠券。 cust = Stripe::Customer.retrieve("cus_asdasdad") cust.coupon = "COU
我在订阅中添加发票项目时遇到问题,目前无法正常工作。 我已经在 strip 上创建了一个发票项目,并且希望该发票项目包含在定期付款中 这是我的代码,它在第一个发票上添加了一个发票项目,但在下一个发票上
我是一名优秀的程序员,十分优秀!