ryanwinchester

ryanwinchester

Paid signups/registration

What would you guys think is the best way to handle a signup form that includes making a payment?

I was thinking of a Registration.changest where the module looks like

defmodule App.Store.Registration do
  use Ecto.Schema

  import Ecto.Changeset
  import App.Repo, only: [preload: 1]

  alias App.Accounts.User

  schema "registrations" do
    belongs_to :customer, App.Store.Customer
    belongs_to :purchase, App.Store.Purchase
    belongs_to :user, App.Accounts.User
    timestamps()
  end

  def register_changeset(%__MODULE__{} = registration, attrs) do
    registration
    |> preload([:customer, :purchase])
    |> cast(attrs)
    |> cast_assoc(:customer, required: true)
    |> cast_assoc(:purchase, required: true)
  end

  def complete_changeset(%__MODULE__{} = registration, attrs) do
    registration
    |> preload(:user)
    |> cast(attrs)
    |> cast_assoc(:user, required: true, with: &User.register_changeset/2)
  end
end

Where you first complete a form that corresponds to register_changeset and then once that is done and the payment is processed show a form for the complete_changeset to create the user account w/ password, etc.

So, for the payment part, I was thinking App.Customer would have a payment_method field which would be an embed, or assoc or something that included a stripe token that is generated as part of filling out the signup form payment details.

Does this seem like a good way to do it? If not, what would you do?

Where would you guys put the payment processing step?

If the payment failed, I’d like to return a changeset error ideally, since then the response would all be the same no matter the error, but then we have the issue of a possible succeeding payment but an invalid changeset overall. therefore we could have a resubmission and possible double-charge.

First Post!

NobbZ

NobbZ

I’d do it similar to a double-opt-in registration process where a client has to click those links in an email. But instead of clicking that link he has to pay the bill.

  1. After submitting the registration form create the user, but have a flag tagging it as inactive
  2. Send email containing payment information/send them to the payment processor of your choice
  3. Await confirmation of payment (via processor or by manually checking your bank-account)
  4. Remove the flag that tags inactive and therefore have it active now.

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New

Other popular topics Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New

We're in Beta

About us Mission Statement