Once phx-trigger-action is true, LiveView disconnects and then submits the form.Īny idea on how to test that the form actually gets posted?Ĭalling render_submit/2 returns the rendered HTML which I can test to ensure that there are no changeset errors, but I’m at a loss on how to test that it actually posts.Īnd the corresponding event handlers: trueĭef handle_event("validate", % = live(conn, Routes. I have a registration form that I’m validating with LiveView and then submitting to a regular controller action over HTTP. Here’s where its mentioned in the docs: Form bindings - Phoenix LiveView v0.15.4 But I plan to make a more comprehensive course on the subject including subscriptions and listening to webhooks.I’m curious how folks are testing LiveView forms that use phx_trigger_action? I did make it easy for myself and only handles the success cases. That i can fill in with a test card that I received from Stripes page.Īnd when I submit, I should get a success message:īesides that, I should be able to navigate to purchases in Stripes dashboard and see the transaction registered there. So, when Stripe Elements is connected, and I have filled out email and name, I should be presented with: To keep things simple, I will just saddle for showing the success message in the in an if-else |> assign(:changeset, Checkouts.change_checkout(%Checkout The initial code in the LiveView is: defmodule do When the payment is successful, I want to render a success message When that is valid and submitted, I want to render the credit card field I want to render an initial form with email and name So make sure you don’t commit it in source control. NOTE that its really important that you don’t share this or make it public in any way. I can find the secret key if I click “Reveal test key token” I get the STRIPE_SECRET from the Stripe dashboard. # config/config.exsĬonfig :stripity_stripe, api_key: System.get_env("STRIPE_SECRET") There are different API keys so, in development, make sure you insert the development key. An important thing to note, is that stripe supports development and production. There is only one configuration that is required to get started. I use the awesome package “stripity_stripe”. When that is done, I am ready for installing and setup Stripe. I will use that for form validation in the checkout form # lib/shop_test/checkouts/checkout.ex I want to remove some of the values that are required in the changeset so only email and name is required. mix Checkouts Checkout checkouts email name amount:integer currency payment_intent_id payment_method_id statusĪnd then run migrations with: mix ecto.migrateĪfter I have run the migrations, there is only one thing that I need to change. The important thing to store is the payment_intent_id. In this tutorial, I don’t associate them with the users table but have a specific checkouts context and table. If you want to deploy a Phoenix LiveView app right now, then check out how to get started. I want to store the checkouts in the database for convenience. Triggering a Phoenix Controller Action From a Form in a LiveView Annie Ruygt This is a post about getting a form in a LiveView to invoke a Phoenix controller action, on your terms. If you don’t already have an account, head over to Stripe ( ) and sign up. Keep in mind that this is a get-started tutorial and does not go into product subscriptions, which will come in a follow up tutorial or course. I think its particularly suitable since it involves async communication with an external service. I combine Phoenix LiveView and Stripe Elements to create a self hosted customized checkout. The tutorial includes working process for Strong Customer Authentication (SCA). In this tutorial, I will go through how I setup Stripe payments with Phoenix and LiveView to make your app prepared for accepting payments.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |