4
votes

I'm integrating Stripe Payment Gateway to an Android App and facing some questions and issues. Following the Stripe Documentation it seems like having its own Server is required. Digging for a few Hours, Firebase Cloud Functions can do the Server work...Great !!

But from what I can find, it can be done in at least two ways:

  • HTTP Trigger
  • A write to Firebase Database that would trigger a Cloud Function

So first, which one to use?
The good old Industry trusted http endpoint with good old Retrofit?
Or the much more simple Write to Firebase Database to trigger the function?

Also, as for the next step, I could not find any Android tutorial for the next steps. Only this Web app: https://github.com/firebase/functions-samples/tree/master/stripe.
From what I can see, it would need Node.js, npm etc etc...

Nothing more simple from Google?

Cheers guys

1
Whether to use the http trigger or write to firebase trigger depends on your application. Which do you think is more suitable? As for Android, check out Stripe's Android library. stripe.com/docs/mobile/androidKevin Lee

1 Answers

2
votes

First of all, either way you're going to have to write backend code in JavaScript to handle payments.

So the process that works for us with Cloud Functions is -

1) Android provides card details to Stripe using native SDK

2) Stripe provides a token which Android sends it to your Firebase backend

you could store it in stripeTokens/userId/yourToken

3) Firebase cloud function then triggers a function and uses this token to create Stripe customer (See saving for later and Customer)

you could store it in stripe_customers/userId/stripeCustomerId

4) Remember to remove yourToken because it's only valid once

5) finally you can use this stripeCustomerId to make payments and update related nodes in the backend

Important concept here is to create a customer and store it in your backend for future payments.

So steps after 2) are all cloud functions, so yes most of the work is done in backend. Only thing Android is doing is entering card details, sending token, triggering and listening for future charges.

As far as HTTP is concerned, concept is similar but only thing different is you wait for the response and if there is any errors you get it there, whereas if you were to do with Cloud Functions, you would have to write those errors somewhere and read those from client.

Hope this helps.