Skip to content

Instantly share code, notes, and snippets.

@dereckmartin
Last active October 22, 2017 09:39
Show Gist options
  • Save dereckmartin/025a1f3909fdbc2eb0874ee7abbbad07 to your computer and use it in GitHub Desktop.
Save dereckmartin/025a1f3909fdbc2eb0874ee7abbbad07 to your computer and use it in GitHub Desktop.
Phoenix Framework: PayPal IPN Handshake
defmodule AppName.IpnController do
@moduledoc """
IPN Controller.
"""
use AppName.Web, :controller
def create(conn, params) do
# PayPal requires the params returned in the exact order given.
# The map needs to be a list. encode/1 keep the order of a list,
# but not a map. https://hexdocs.pm/plug/Plug.Conn.Query.html.
pp_query_string = Plug.Conn.Query.encode(
params |> Enum.to_list
)
# Join the URI (e.g., sandbox/prod) with the params)
pp_ack_uri = Enum.join(["https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_notify-validate", pp_query_string],"&")
# Let it fly.
case HTTPoison.post(pp_ack_uri,'',[],[]) do
{:ok, response} ->
IO.inspect(response)
# Do business logic
{:error, reason} ->
IO.inspect(reason)
# Uh, oh.
end
# Render a blank
html(conn,'')
end
end
@dsignr
Copy link

dsignr commented Oct 22, 2017

Thank you so much! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment