0

Im trying to integrate Stripe using php. When making some initial configurations like in the code below:

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

  $token  = $_POST['stripeToken'];

  $customer = \Stripe\Customer::create(array(
      'email' => 'customer@example.com',
      'source'  => $token
  ));

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

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

I take this error as output

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

Can someone show me how to deal with this error? Im new at Stripe and PHP.

user6591546
  • 25
  • 1
  • 7
  • Possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Alessandro Da Rugna Jul 15 '16 at 12:48

1 Answers1

1

Check your post data.

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

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

        $customer = \Stripe\Customer::create(array(
        'email' => 'customer@example.com',
        'source'  => $token
        ));

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

        echo '<h1>Successfully charged $50.00!</h1>';
    }
?>
Volkan Yılmaz
  • 539
  • 3
  • 10