【问题标题】:Retrieving Customer Id from stripe to store in database从条带中检索客户 ID 以存储在数据库中
【发布时间】:2016-03-17 22:02:22
【问题描述】:

我正在使用 Stripe 作为我设计的网站的支付网关。我已经能够创建客户并向客户收费,但是我还想将客户 ID 存储在我的数据库中。如何检索客户 ID?这是我的代码 sn-p:

....

// Create a Customer
      $customer = \Stripe\Customer::create(array(
          'email' => $email,
          'card'  => $token,
          //'address_line1' =  $addr1 . " ". $addr2 . " ". $city . " " . " " .$country ,
          //'address_zip' = $postcode,
          'description' =>'Partnership' . " " . $fname . " " . $lname
      ));


      // Charge the Customer instead of the card
      $charge = \Stripe\Charge::create(array(
          'customer' => $customer->id,
          'amount'   => $amount,
          'currency' => 'gbp',
           "metadata" => array("order_id" => "6735")
      ));

     //retrieve customer id
     $customerId = \Stripe\Charge::retrieve($charge['customer']);

这是我收到的错误消息:

Notice: Undefined variable: charge 

Fatal error: Uncaught exception 'Stripe\Error\InvalidRequest' with message 'Could not determine which URL to request: Stripe\Charge instance has invalid ID: ' in ....
 1. enter code here

【问题讨论】:

  • 你是怎么解决这个问题的?我需要一点帮助

标签: stripe-payments


【解决方案1】:

将客户对象分配给$customer 变量后,您可以通过$customer->id 访问其ID。这就是您在费用创建请求中传递客户 ID 的操作。

您应该这样做以将 ID 保存在数据库中。

【讨论】:

    猜你喜欢
    • 2017-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 2021-06-07
    • 2019-05-17
    • 2017-06-08
    • 1970-01-01
    相关资源
    最近更新 更多