亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 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條經驗 獲得超8個贊

我在這里看到的唯一會導致該錯誤的路徑是 $_POST['stripeToken'] 為空或 null。我沒看到你在檢查這一點。如果您查看 Stripe 儀表板日志,您應該能夠看到腳本發送到“創建客戶”端點的確切參數。

除此之外,如果您仍然遇到困難,我會將請求 ID (req_xxx) 與您的示例代碼一起發送給 Stripe 支持,以便有人可以仔細查看。


查看完整回答
反對 回復 2023-08-11
  • 3 回答
  • 0 關注
  • 199 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號