实时模式中存在类似的对象,但使用测试模式密钥来发出此请求。扔进php

Ade*_*ike 0 php stripe-payments

我正在尝试以条带实时模式付款,但显示以下错误:

PHP Fatal error: Uncaught (Status 400) (Request req_uocWWxAIPTJ6ZR) No such token: tok_1FbZniE3n36TXaJ5sMm5KSsX; 实时模式中存在类似的对象,但使用测试模式密钥来发出此请求。
扔进去

我已经在网上阅读了几个教程,但仍然没有正面。

 require_once "vendor/autoload.php";

\Stripe\Stripe::setApiKey('sk_live_xxxxxxxxxxxxxxxxxxxxxx');
 $token = $_POST['stripeToken'];


    // Add customer to stripe 
  $customer = \Stripe\Customer::create(array( 
        'email' => $email, 
        'source'  => $token 
    )); 

  // Unique order ID 
    $orderID = strtoupper(str_replace('.','',uniqid('', true))); 

    // Charge a credit or a debit card 
    $charge = \Stripe\Charge::create(array( 
        'customer' => $customer->id, 
        'amount'   => $amt, 
        "currency" => "usd",
        'description' => "Payment for ". $rooms, 
        'metadata' => array( 
            'order_id' => $orderID 
        ) 
    )); 

    // Retrieve charge details 
  $chargeJson = $charge->jsonSerialize(); 
Run Code Online (Sandbox Code Playgroud)

请问,我该怎么做才能解决这个问题?

koo*_*jah 5

此错误表明客户端使用 Live Publishable API 密钥 (pk_live_123) 来创建令牌,而服务器端使用测试密钥 API 密钥 (sk_test_123) 来创建费用。

我知道您的代码显示您正在使用 Live Secret 密钥,但事实并非如此。我在这里推荐的是将日志添加到您的 PHP 代码服务器端,以确保您正在运行的代码与您正在阅读的代码相同,并确认您使用的是正确的 API 密钥。