1

so I've spent a fair amount of time (weeks) with this issue however still have not been able to figure out how to resolve it. I believe I've narrowed it down to the issue of trying to get a Stripe Connect webhook to fire once a user has completed the signup form through the Stripe Connect Express process. Here's the example Stripe gives with their RocketRides.io demo. I've submitted an issue to stripe but am waiting to hear back. I was hoping to get there quicker with the help of the SO community.

I've previously created other questions as I chase the proverbial rabbits down their various holes as I go through the trial and error process of trying to narrow down the issue so bear with me. You can find these other links at the bottom of this question post.

The snippet below displays my Stripe CLI Log when I am "listening" with stripe listen.

stripe listen snippet

This snippet displays the stripe logs tail stripe logs tail snippet

The customer.created is fired when a user signs up for my app, which is supposed to happen using the code below. I am not sure if this is supposed to be used when trying to use a Stripe Connect Account which is my intention. I'm still figuring out Stripe. The bottom line is I need to have payout and subscription capability, and from the research I've done, Stripe Connect is the direction to go.

exports.createStripeCustomerHTTPSCall = functions.firestore.document('Users/{userName}').onCreate((change, context) =>{

    console.log("Stripe Customer profile for " + context.params.userName + " created.");

    return stripeToken.customers.create(
        {
            description: 'My First Test Customer (created for API docs)',
            email: context.params.userName,
        },
        (err, customer) => {
        // asynchronously called
            console.log("Creating Stripe customer failed because: " + err.toString())
        }
    )

Once a user signs up for the App and is logged in the FirebaseDatabase as a user, they will be directed to the Stripe Connect Express form.

The issue now I'm running into is getting stripe to fire a Connect Webhook which would trigger Step 4, a Cloud Functions version of a cURL request to the redirected URL with the Authentication code, and potentially a state code. The account.application.authorized event only occurs in my listener only after I have sent in a cURL request (I think is called a GET Request? I'm not a formally trained programmer)

I believe the issue lies in setting up a webhook to fire once a user has completed the form and is redirected which I think should be account.updated?

Here is my webhook setup: enter image description here

enter image description here

Here is my Node.js code. I'm not sure if its relevant since I can't even get the webhook to fire but just in case:

exports.stripeCreateOathResponseToken = functions.https.onRequest((req, res) => {

console.log("rawbody: " + rawbody); // <-- usually comes back with req.rawbody
    console.log("request.body: " + req.body); // <-- returns undefined
    console.log("request.query.code: " + req.query.code); // <-- returns undefined
    console.log("request.query.body: " + req.query.body); // <-- returns undefined
    console.log("request.query.state: " + req.query.state); // <-- returns undefined

return stripeToken.oauth.token({
          grant_type: 'authorization_code',
          code: req.query.code,
    }).then(function(response) {
          // asynchronously called

        return res.send(response)

          // var connected_account_id = response.stripe_user_id;
        })
        .catch(error=> {
            res.send(error)
        })

    });

In case its relevant, here is android kotlin code for when user decides to sign up for payouts capabilities. AKA Stripe Connect Express

openURL.data = Uri.parse(
                            "https://connect.stripe.com/express/oauth/authorize?" +
                                    "redirect_uri=http://XXXXXXXXXXXXXX.com&" +
                                    "client_id=ca_XXXXXXXXXXXXXXXXXXXX" + // how to hide client id? maybe look at how to access from stripe CLI
                                    "state=" + mAuth.currentUser!!.uid +
                                    "&stripe_user[email]=" + userEmail +
                                    "&stripe_user[business_type]=individual" +
                                    "&stripe_user[phone_number]=" + userPhoneNumberStripped +
                                    "#/")

                    startActivity(openURL)

Previous Questions

Stripe Firebase Cloud Functions - res.send() is not a function

Cloud Firebase Stripe Connect - Retrieve Authorization Code / Access Token, State, etc

Firebase Cloud Functions - Stripe Connect Webhook not firing

Android Stripe Connect WebView - Create Account Form NOT loading

Cflux
  • 1,423
  • 3
  • 19
  • 39

1 Answers1

1

In this case a webhook won't work; you'll instead want to redirect the user - after they complete the OAuth process - to a Cloud Functions URL that runs the Node.js code you've supplied there (and then redirects them to whatever your next step is from there).

You'll also want to make sure that the URL you're redirecting to is listed as a redirect URL in your dashboard's Platform Settings, per here: https://stripe.com/docs/connect/express-accounts#integrating-oauth

In terms of redirecting in GCF, this might help: https://stackoverflow.com/a/45897350/379538

floatingLomas
  • 8,553
  • 2
  • 21
  • 27
  • Am I mistaken or does Stripe docs only mention to redirect to the platform's website? I don't see it mention anywhere to make a redirect to the Cloud Functions URL. I'll edit my Kotlin code and see how that goes. – Cflux Mar 09 '20 at 14:07
  • so I replaced my redirectURI of my kotlin code to be ` "redirect_uri=https://us-central1-xxxxxxxxxx.cloudfunctions.net/stripeCreateOathResponseToken&" +` but still nothing is triggered. I am looking around on how to trigger a cloud function through the `openURL.data = Uri.parse` im not getting any hits. – Cflux Mar 09 '20 at 15:28
  • 1
    Are there any errors? Is that URL listed as a redirect URL in your dashboard's Platform Settings, per here? https://stripe.com/docs/connect/express-accounts#integrating-oauth – floatingLomas Mar 10 '20 at 04:02
  • 1
    That was it! it was the URL in the [Connect Settings] (https://dashboard.stripe.com/settings/applications) it had my platform's URL listed as a default which I guess is why it was overriding my endpoint's URL that i had in my kotlin code. Now when the user completes the signup process, it just goes to a white page showing `response: [object Object]` in the top left corner but atleast now its working. I'll have to rig up something so it fowards to the platform's page or something. Please post the previous comment as an answer so I can give credit. I'd buy you a beer if I could. – Cflux Mar 10 '20 at 04:57
  • @Cflux Edited. :) – floatingLomas Mar 18 '20 at 06:55