【问题标题】:Stripe PHP - how to create token with existing customer/cardStripe PHP - 如何使用现有客户/卡创建令牌
【发布时间】:2017-10-04 06:11:25
【问题描述】:

我看过很多类似的帖子,但找不到能回答我问题的帖子。我能够检索现有客户及其卡,但无法弄清楚如何使用它创建令牌。我找到的所有示例都需要卡信息(例如卡号 cvv 等),如果您通过我无权访问的 API 检索卡,则需要这些信息。我敢肯定这是我缺少的一些简单的东西:

$customer = \Stripe\Customer::retrieve($customer_id);
$card = $customer->sources->retrieve($card_id);

$token = \Stripe\Token::create(array(
      "card" => // What to put here???
    )
  );

【问题讨论】:

  • 添加卡的现有客户无需创建令牌。如果客户拥有多张卡,您只需将source 设置为现有卡id 即可。
  • 为什么需要token??你已经拥有customer_id !!!

标签: php stripe-payments


【解决方案1】:

正如@zico 在评论中解释的那样,一旦您将卡片与客户对象一起保存,就无需创建新令牌。您可以在customer 参数中简单地传递客户的ID,并且可以选择在source 参数中传递卡的ID(如果客户有多张卡并且您想从非默认卡中收费)。

$charge = \Stripe\Charge::create(array(
    "amount" => 400,
    "currency" => "usd",
    "customer" => "cus_...", // ID of the customer you want to charge
    "source" => "card_...", // ID of the specific card, only needed if the customer has
                            // multiple cards and you want to charge a different
                            // card than the default one
));

【讨论】:

    猜你喜欢
    • 2018-05-30
    • 2014-02-22
    • 2019-07-09
    • 2020-08-20
    • 2018-11-20
    • 1970-01-01
    • 2014-03-30
    • 2014-03-08
    • 2021-03-13
    相关资源
    最近更新 更多