0
votes

I am trying to pass a FirebaseFirestore User Uid to a Stripe / firestore cloud function.

So I would have an https query like following :

https://connect.stripe.com/express/oauth/authorize?response_type=code&client_id={accountid}&scope=read_write to open in a Webview

Here is my function

exports.connectStripeExpressAccount = functions.https.onRequest((req, res) =>{
  console.log('query state is  ----> ' + req.query.state);
  const authCode = req.query.code;
  return stripe.oauth.token({
    grant_type: 'authorization_code',
    code: authCode,
  }).then(async response => {
      var connected_account_id = response.stripe_user_id;
      const uid = req.query.state
      const writeResult = await admin.firestore().collection('Registration').doc(uid)
                           .set({'customer_id': connected_account_id});
      return res.send("Well done, account integration is completed. You can now close the window and go back to the app");
      });
});
2
Where are you calling the URL with the client_id query string parameter? Your code shows an HTTP Cloud Function, that will be exposed by an URL but this URL is not https://connect.stripe.com/express.... So where are you building and calling the https://connect.stripe.com/... URL with the client_id query string parameter? - Renaud Tarnec
the url is called from a flutter app using a Webview, in the url I provided, I ve just replace the real stripe clientId with {clientId} in order to hide it. Accessing this url to stripe launches a default function witch is set to be connectStripeExpressAccount - Yann Massard
What is not clear is how the connectStripeExpressAccount Cloud Function is connected to the other steps? Is it exposed as a webhook that Stripe calls? In other words: you write "Accessing this url to stripe launches a default function witch is set to be connectStripeExpressAccount" but how does your "system" (i.e. Flutter app + Stripe + Cloud Function backend) launches the Cloud Function? - Renaud Tarnec
technically yes, on the stripe side you define a URI that connects straight to your cloud function. when the URL request has no parameters, it automatically connects to this URI - Yann Massard
You should explain much more precisely how the different components (i.e. Flutter app + Stripe + Cloud Function backend) interact between each other and which info/payload is transmitted for each event. I have the feeling that from your Flutter app you call Stripe with a user ID and you want Stripe to pass this user ID when calling back your Cloud Function, but this is not clear. - Renaud Tarnec

2 Answers

1
votes

For new integrations with Express Accounts you should ideally be using the Account Links functionality instead of OAuth. That said, if you provide the state value, it should carry through, so I'd make sure you're actually providing it when opening the WebView.

0
votes

If the User uid is stored in the query parameter state and the URL looks like this: https://connect.stripe.com/express/oauth/authorize?response_type=code&client_id=ca_JCV8JW9ZIjBaGkwkhbDDDQegceWGidqh&scope=read_write&state=useruidxxx

Your code would look like this:

exports.connectStripeExpressAccount = functions.https.onRequest((req, res) =>{
  console.log('query state is  ----> ' + req.query.state);
  const authCode = req.query.code;
  return stripe.oauth.token({
    grant_type: 'authorization_code',
    code: authCode,
  }).then(async response => {
      var connected_account_id = response.stripe_user_id;
      const uid = req.query.state
      const writeResult = await admin.firestore().collection('Registration').doc(uid)
                           .set({'customer_id': connected_account_id});
      return res.send("Well done, account integration is completed. You can now close the window and go back to the app");
      });
});