     %PaymentSchema{}
     |> PaymentSchema.creation_changeset(params)
     |> get_payment_autorization
-    |> store_payment
+    |> put_payment_token
+    |> validate_payment
+    |> save_payment
     |> send_response(conn)
   end
 

    changeset = changeset
    |> Ecto.Changeset.put_change(:auth, %Tokenizer.DB.Models.Authorization3DS{})
    |> Ecto.Changeset.put_change(:external_id, "007")
    |> put_token

    {:ok, changeset}
  end

  defp put_token(%Ecto.Changeset{} = changeset) do
    expires_in = Confex.get(:tokenizer_api, :payment_token_expires_in)

    expires_at = Timex.now
    |> Timex.shift(microseconds: expires_in)

    changeset
    |> Ecto.Changeset.put_change(:token, @payment_token_prefix <> "-" <> Ecto.UUID.generate)
    |> Ecto.Changeset.put_change(:token_expires_at, expires_at)
  end

  # Store payment changes into DB
  defp store_payment({:error, reason}), do: {:error, reason}
  defp store_payment({:error, reason, details}), do: {:error, reason, details}
  defp store_payment({:ok, %Ecto.Changeset{} = changeset}) do
    case PaymentSchema.changeset(changeset) do
      %Ecto.Changeset{valid?: true} = changeset ->
        IO.inspect changeset.changes.sender.changes.credential.validations

        changeset
        |> Tokenizer.DB.Repo.insert
      %Ecto.Changeset{valid?: false} = changeset ->
        {:error, :invalid, changeset}
    end
  end

  # Responses

  end

  defp send_response({:error, :invalid, %Ecto.Changeset{} = changeset}, conn) do
    conn
    |> put_status(422)
    |> render(EView.ValidationErrorView, "422.json", changeset)
