2017-08-09 51 views
1

我有這樣的信用卡將在客戶最初跡象了添加信用卡現有用戶

// CREDIT CARD CODE (STRIPE) 

$q_get_user = "select * from users where `id` = '$user_id' "; 
$r_get_user = mysqli_query($conn,$q_get_user); 
$get_user = mysqli_fetch_assoc($r_get_user); 


if(1) { 
    \Stripe\Stripe::setApiKey("sk_live_9N676756776"); 


    try { 

     $t = \Stripe\Token::create(
       array(
         "card" => array(
           "name" => $get_user['first_name']." ".$get_user['last_name'], 
           "number" => $credit_num, 
           "exp_month" => $credit_month, 
           "exp_year" => $credit_year, 
           "cvc" => $credit_ccv 
         ) 
       ) 
     ); 

     if($t->id != '') { 
      try { 
       $c = \Stripe\Customer::create(array(
         "description" => "Customer for ".$get_user['email'], 
         "source" => $t->id) 
       ); 
       if($c->id != '') { 
        $stripe_token_response = mysqli_real_escape_string($conn, json_encode($t)); 
        $stripe_token_id = mysqli_real_escape_string($conn, $t->id); 
        $stripe_customer_response = mysqli_real_escape_string($conn, json_encode($c)); 
        $stripe_customer_id = mysqli_real_escape_string($conn, $c->id); 
        $stripe_card_id = mysqli_real_escape_string($conn, $c->default_source); 
       } 

      } catch (Exception $e) { 
       //print_r($e->getMessage()); 
       header('Location: /credits?error=cc&message='.urlencode($e->getMessage()));die; 
      } 
     } 

    } catch (Exception $e) { 
     //print_r($e->getMessage()); 
     header('Location: /credits?error=cc&message='.urlencode($e->getMessage()));die; 

    } 



} 

// END - CREDIT CARD CODE (STRIPE) 

我怎樣才能使之成爲一個新客戶的內部爲它添加到現有的客戶?因此,客戶正在添加新卡(他們將擁有多個卡)

回答

1

您正在通過API直接發送卡詳細信息,這可能不是您想要執行的操作。這意味着你的服務器上的卡號有一些serious PCI compliance implications。我強烈建議您修改您的集成,以便首先通過使用Stripe.jsStripe Checkout客戶端將卡詳細信息直接發送到Stripe並獲取一個唯一的卡令牌(tok_XXX),然後您可以安全地發送到您的服務器創建客戶或添加爲卡。

你可以找到'卡更新'過程的描述here;你需要的唯一的區別是,而不是這樣做是爲了更換卡:

$cu->source = $_POST['stripeToken']; // obtained with Checkout 

你想do this添加一個新的:

$customer->sources->create(array("source" => $t->id)); 
相關問題