2016-04-29 97 views
0

enter image description here如何創造客戶後檢索條紋對象條紋客戶ID

<?php 
require_once('Stripe/lib/Stripe.php'); 
Stripe::setApiKey(trim($pkey)); 

try 
{ 
    $customer = Stripe_Customer::create(array(
    'email' => $_POST['stripeEmail'], 
    'source' => $_POST['stripeToken'], 
    'plan' => trim($plan) 
)); 

} 
catch(Exception $e) 
{ 
    //header('Location:oops.html'); 
    error_log("unable to sign up customer:" . $_POST['stripeEmail']. 
    ", error:" . $e->getMessage()); 
} 
?> 

在這裏,我想獲得客戶ID,所以我打印$客戶對象時,它給人的條紋對象,但我不不知道如何從結果中檢索客戶ID。 如果有人知道請幫助我。 在此先感謝

回答

2

只需使用以下代碼行即可獲取客戶ID。

$customer = $stripe->customers()->create([ 
     'email' => $_POST['stripeEmail'], 
     'source' => $_POST['stripeToken'], 
     'plan' => trim($plan) 
    ]); 

echo $customer['id']; 

這會幫助你。

+2

感謝您的回覆我試過$ customer-> id它適用於我 –

+0

請接受我的anser如果它可以幫助你。 –

+0

@ravikumar請接受我的回答。它真的鼓勵他人的貢獻。謝謝。 –