Advertisement
Guest User

Untitled

a guest
Apr 26th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 2.44 KB | None | 0 0
  1. -module(ppb_paypal_nitro).
  2. -export([main/0,form/6]).
  3. -include_lib("nitrogen_core/include/wf.hrl").
  4.  
  5. -define(plg(PL,Key),proplists:get_value(Key,PL,"")).
  6.  
  7.  
  8. %% ------------------------ v Public Result from DPM v ------------------
  9.  
  10. main() ->
  11.     {ok,Body} = process_ipn(),
  12.     Tag = wf:q(item_number),
  13.     _ReceiptURL = ppb:payment_processed(Tag,Body).
  14.  
  15. process_ipn() ->
  16.     Sandbox = false,
  17.     SandboxURL = sandbox_url(Sandbox),
  18.     Body = wf:to_list(wf:request_body()),
  19.     NewBody = "cmd=_notify-validate&" ++ Body,
  20.     NewURL = "https://www" ++ SandboxURL ++ ".paypal.com/cgi-bin/webscr?" ++ NewBody,
  21.     Request = {
  22.         NewURL,
  23.         []
  24.     },
  25.     HTTPOpts = [
  26.         {autoredirect,true}
  27.     ],
  28.     Opts = [
  29.         {body_format,list},
  30.         {full_result,false}
  31.     ],
  32.     case httpc:request(get,Request,HTTPOpts,Opts) of
  33.         {ok, {200,"VERIFIED"}} ->
  34.             {ok,Body};  %% REturn the original info that was sent
  35.         {ok, {200,"INVALID"}} ->
  36.             {error,paypal_said_invalid};
  37.         {ok, {Code,Result}} ->
  38.             {error,{{http_code,Code},Result}};
  39.         {error, Reason} ->
  40.             {error, Reason}
  41.     end.
  42.  
  43. %% ------------------------ ^ Private Form from DPM ^ ----------------
  44.  
  45. sandbox_url(true) -> ".sandbox";
  46. sandbox_url(_) -> "".
  47.  
  48.  
  49. form(Email,InvoiceNum,Amount,Description,ReturnURL,RelayHost) ->
  50.     Sandbox = false,
  51.     SandboxURL = sandbox_url(Sandbox),
  52.     Amount2 = ppb:dollars(Amount),
  53.     HiddenFields = [
  54.         {cmd,"_xclick"},
  55.         {currency_code,"USD"},
  56.         {business,Email},
  57.         {item_name,Description},
  58.         {item_number,InvoiceNum},
  59.         {amount,Amount2},
  60.         {return_url,ReturnURL},
  61.         {cancel_url,ReturnURL},
  62.         {ipn_notification_url,"http://" ++ RelayHost ++ "/ppb/authnet/nitro"}
  63.     ],
  64.  
  65.     [
  66.         "<form name=paypal method=post action=\"https://www" ++ SandboxURL ++ ".paypal.com/cgi-bin/webscr\">",
  67.         lists:map(fun({Field,Val}) ->
  68.             ["<input type=hidden name=\"",wf:to_list(Field),"\" value=\"",wf:html_encode(wf:to_list(Val)),"\">"]
  69.         end,HiddenFields),
  70.         #singlerow{cells=[
  71.             #tablecell{text="Amount to be billed:"},
  72.             #tablecell{text=["$",Amount2]}
  73.         ]},
  74.         "<input type=image type=submit border=0 src=\"https://www.paypalobjects.com/en_US/i/btn/btn_paynow_LG.gif\" alt=\"Pay with PayPal\" style='border:none' />",
  75.         "<img alt=\"\" border=0 width=1 height=1 src=\"https://www.paypal.com/en_US/scr/pixel.gif\" />",
  76.         "</form>"
  77.     ].
  78.        
  79.    
  80.  
  81. %% build_button(InvoiceNum,Amount,Description) ->
  82. %%  Fields = [
  83. %%      {"METHOD","BMCreateButton"},
  84. %%      {"BUTTONCODE","ENCRYPTED"},
  85. %%      {"BUTTONTYPE","BUYNOW"},
  86. %%      {"L_BUTTONVAR1","
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement