Creating client in local bank and api simultaneously

I am currently creating an integration with a payment gateway via JSON API.

But I don’t know how I can make the client fill in the forms, and insert it into my local database and simultaneously send it to the API.

Has anyone done this?
Can you help me?

I hope it was not confusing, below I will send what has already been done.

Note: I managed to get the API to work manually, but I don’t know how to make it work with the information passed in the template.


  def create(conn, %{"client" => client_params}) do
    case Structure.create_client(client_params) do
      {:ok, client} ->
        |> put_flash(:info, "Client created successfully.")
        |> redirect(to: Routes.client_path(conn, :show, client))

      {:error, %Ecto.Changeset{} = changeset} ->
        render(conn, "new.html", changeset: changeset)


def api_create_client() do
  url = ""
  headers = %{"Content-Type" => "application/json", "Authorization" => "Basic AUTHAPIBASE64"}
  hackney = [basic_auth: {"AUTHAPI", "AUTHAPI"}]

  body = Poison.encode!(
      ownId: "3", 
      fullname: "Test Teste", 
      email: "", 
      birthDate: "1980-5-10", 
      taxDocument: %{
        type: "CPF",
        number: "00013390000"
      phone: %{  
         countryCode: "55", 
         areaCode: "11", 
         number: "22226842"
      shippingAddress: %{  
         city: "Rio de Janeiro", 
         district: "Ipanema", 
         street: "Avenida Atlântica", 
         streetNumber: "60", 
         zipCode: "02446000", 
         state: "RJ", 
         country: "BRA"

)!(url, body, headers, [hackney: hackney])