Reputation: 2848
I can charge a user and save the card for future charges. To set the default card for the user I'm doing Stripe::Customer.update
(see below)
def new
@payment_intent = Stripe::PaymentIntent.create(amount: 100,
currency: 'usd',
customer: current_user.stripe_id,
setup_future_usage: 'off_session')
end
def create
@payment_intent = Stripe::PaymentIntent.retrieve({id: params[:payment_intent_id])
if @payment_intent.status == "succeeded"
Stripe::Customer.update(current_user.stripe_id, invoice_settings: { default_payment_method: @payment_intent.payment_method })
#do stuff
else
render :new
end
end
Is there a way to specify that the card being used should be the default for the user when creating the payment intent (instead of calling Stripe again with Stripe::Customer.update)?
Upvotes: 1
Views: 1213
Reputation: 5847
There is no concept of a "default" PaymentMethod with PaymentIntents. When creating a new PaymentIntent with a saved card you'd have to specify both the Customer ID and the ID of a PaymentMethod that's attached to the Customer: https://stripe.com/docs/payments/save-during-payment#web-create-payment-intent-off-session
Upvotes: 3