Last active
October 22, 2017 09:39
-
-
Save dereckmartin/025a1f3909fdbc2eb0874ee7abbbad07 to your computer and use it in GitHub Desktop.
Phoenix Framework: PayPal IPN Handshake
This file contains hidden or 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much! 👍