Best practices for an Umbrella app with many payment api apps

I’m about to build an Umbrella app where each app is a payment service for my end users.

each payment app makes a call to an API (like Stripe, Paypal, etc.) to process the payment.

so here is what I planned to do : create one router app that will redirect each request to the right app (depending on wether the user asked to pay through Stripe or Paypal for example). And create one phoenix app for each payment solution (no ecto, no webpack, no html, just one function for each api route).

So here are my questions:

  • Do I need to create any phoenix app ? shouldn’t any simple elixir app be enough ? as all I need is:
    An app that routes the incoming requests
    a module for each payment service that make api calls to the payment solution

  • is it necessary to create an umbrella project ?
    I feel like it’s always a good practice to create an umbrella project, no matter what the project is. am I right?

If all you need is handling HTTP requests you could try using plug_cowboy instead of Phoenix. It is a more lightweight solution that Phoenix but also grants you all the advantages of using Plug.
There is a great tutorial about this in elixir school.

1 Like

:wave:

I’d probably create a single app for all payments, called :payment, which would have several “payment providers”, Payment.Provider.{PayPal, Stripe, AliPay, Bitcoin, etc...}, which would all implement the Payment.Provider behaviour @callback pay(Payment.t) :: Payment.t, and export a single function Payment.pay(provider, payment).

Then I’d create a single http endpoint which would call that function on a request with the correct provider set.

4 Likes

Hi @idi527 thank you for your answer ! why would you create a single app instead of an umbrella app ?

hi @jkmrto ! thank you for your help :slight_smile: would you also only use plug_cowboy for the router app ?

I would create a single app for payments in the “umbrella” project structure, and then one app for the web interface. I wouldn’t separate the payment into several apps, since I don’t see any reason to …

I only separate an app if one of the following are “true”:

  • the app needs to be deployed in several separate releases, for example, “metrics” app which exposes prometheus metrics might be deployed both with a “database” app, and with a “web” app
  • the app is being depended on by several other apps, for example a “repo” (as in ecto repo) app which is used to connect to the same database from a “crawler” and from a “web” apps (which is quite similar to the previous point now that I think about it)
  • the app is being worked on independently by someone else

Separating code into several apps for any other reason I consider a bit superfluous … Modules can do just as good but with less ceremony.

3 Likes