我在客户首次注册时添加了此信用卡
// 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) {
StripeStripe::setApiKey("sk_live_9N676756776");
try {
$t = StripeToken::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 = StripeCustomer::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)
我怎样才能让它成为新客户,以便它添加到现有客户中?因此,客户正在添加新卡(他们将拥有多个卡(
您直接通过 API 发送卡详细信息,这可能不是您想要做的事情。这意味着您会在服务器上获得卡号,这会产生一些严重的PCI合规性影响。我强烈建议您修改您的集成,以便您始终首先使用 Stripe.js 或 Stripe Checkout 客户端将卡详细信息直接发送到 Stripe 并获得唯一的卡令牌 (tok_XXX(,然后将其安全地发送到您的服务器以创建客户或添加为卡。
您可以在此处找到"卡更新"过程的说明;您需要的唯一区别是,而不是这样做来更换卡:
$cu->source = $_POST['stripeToken']; // obtained with Checkout
您要执行此操作以添加新的:
$customer->sources->create(array("source" => $t->id));