benonymus

benonymus

So the erro meassage is :

(exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in MyApiWeb.FallbackController.call/2

And the code where it is coming from is :

def create(conn, %{
  "description" => description,
  "email" => email,
  "source" => source,
  "subscriptionID" => subscriptionID
}) do
  with {:ok, %t{} = t} <- Stripe.Customer.create(%{description: description, email: email}) do
    conn
    |> IO.inspect(t)
  end
end

Thanks

Showing Posts 1 to 10

NobbZ

NobbZ

I’m not sure what you try to bind to t in the with clause. But regardless what gets bound to it, its either an atom or a map/struct, while IO.inspect/2 expects keywords as its seconds argument (where t is used).

I am totally not sure though, if that is the problem though, since your error message complains about call/2 and you have shown only the create action.

To actually find your problem you’ll probably need to show more of your controller, as call/2 is the function that should dispatch the request to your actual action, so the problem is much earlier in the stack.

benonymus

benonymus OP

I am trying to use stripity stripe, and it is form their documentation, so I am not sure myself.
currently I only have this create action in my controller

NobbZ

NobbZ

There has to be more, some use or other stuff or there wouldn’t even be the call/2 function from the error message.

So could you please share the full controller?

benonymus

benonymus OP

sure and thanks

defmodule MyApiWeb.UserController do
  use MyApiWeb, :controller
  action_fallback(MyApiWeb.FallbackController)
  require Logger

  def create(conn, %{
        "description" => description,
        "email" => email,
        "source" => source,
        "subscriptionID" => subscriptionID
      }) do
    with {:ok, %t{} = t} <- Stripe.Customer.create(%{description: description, email: email}) do
      conn
      |> IO.inspect(t)
    end
  end
end
NobbZ

NobbZ

A fallback controller will be called when your actual action fails to return a proper conn.

As the with can’t match after my understanding (I’ve explained that above), you always return nil, which isnt a valid conn. So the fallback will be called. Why that doesn’t have a clause matching, we can’t say, because you haven’t shown it.

Also can you please share a link to the resources that gave you the example?

benonymus

benonymus OP

well I tried to puzzle it out from many, beause I could not find an example that uses striptiy stripe or elixir with stripe really.

also I am assuming that I am using this wrong but I just dont really understand that what the doc is trying to say
https://github.com/code-corps/stripity_stripe

https://medium.com/@njwest/jwt-auth-with-an-elixir-on-phoenix-1-3-guardian-api-and-react-native-mobile-app-1bd00559ea51

I used this as my base, made it work earlier, so I just used it as a general guide, these were the main ones, but had some other ones too

as for my code the router:
defmodule MyApiWeb.Router do
use MyApiWeb, :router

  pipeline :api do
    plug(CORSPlug, origin: "*")
    plug(:accepts, ["json"])
  end

  scope "/api", MyApiWeb do
    pipe_through(:api)

    post("/users", UserController, :create)
    # options("/users", UserController, :create)
  end
end
NobbZ

NobbZ

Sorry I have to say, but I can’t find anything in the links that is like the snippet you posted.

So I have to ask again, where did you found the t = %t{} pattern? What are you trying to achieve by using it?

What is it you want to inspect in the withs body? t or conn?

Have you understood what with is used for?

Why do you use a fallback controller at all? Do you really need it? Do you understand what it is meant for?


PS: the router is probably unrelated, the error is raised from your fallback controller.

benonymus

benonymus OP

the fallback controller was auto generated, this t = %t{} my friend said it and what it tries to achieev is to get the created user.
I want ot inspect the created user so t in this case.
Maybe if you know an open source project that uses elixir with stripe could yo link it?
or just help me understand how to use the package?

Thank you

idi527

idi527

:waving_hand:

t = %t{} seems rather pointless to me since, for example

iex(3)> t = %t{} = %User{}
%User{id: nil}
iex(4)> t
%User{id: nil}

here the intermediate value (from %t{} = %User{} such that t = User) is lost. If you want to pattern match on a user struct, it’s usually accomplished like this

iex(3)> %User{id: user_id} = %User{}

To better understand what goes wrong with

(exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in MyApiWeb.FallbackController.call/2

we would either need to see the implementation of MyApiWeb.FallbackController or at least what’s in t that causes the “happy path” in with to fail. Try this

def create(conn, %{
  "description" => description,
  "email" => email,
  "source" => source,
  "subscriptionID" => subscriptionID
}) do
  with {:ok, t} <- Stripe.Customer.create(%{description: description, email: email}) do
    conn # are you sure you don't want to `send_resp(conn, 200, [])` at least?
  else 
    unmatched ->
      IO.inspect(unmatched, label: "unmatched")
  end
end
NobbZ

NobbZ

I wasn’t in the need of a payment provider so far.

But please try to match only {:ok, user} and then do IO.inspect user; conn.

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews