Stripe payments 为什么我的数组在使用PHP中的条带API创建客户时不返回任何数据?

Stripe payments 为什么我的数组在使用PHP中的条带API创建客户时不返回任何数据?,stripe-payments,php-5.6,Stripe Payments,Php 5.6,我试图在Stripe中创建客户和收费。 但是,当我试图打印$customer数组变量中的数组数据时,会得到一个空白页 我还尝试向charge.php页面回显字符串,以确保charge页面正常工作(回显“页面正常工作”);,确实如此。所以我知道这不是问题的一部分 权限似乎还可以 这些是有关文件的权限 -rw-rw-r--1沙盒管理员682 Apr 7 15:55 charge.php -rw-rw-r--1沙盒管理员1612年4月7日17:01 index.php 我已经检查了我的代码好几次了,但

我试图在Stripe中创建客户和收费。 但是,当我试图打印$customer数组变量中的数组数据时,会得到一个空白页

我还尝试向charge.php页面回显字符串,以确保charge页面正常工作(回显“页面正常工作”);,确实如此。所以我知道这不是问题的一部分

权限似乎还可以

这些是有关文件的权限 -rw-rw-r--1沙盒管理员682 Apr 7 15:55 charge.php -rw-rw-r--1沙盒管理员1612年4月7日17:01 index.php

我已经检查了我的代码好几次了,但是运气不好。 有人能帮我理解我可能做错了什么吗

注意:下面显示的代码都在相应文件类型的单独文件中,即所有PHP代码都在不同的.PHP文件中,JS在.JS文件中。 注释标记不在实际代码中。它们只是为了进行此对话而指示每个文件的起始位置

     <!-- index.php code below -->
     <html>
     <body>
        <div class="container">
        <h2 class="my-4 text-center">Title of Product Page Here</h2>
            <form action="./charge.php" method="post" id="payment-form">
            <div class="form-row">
            <input type="text" class="form-control mb-3 StripeElement StripeElement--empty" name="first_name" placeholder="First Name">
            <input type="text" class="form-control mb-3 StripeElement StripeElement--empty" name="last_name" placeholder="Last Name">
            <input type="email" class="form-control mb-3 StripeElement StripeElement--empty" name="email" placeholder="Email Address">
                <div id="card-element" class="form-control">
                <!-- A Stripe Element will be inserted here. -->
                </div>
    
                <!-- Used to display form errors. -->
                <div id="card-errors" role="alert"></div>
            </div>
    
            <button>Submit Payment</button>
            </form>
        </div>
    
        <script src="https://js.stripe.com/v3/"></script>
        <script src="js/charge.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    </body>
    </html>

    <!-- charge.php code below -->
    <!-- Note: Both the Stripe test Key and Stripe PW were masked per Stripe recommendation. Actual test key and password used in real code --> 

    <?php
    require_once('vendor/autoload.php');
    \Stripe\Stripe::setApiKey('sk_test_################');
    
    // Sanitize 
    $POST = filter_var_array($_POST, FILTER_SANITIZE_STRING);
    $first_name = $POST['first_name'];
    $last_name = $POST['last_name'];
    $email = $POST['email'];
    $token = $POST['stripeToken'];
    
    // Create customer 
    $customer = \Stripe\Customer::create(array(
        "email" => $email,
        "source" => $token
    ));
    
    // Charge customer
    $charge = \Stripe\Charge::create(array(
        "amount" => 5000,
        "currency" => "usd",
        "description" => "Audio Loops Pack 2019",
        "customer" => $customer->id
     ));
    
    print_r($customer);


    <!-- charge.js code below -->

    // Create a Stripe client.
    var stripe = Stripe('pk_test_################');
    
    // Create an instance of Elements.
    var elements = stripe.elements();
    
    // Custom styling can be passed to options when creating an Element.
    // (Note that this demo uses a wider set of styles than the guide below.)
    var style = {
      base: {
        color: '#32325d',
        fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
        fontSmoothing: 'antialiased',
        fontSize: '16px',
        '::placeholder': {
          color: '#aab7c4'
        }
      },
      invalid: {
        color: '#fa755a',
        iconColor: '#fa755a'
      }
    };
    
    //Style button 
    document.querySelector('#payment-form button').classList ='btn btn-primary btn-block mt-4';
    
    // Create an instance of the card Element.
    var card = elements.create('card', {style: style});
    
    // Add an instance of the card Element into the `card-element` <div>.
    card.mount('#card-element');
    
    // Handle real-time validation errors from the card Element.
    card.addEventListener('change', function(event) {
      var displayError = document.getElementById('card-errors');
      if (event.error) {
        displayError.textContent = event.error.message;
      } else {
        displayError.textContent = '';
      }
    });
    
    // Handle form submission.
    var form = document.getElementById('payment-form');
    form.addEventListener('submit', function(event) {
      event.preventDefault();
    
      stripe.createToken(card).then(function(result) {
        if (result.error) {
          // Inform the user if there was an error.
          var errorElement = document.getElementById('card-errors');
          errorElement.textContent = result.error.message;
        } else {
          // Send the token to your server.
          stripeTokenHandler(result.token);
        }
      });
    });
    
    // Submit the form with the token ID.
    function stripeTokenHandler(token) {
      // Insert the token ID into the form so it gets submitted to the server
      var form = document.getElementById('payment-form');
      var hiddenInput = document.createElement('input');
      hiddenInput.setAttribute('type', 'hidden');
      hiddenInput.setAttribute('name', 'stripeToken');
      hiddenInput.setAttribute('value', token.id);
      form.appendChild(hiddenInput);
    
      // Submit the form
      form.submit();
    }


这里是产品页面的标题
付款

你的
js/charge.js
代码是什么?原因可能是CreateCustomer和ChargeCustomer从未被调用。您可以检查网络选项卡以查看HTTP流量,并检查控制台选项卡以查看是否存在任何javascripterrors@wsw我在上面的代码示例中添加了charge.js。我可以在charge.php处理中回显令牌。它很好用。但是如果我在PHP脚本中添加$customer和$charge,我就看不到令牌、$customer或$charge数据。因此,我认为js/charge.js文件可以正常工作,但当我创建一个客户或charge.put a die()时,一定是出了问题;打印后(客户)@斯拉夫人我在print_r()之后尝试了die()方法。相同的空白页。@byiton,您能在
//创建客户
//向客户收费
之前打印出您的值并打印出POST表单吗。我很确定客户创建没有被调用。你的
js/charge.js
代码是什么?原因可能是CreateCustomer和ChargeCustomer从未被调用。您可以检查网络选项卡以查看HTTP流量,并检查控制台选项卡以查看是否存在任何javascripterrors@wsw我在上面的代码示例中添加了charge.js。我可以在charge.php处理中回显令牌。它很好用。但是如果我在PHP脚本中添加$customer和$charge,我就看不到令牌、$customer或$charge数据。因此,我认为js/charge.js文件可以正常工作,但当我创建一个客户或charge.put a die()时,一定是出了问题;打印后(客户)@斯拉夫人我在print_r()之后尝试了die()方法。相同的空白页。@byiton,您能在
//创建客户
//向客户收费
之前打印出您的值并打印出POST表单吗。我相当肯定,不知何故,客户创建没有被调用。