无法保存条带客户ID

时间:2016-06-23 20:32:26

标签: php jquery stripe-payments

正如标题所示,我无法使用Stripe将我的客户ID保存在我的数据库中。我正在创建一个注册表单,因此当用户注册该网站时,他们将拥有一个Stripe客户ID,以便将来付款。但是,当用户注册时,除客户ID外,所有数据都将保存到数据库中。

        // Create a Customer
        $customer = \Stripe\Customer::create(array(
          "source" => $token,
          "description" => "Example customer")
        );
         echo "customer ID is ".$customer->id;
         $newCustomer = $customer->id;
        // Charge the Customer instead of the card
        \Stripe\Charge::create(array(
          "amount" => 250, // amount in cents, again
          "currency" => "gbp",
          "customer" => $customer->id)
        );
}
?>
    <div class="container">
      <div class="login">
      <form action="register.php" method="POST">
        <div class="col-md-6 login-do">
            <div>
      <select name="title" type="text" class="dropdown-select">
          <option value="">Title</option>
          <option value="Mr">Mr</option>
          <option value="Miss">Miss</option>
          <option value="Mrs">Mrs</option>
          <option value="Ms">Ms</option>
      </select>
    </div>

      <div class="login-mail">
        <input name="first_name" type="text" placeholder="First Name" required="" oninvalid="this.setCustomValidity('Please Enter your first name')"/>
        <i  class="glyphicon glyphicon-user"></i>
      </div>
      <div class="login-mail">
        <input name="last_name" type="text" placeholder="Last Name" required="" oninvalid="this.setCustomValidity('Please Enter your last name')" />
      </div>
        <div class="login-mail">
          <input name="email" type="text" placeholder="E-Mail" />
          <i  class="glyphicon glyphicon-envelope"></i>
        </div>
        <div class="login-mail">
          <input name="pass" type="text" type="password" placeholder="Password" />
          <i  class="glyphicon glyphicon-lock"></i>
        </div>
        <div class="login-mail">
          <input name="retyped_password" type="text" type="password" placeholder="Retype Password" />
        </div>

      <a class="news-letter " href="#">
  <label class="checkbox1"><input type="checkbox" name="checkbox" ><i> </i>Forget Password</label>
  </a>
<label class="hvr-skew-backward">
<input type="submit" name="submit" value="Submit">
</label>

</div>
<div class="col-md-6 login-right">
<a href="login.html" class="hvr-skew-backward">Login</a>

</div>

<div class="clearfix"> </div>
</form>
</div>

</div>
      <?php
      if( isset($_POST['submit']) ){
        $title = $_POST['title'];
        $first_name = $_POST['first_name'];
        $last_name = $_POST['last_name'];
        $email = $_POST['email'];
        $password = $_POST['pass'];
        $retyped_password = $_POST['retyped_password'];
        $newCustomer = $_POST['newCus'];

2 个答案:

答案 0 :(得分:0)

您希望身份证来自哪里?您正在创建客户,但不在代码顶部包含其ID。它不应该包含在那里吗?

$customer = \Stripe\Customer::create(array(
  "source" => $token,
  "description" => "Example customer",
  "id" => "123")
);

答案 1 :(得分:0)

逻辑应该是这样的(只是伪代码):

  1. 在用户数据库中查找用户。
  2. 如果用户已经保存了Stripe客户ID,请从中设置$ customer_id。
  3. 如果不是:
    1. 致电\Stripe\Customer::create()
    2. 更新用户数据库以添加客户ID。
    3. 从返回的客户对象设置$ customer_id。
  4. 使用$ customer_id
  5. 创建费用