Skip to content

Instantly share code, notes, and snippets.

@dsignr
Forked from dereckmartin/IpnController.ex
Created October 22, 2017 09:34
Show Gist options
  • Select an option

  • Save dsignr/dd0be66cda76e31969e286aba97e00fb to your computer and use it in GitHub Desktop.

Select an option

Save dsignr/dd0be66cda76e31969e286aba97e00fb to your computer and use it in GitHub Desktop.

Revisions

  1. @dereckmartin dereckmartin revised this gist Sep 16, 2016. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions IpnController.ex
    Original file line number Diff line number Diff line change
    @@ -17,12 +17,12 @@ defmodule AppName.IpnController do
    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,'',[],[])
    {:ok, response}
    case HTTPoison.post(pp_ack_uri,'',[],[]) do
    {:ok, response} ->
    IO.inspect(response)
    # Do business logic
    {:error, message}
    IO.inspect(message)
    {:error, reason} ->
    IO.inspect(reason)
    # Uh, oh.
    end

  2. @dereckmartin dereckmartin created this gist Sep 16, 2016.
    32 changes: 32 additions & 0 deletions IpnController.ex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    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,'',[],[])
    {:ok, response}
    IO.inspect(response)
    # Do business logic
    {:error, message}
    IO.inspect(message)
    # Uh, oh.
    end

    # Render a blank
    html(conn,'')
    end
    end