Add stripe for payment in Phoenix site

Hello everyone, I would like to add stripe in my project to make payments,

Could someone help me please?

Thanks! :smiley:

2 Likes

Hi! The first thing to check is not related to Elixir. Is Stripe available in your country?

1 Like

Yes, i can use stripe in my country

You can try this one. This old to this industry standards but perhaps it helps you enough to fork it and readapt it to your needs (and to release to the community :slight_smile: )

1 Like

I believe GitHub - beam-community/stripity_stripe: An Elixir Library for Stripe is a better choice if someone wants to make a relatively low-level / custom integration.

From my experience, I think it’s most convenient to use the tools and services already provided by Stripe, such as: Stripe Checkout | Stripe-Dokumentation or Kundenportal integrieren | Stripe-Dokumentation

It really depends on the type of your project, so if you could provide more information, we can be more helpful.

1 Like

I recently integrated Stripe on an application I’m working on and Stripity Stripe was pretty straightforward to use and had all we needed.
Even if you’re using Stripe checkout (which I also recommend) you can easily create the session with Stripity Stripe.

To OP: your question is to vague. What exactly you need help with on the integration?

2 Likes

I don’t know how to use stripe in elixir

There might be some clues here: Setup Stripe with Phoenix LiveView - Tutorials and screencasts for Elixir, Phoenix and LiveView (Note that I have never tried it myself)

1 Like

this doc is not complete, I have tried this but it’s doesn’t work

Try this one.

1 Like

Thank you everybody, I’ve change the paiment mode

Hi Hasimbola,

It’s hard to give advice without knowing more about what specifically you’re trying to do. Do you need people to make one-off payments, or subscriptions? Is there a range of products they can choose from? What happens after they pay - does it create a user account? Grant access to a specific part of the site? Send them an email with the product attached?

The simplest approach is to use a Stripe-hosted checkout page: Accept a payment | Stripe-Dokumentation

The flow would work roughly like this:

  • Users visit a path on your site e.g. /checkout.
  • On the backend you generate a Checkout object using the stripity_stripe package, which contains a URL. You redirect them to this URL.
  • They’ll see a Stripe-hosted page where they can enter their payment information etc.
  • On successful payment, they’ll be redirected back to a URL on your site e.g. /checkout_complete which will have a session_id param.
  • You use this session_id param to pull information from Stripe about the checkout session and what they purchased - you can use this this to update your site accordingly e.g. grant them access to the product.

Remember that anyone can type /checkout_complete into their address bar so you can’t trust this URL blindly. You need to pull information from Stripe using your API keys to verify that people have actually paid.

You probably also want to set up a webhook endpoint so that Stripe can send you information about all activity on your account e.g. subscription cancellations and renewals. Again, you need to verify this endpoint so you can be sure that the requests are actually coming from Stripe and not from an attacker - Stripe’s docs have information about how to do this.

Other than that I can’t really give any more advice without knowing more about the details of what you want to do, but I hope that helps.

EDIT: wait, I only just noticed that this thread is from 2022. Oh well, I hope someone still finds the above helpful.

9 Likes

I find this very useful. Thanks, George!