php - 在 Slim PHP 中处理 Stripe 错误
问题描述
我正在努力寻找一种解决方案来处理来自 Slim 中 Stripe 的错误消息。当我收到回复时,Slim 正在加载:
<h1>Slim Application Error</h1>
<p>The application could not run because of the following error:</p>
<h2>Details</h2>
<div><strong>Type:</strong> Stripe\Exception\InvalidRequestException</div>
<div><strong>Message:</strong> Must provide source or customer.</div>
我似乎无法获得错误的 JSON 表示。
我有一个 try/catch 块,但似乎没有什么不同。
try {
$charge = \Stripe\Charge::create([
"amount" => $total_amount * 100,
"currency" => "aud",
"customer" => $customer_id,
"description" => 'Payment for order ID #' . $request['orderID']
]);
} catch (\Stripe\Error\Card $e) {
// Handle "hard declines" e.g. insufficient funds, expired card, etc
// See https://stripe.com/docs/declines/codes for more
}
有任何想法吗?
解决方案
尝试捕获超薄错误页面中提到的异常类型“Stripe\Exception\InvalidRequestException”
try {
$charge = \Stripe\Charge::create([
"amount" => $total_amount * 100,
"currency" => "aud",
"customer" => $customer_id,
"description" => 'Payment for order ID #' . $request['orderID']
]);
} catch (\Stripe\Exception\InvalidRequestException $e) {
// Handle "hard declines" e.g. insufficient funds, expired card, etc
// See https://stripe.com/docs/declines/codes for more
}
推荐阅读
- html - 更改 Kendo UI Timepicker 突出显示的文本颜色
- homebrew - 如何将自制软件包标记为候选发布?
- api - 使用证书测试 API
- wordpress - Wordpress - 重写 url 中的分类值以进行翻译
- github - 如何解决 GitHub 保护分支上的合并冲突。?
- vba - 如何用vba代码打开外部访问数据库并最大化
- r - R chisq.test - 通过df自动化,每个变量都有,df有数据,不是计数,宽格式
- excel - Excel 索引匹配 - 最大、第二大、第三大且没有重复匹配
- python - 如何使用 django 从用户输入中计算未保存到数据库的值和数据库中的值
- clojure - 使用 environ 访问 leiningen project.clj 中的环境变量时出错