TomFree
TomFree

Reputation: 1389

Stripe how to set country when creating subscription with decent ux and differen auth providers?

I want users that authenticate via signup (email/pwd) or google auth to be able to create subscription using creditcards/iban debit etc. The problem I face is getting the country informaiton once (dont wanna annoy users obviously with entering it multiple times) and hand it to stripe before setting up subscription.

The reason is that stripe needs the country to be assigned to the user when creating subscriptions to calculate taxes and stuff and otherwise fails.

In its elements form to setup setupintents/payment methods for subscriptions stripe has a country input element but i dont have direct access to the input for security reasons. Then the input is sent to stripe when processing the setupintent and creating the payment method in the stripe backend. However I am not sure that when creating the subscription the payment method has been created entirly and the info is somehow available.

So I kind of see 3 options

  1. get the country info from stripe elements somehow - there seems to be no api though - which to me makes sense for security puposes.

  2. have the user entry country twice - once at signup and once when entering payment details. Which would be especially anoying when using Google Auth as AuthProvider since users would not expect to need to complete yet another form

  3. use setup intent events completed or requires_action to get the country info from the setupintent. However those events are not guaranteed to be called before the redirect to succesUrl at which i create the subscription. Alternatively I could trigger subscription creation when those events happen - however then redirect may happen and user expected to be subscribed but isn't

So all in all it seems there is no good option - or am I missing sth?

Cheers Tom

Upvotes: 0

Views: 454

Answers (1)

os4m37
os4m37

Reputation: 1133

One option is to create a Stripe Customer and set it's address (using the information you collected from Signup)

curl https://api.stripe.com/v1/customers \
  -u "sk_test_51LFx4JF1SIVBSMvIt9b4wQdU6HaIJihHN3trk4Gsatf6s4HhFq8hUnzNXfabz4e3G7DohAQQr1saKyb823PPBGck00zimBeeF9:" \
  -d description="a new user" \
  --data-urlencode email="[email protected]" \
  -d payment_method=pm_1FU2bgBF6ERF9jhEQvwnA7sX \
  -d "address[country]"=US \
  -d "address[postal_code]"=94103 \
  -d "expand[]"=tax

https://stripe.com/docs/billing/taxes/collect-taxes?tax-calculation=stripe-tax#create-a-customer

Upvotes: 0

Related Questions