Reputation: 5608
I have a stripe customer already added, I am figuring out to add new card to customer. I searched around but couldn't found anything confirmed to asnwer my following questions.
Is following is the correct way to add new card ?
$customer = \Stripe\Customer::retrieve(Auth::user()->stripe_key);
// Got the customer details successfully from the above call.
$card = $customer->cards->create(
array(
"card" =>
array(
"number"=> "4242424242424242",
"exp_month" => "12",
"exp_year" => "2016",
"cvc" => "123"
)
)
);
Upvotes: 1
Views: 2506
Reputation: 141
It seems like the answer from @karllekko is outdated now. I found the following that seems to work good currently.
$email = $_POST['email'];
$customers = \Stripe\Customer::all(['email' => $email]);
$customer = $customers->data[0];
$token = $_POST['stripeToken'];
$newCard = \Stripe\Customer::createSource($customer->id, ['source' => $token]);
https://docs.stripe.com/api/cards/create
Upvotes: 0
Reputation: 7198
Stripe does not have a direct form specifically for adding a new card to a customer, however you can use Checkout or Elements to collect the customer's card details.
The process for adding a new card to a customer would be as follows:
$token = $_POST['stripeToken']; #for example
$customer = \Stripe\Customer::retrieve(Auth::user()->stripe_key);
$customer->sources->create(array("source" => $token));
[0] - https://stripe.com/docs/checkout or https://stripe.com/docs/stripe-js/elements/quickstart
[1] - https://stripe.com/docs/api/php#create_card
Upvotes: 2