2016-07-15 17 views
0

phpを使用してストライプを統合しようとしています。以下のコードのようにいくつかの初期設定を行うとき は:PHPを使用したスト​​ライプでのチェックアウトの使用

<?php 
 
    require_once('./elda.php'); 
 

 
    $token = $_POST['stripeToken']; 
 

 
    $customer = \Stripe\Customer::create(array(
 
     'email' => '[email protected]', 
 
     'source' => $token 
 
)); 
 

 
    $charge = \Stripe\Charge::create(array(
 
     'customer' => $customer->id, 
 
     'amount' => 5000, 
 
     'currency' => 'usd' 
 
)); 
 

 
    echo '<h1>Successfully charged $50.00!</h1>'; 
 
?>

私は出力

Notice: Undefined index: stripeToken in C:\xampp\htdocs\laravel\stripe\public\2.php on line 4 

としてこのエラーを取る誰かがこのエラーに対処する方法私を見ることができますか? StripeとPHPで新しいです。

+0

[PHP: "注意:未定義の変数" と "注意:未定義のインデックス"]の可能な重複(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice -undefined-index) –

答えて

1

あなたの投稿データを確認してください。

<?php 
    require_once('./elda.php'); 

    if (isset($_POST['stripeToken'])){ 
     $token = $_POST['stripeToken']; 

     $customer = \Stripe\Customer::create(array(
     'email' => '[email protected]', 
     'source' => $token 
     )); 

     $charge = \Stripe\Charge::create(array(
     'customer' => $customer->id, 
     'amount' => 5000, 
     'currency' => 'usd' 
     )); 

     echo '<h1>Successfully charged $50.00!</h1>'; 
    } 
?> 
関連する問題