使用Php在Stripe中使用Checkout

时间:2016-07-15 11:44:05

标签: php laravel stripe-payments

我试图使用php整合Stripe。 在进行一些初始配置时,如下面的代码所示:



<?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>';
?>
&#13;
&#13;
&#13;

我将此错误视为输出

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

有人可以告诉我如何处理这个错误吗? 我是Stripe和PHP的新手。

1 个答案:

答案 0 :(得分:1)

检查您的帖子数据。

<?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>';
    }
?>