0

I'm creating a lecture recording app that makes it easier for students to share and learn together from a recorded lecture. This app stores mp3 and png files on Firebase storge. Each user will have 100MB of storage for free (this is around 4-8 lecture that they can record). The problem is that users may need more memory and I cant afford it pay all from ads, therefore I want to add a monthly charge for those users who need more memory.

Now I'm not sure or have any experience in any money transaction by code. Can anyone give me an idea or what I can do to solve this problem?

P.S. I was also thinking of using Google Drive API to allow the user to save their recorded lecture on their own cloud, but I'm not sure if that will give me as much functionality as firebase storage.

Kamil B
  • 95
  • 1
  • 4

1 Answers1

1

If I understood the requirement correctly, this is what you'll need to implement.

  1. In-app subscriptions: docs
  2. Server-side verification of those subscriptions — in your case a Firebase Function, which you'll call from your app when the user subscribes, and which will verify the legitimacy of the purchase and grant the user profile a custom claim (i.e. a flag on their profile) saying they have access to more storage. My question/answer may help you out. More on custom claims here.
  3. Logic that verifies that whenever a user uploads a file, their total folder size doesn't exceed the limit (100 MB or more, depending on whether that custom claim is set). Unfortunately there's no way to check total folder size directly in Storage Rules, so you'll have to write another Firebase Function, which will be triggered whenever a user uploads a file — docs.
  4. Now, I'm not so sure whether it's possible to get total folder size from Functions as well, therefore you may also need to write your own logic that would keep track of how much storage space a user had already used (e.g. keep a database record) and use that to verify whether the newly uploaded file should be kept or discarded.
Actine
  • 2,867
  • 2
  • 25
  • 38
  • That all good advise, but I've been looking into it and unfortunately, I cannot find code examples of how to approach Firebase transactions. Do you know if there is an API for me to use that does this? – Kamil B Jul 04 '18 at 11:45
  • What transactions exactly do you mean? – Actine Jul 04 '18 at 18:51
  • I want a PayPal transaction, so when a user pays £2 they will get a specific amount of memory for a month – Kamil B Jul 04 '18 at 20:25
  • Also here's what I've done so far: https://github.com/kamilbolka/lecture-recording-app – Kamil B Jul 04 '18 at 20:27
  • I cannot help you with PayPal, but FYI you **mustn't** use anything except In-app Billing for your case — read [developer policy](https://play.google.com/about/monetization-ads/payments/) for details. Otherwise, I see the flow like this: after a successful purchase flow your app makes a HTTP request to a Firebase Function, which does a server-side verification of provided purchase token and grants the user the permission for extra storage. You do this once, but you can also check on each launch if the user who doesn't have the permission perhaps has recent purchases, and repeat the request – Actine Jul 05 '18 at 14:12