2017-10-04 87 views
1

我見過很多類似的帖子,但找不到可以回答我的問題的帖子。我能夠檢索現有客戶及其卡片,但無法弄清楚如何使用此功能創建令牌。我發現的所有示例都需要卡信息(例如卡號cvv等),如果您通過API檢索卡,則無法訪問。我敢肯定,這是一些簡單的我失蹤:條紋PHP - 如何創建令牌與現有的客戶/卡

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

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

沒有必要爲已添加卡的現有客戶創建令牌。如果客戶擁有多張卡片,您只需將「源」設置爲現有卡片「ID」即可。 – Zico

+0

爲什麼你需要'token'?你已經擁有'customer_id'! –

回答

0

由於@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 
)); 
相關問題