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

我正在尝试在向他们收费之前创建一个客户。我的档案里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:402

Type is:card_error

Code is:missing

Param is:card

Message is:Cannot charge a customer that has no active card

知道我在这里缺少什么吗?


POPMUISE
浏览 98回答 3
3回答

HUX布斯

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']),                         )                     );

动漫人物

以前不需要这个,但我添加了它,现在我的代码又可以工作了。不知道为什么:p\Stripe\Customer::createSource(    $stripe_id,    array('source' => $token));在我的之前添加了这个$charge = \Stripe\Charge::create()

弑天下

我在这里看到的唯一会导致该错误的路径是 $_POST['stripeToken'] 为空或 null。我没看到你在检查这一点。如果您查看 Stripe 仪表板日志,您应该能够看到脚本发送到“创建客户”端点的确切参数。除此之外,如果您仍然遇到困难,我会将请求 ID (req_xxx) 与您的示例代码一起发送给 Stripe 支持,以便有人可以仔细查看。
打开App,查看更多内容
随时随地看视频慕课网APP