2016-11-22 1 views
2

次のコードを使用してストライプユーザーを作成しています。PHPのストライプエラー処理エラー

カード番号が間違っているとエラーを処理できません。

 $stripeClassesDir = __DIR__ . '/stripe-php-master/lib/'; 
     $stripeUtilDir = $stripeClassesDir . 'Util/'; 
     $stripeErrorDir = $stripeClassesDir . 'Error/'; 
     $stripeHttpClientDir = $stripeClassesDir . 'HttpClient/'; 

     set_include_path($stripeClassesDir . PATH_SEPARATOR . $stripeUtilDir . PATH_SEPARATOR . $stripeErrorDir . PATH_SEPARATOR . $stripeHttpClientDir); 

     function __autoload($class) 
     { 
      $parts = explode('\\', $class); 
      require end($parts) . '.php'; 

     } 

     try { 

       \Stripe\Stripe::setApiKey("sk_test_key"); 

       $t = \Stripe\Token::create(array("card" => array(
        "number" => $cardNumber, 
        "exp_month" => $cardMonth, 
        "exp_year" => $cardYear, 
        "cvc" => $cardCVC))); 

       //echo $t; 

      } catch(\Stripe\Error\Card $e) { 
      // Since it's a decline, \Stripe\Error\Card will be caught 
      $body = $e->getJsonBody(); 
      $err = $body['error']; 

      print('Status is:' . $e->getHttpStatus() . "\n"); 
      print('Type is:' . $err['type'] . "\n"); 
      print('Code is:' . $err['code'] . "\n"); 
      // param is '' in this case 
      print('Param is:' . $err['param'] . "\n"); 
      print('Message is:' . $err['message'] . "\n"); 
     } catch (\Stripe\Error\RateLimit $e) 
     { 
      // Too many requests made to the API too quickly 
     } catch (\Stripe\Error\InvalidRequest $e) { 
      // Invalid parameters were supplied to Stripe's API 
     } catch (\Stripe\Error\Authentication $e) { 
      // Authentication with Stripe's API failed 
      // (maybe you changed API keys recently) 
     } catch (\Stripe\Error\ApiConnection $e) { 
      // Network communication with Stripe failed 
     } catch (\Stripe\Error\Base $e) { 
      // Display a very generic error to the user, and maybe send 
      // yourself an email 
     } 
     catch (Exception $e) { 
      // Something else happened, completely unrelated to Stripe 
     } 

このコードは、次のエラーを示します。

Fatal error: Class 'Stripe\Error\Card' not found in /home/user/public_html/stripe-php-master/lib/ApiRequestor.php on line 114

+0

'クラスのストライプ\エラー\カード」ではありません'Stripe \ Error \ Card'クラス – bassxzero

+0

を見つけることができませんが、間違ったカード番号をチェックしているときにこのエラーが発生します。私が間違って入力したとき、または2桁の数字しか入力しない。この問題を解決するために私を助けてください。パスエラーの場合は?どのように同じのためのパスを設定する? – web

+0

は、エラーの意味を変更しません。 – bassxzero

答えて

1

StripeのPHPライブラリが正しく読み込まれていません。 READMEファイルに示されているように、init.phpファイルをライブラリのフォルダのルートに含める必要があります。

私は

$stripeClassesDir = __DIR__ . '/stripe-php-master/lib/'; 
$stripeUtilDir = $stripeClassesDir . 'Util/'; 
$stripeErrorDir = $stripeClassesDir . 'Error/'; 
$stripeHttpClientDir = $stripeClassesDir . 'HttpClient/'; 

set_include_path($stripeClassesDir . PATH_SEPARATOR . $stripeUtilDir . PATH_SEPARATOR . $stripeErrorDir . PATH_SEPARATOR . $stripeHttpClientDir); 

の交換をお勧めしたい:found`はカード番号が間違っていたという意味ではありません、それはPHP wasnを意味

require_once('./stripe-php-master/init.php'); 
+0

ありがとうYwainそれは私のために働く。再びありがとう! – web