-
-
Save dsignr/dd0be66cda76e31969e286aba97e00fb 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