-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No-hosted Paypal button, removed Stripe and websockets for validation
- Loading branch information
aguxez
committed
Feb 28, 2018
1 parent
465e774
commit 42d5ca7
Showing
27 changed files
with
197 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
use Mix.Config | ||
|
||
config :ecom, env: :dev | ||
|
||
import_config "dev.secret.exs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defmodule Ecom.Interfaces.Worker do | ||
@moduledoc false | ||
|
||
alias Ecom.Worker | ||
|
||
defdelegate update_user(user, params_password, attrs), to: Worker | ||
defdelegate can_create_product?(user, params), to: Worker | ||
defdelegate sign_in(user, password), to: Worker | ||
defdelegate new_user(params), to: Worker | ||
defdelegate empty_user_cart(user, proc_id, param_proc_id), to: Worker | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,40 @@ | ||
// NOTE: The contents of this file will only be executed if | ||
// you uncomment its entry in "assets/js/app.js". | ||
|
||
// To use Phoenix channels, the first step is to import Socket | ||
// and connect at the socket path in "lib/web/endpoint.ex": | ||
import {Socket} from "phoenix" | ||
|
||
let socket = new Socket("/socket", {params: {token: window.userToken}}) | ||
|
||
// When you connect, you'll often need to authenticate the client. | ||
// For example, imagine you have an authentication plug, `MyAuth`, | ||
// which authenticates the session and assigns a `:current_user`. | ||
// If the current user exists you can assign the user's token in | ||
// the connection for use in the layout. | ||
// | ||
// In your "lib/web/router.ex": | ||
// | ||
// pipeline :browser do | ||
// ... | ||
// plug MyAuth | ||
// plug :put_user_token | ||
// end | ||
// | ||
// defp put_user_token(conn, _) do | ||
// if current_user = conn.assigns[:current_user] do | ||
// token = Phoenix.Token.sign(conn, "user socket", current_user.id) | ||
// assign(conn, :user_token, token) | ||
// else | ||
// conn | ||
// end | ||
// end | ||
// | ||
// Now you need to pass this token to JavaScript. You can do so | ||
// inside a script tag in "lib/web/templates/layout/app.html.eex": | ||
// | ||
// <script>window.userToken = "<%= assigns[:user_token] %>";</script> | ||
// | ||
// You will need to verify the user token in the "connect/2" function | ||
// in "lib/web/channels/user_socket.ex": | ||
// | ||
// def connect(%{"token" => token}, socket) do | ||
// # max_age: 1209600 is equivalent to two weeks in seconds | ||
// case Phoenix.Token.verify(socket, "user socket", token, max_age: 1209600) do | ||
// {:ok, user_id} -> | ||
// {:ok, assign(socket, :user, user_id)} | ||
// {:error, reason} -> | ||
// :error | ||
// end | ||
// end | ||
// | ||
// Finally, pass the token on connect as below. Or remove it | ||
// from connect if you don't care about authentication. | ||
let token = document.querySelector("meta[name=channel_token]").getAttribute("content"); | ||
let socket = new Socket("/socket", {params: {token: token}}) | ||
|
||
socket.connect() | ||
|
||
// Now that you are connected, you can join channels with a topic: | ||
let channel = socket.channel("topic:subtopic", {}) | ||
let channel = socket.channel("payments:*", {}) | ||
channel.join() | ||
.receive("ok", resp => { console.log("Joined successfully", resp) }) | ||
.receive("error", resp => { console.log("Unable to join", resp) }) | ||
|
||
let form = document.getElementById("paypal-form"); | ||
|
||
if (window.location.pathname == "/payments") { | ||
form.addEventListener("submit", event => { | ||
event.preventDefault(); | ||
let ser = $("#paypal-form").serializeArray(); | ||
|
||
channel.push("form_submit", {form: ser}); | ||
}) | ||
} | ||
|
||
channel.on("form_resubmit", event => { | ||
let hid_in = document.createElement("input"); | ||
|
||
$("input[name='amount']").remove(); | ||
|
||
|
||
hid_in.setAttribute("type", "hidden"); | ||
hid_in.setAttribute("name", "amount"); | ||
hid_in.setAttribute("value", event.form.amount.value); | ||
|
||
form.appendChild(hid_in); | ||
|
||
form.submit(); | ||
}) | ||
|
||
export default socket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
defmodule EcomWeb.PaymentsChannel do | ||
@moduledoc false | ||
|
||
use Phoenix.Channel | ||
|
||
def join("payments:" <> _sub_topic, _, socket) do | ||
{:ok, socket} | ||
end | ||
|
||
def handle_in("form_submit", %{"form" => _data}, socket) do | ||
total = get_product_total(socket.assigns) | ||
attr = %{"amount" => %{"value" => total}} | ||
|
||
broadcast!(socket, "form_resubmit", %{form: attr}) | ||
|
||
{:noreply, socket} | ||
end | ||
|
||
defp get_product_total(%{user: user}) do | ||
products = Map.values(user.cart.products) | ||
|
||
products | ||
|> Enum.map(fn product -> product["price"] * product["value"] end) | ||
|> Enum.sum() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.