【发布时间】:2026-02-02 09:10:01
【问题描述】:
我有一个使用 Lumen 作为后端的移动应用 (Flutter)。对于付款,我使用 Stripe SDK for PHP。
收费成功后,我需要向用户发送发票。我理解它是这样工作的:
- 在 Stripe 中创建客户
- 使用
customer_id向客户收费 - 使用
customer_id创建发票项目 - Stripe 将使用客户的电子邮件自动通过电子邮件发送发票
我有两个功能:
public function addCard(Request $request) {
$user = User::find($user->id);
if (is_null($user->stripe_id) || empty($user->stripe_id)) {
$customer = \Stripe\Customer::create([
"name" => $user->name,
"email" => $user->email,
"description" => "Test",
]);
$user->stripe_id = $customer->id;
$user->save();
}
}
public function charge(Request $request) {
$charge = \Stripe\Charge::create([
'amount' => 2000,
'currency' => 'eur',
'customer' => $user->stripe_id,
'description' => 'Some description',
]);
\Stripe\InvoiceItem::create([
'customer' => $user->stripe_id,
'amount' => 2500,
'currency' => 'usd',
'description' => 'One-time setup fee',
'auto_advance' => true,
]);
}
它添加了用户,但没有信用卡详细信息。我应该传递哪些参数以便 Stripe 可以为指定用户创建卡令牌?因为它是一个移动应用程序,所以我不能为此目的使用 Stripe.js。
在调用收费函数的那一刻,我收到错误消息:
无法向没有有效卡的客户收费
这是我的第一个支付网关项目......所以非常感谢任何帮助。
【问题讨论】:
-
当用户输入信用卡详细信息时,您必须使用
stripe.js或 Stripe Checkout 来获取卡令牌。 -
我对移动SDK不熟悉,但应该有类似的东西。
标签: php flutter stripe-payments lumen