为了账号安全,请及时绑定邮箱和手机立即绑定

在 php stripe 上获取“无法向没有活动卡的客户收费”

在 php stripe 上获取“无法向没有活动卡的客户收费”

PHP
POPMUISE 2023-08-11 17:46:30
我正在尝试在向他们收费之前创建一个客户。我的档案里charge.php有这个。if (isset($_POST['stripeToken'])) {        \Stripe\Stripe::setApiKey('___stripe_secret_key_____');    $api_error = false;    $token = $_POST['stripeToken'];    try {                               $customer = \Stripe\Customer::create(array(                             "name" => $name,                             "email" => $email,                             "source" => $token,                             "metadata" => ['id' => $uid]                         ));                              $stripe_id = $customer->id;                              //update stripe ID to DB                         User::model()->updateByPk($uid, array('stripe_id' => $stripe_id));                                                   } catch(Exception $e) {                           $api_error = $e->getMessage();                     } 我正在使用自己的 HTML 表单来处理信用卡、到期日和抄送卡。并包含https://js.stripe.com/v3/在我的页面中。当我提交付款时出现此错误Charge creation failed! Status is:402Type is:card_errorCode is:missingParam is:cardMessage is:Cannot charge a customer that has no active card知道我在这里缺少什么吗?
查看完整描述

3 回答

?
HUX布斯

TA贡献1876条经验 获得超6个赞

source创建费用时也尝试在参数中传递 Stripe 令牌。


$charge = \Stripe\Charge::create(

                         array(

                             'customer' => $stripe_id, //customer id

                             'source' => $token,

                             'amount' => $_POST['stripe-amount'],

                             'currency' => strtolower($_POST['stripe-currency']),

                             'description' => 'US Report',

                             'metadata' => [

                                             'Currency' => $_POST['stripe-currency'],

                                             'Invoice' => $_POST['ref_id'],

                                         ],

                            'receipt_email' => $email,

                         ), array (

                             'idempotency_key' => preg_replace('/[^a-z\d]/im', '', $_POST['idempotency']),

                         )

                     );


查看完整回答
反对 回复 2023-08-11
?
动漫人物

TA贡献1815条经验 获得超10个赞

以前不需要这个,但我添加了它,现在我的代码又可以工作了。


不知道为什么:p


\Stripe\Customer::createSource(

    $stripe_id,

    array('source' => $token)

);

在我的之前添加了这个$charge = \Stripe\Charge::create()


查看完整回答
反对 回复 2023-08-11
?
弑天下

TA贡献1818条经验 获得超7个赞

我在这里看到的唯一会导致该错误的路径是 $_POST['stripeToken'] 为空或 null。我没看到你在检查这一点。如果您查看 Stripe 仪表板日志,您应该能够看到脚本发送到“创建客户”端点的确切参数。

除此之外,如果您仍然遇到困难,我会将请求 ID (req_xxx) 与您的示例代码一起发送给 Stripe 支持,以便有人可以仔细查看。


查看完整回答
反对 回复 2023-08-11
  • 3 回答
  • 0 关注
  • 96 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信