Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(ppb_paypal_nitro).
- -export([main/0,form/6]).
- -include_lib("nitrogen_core/include/wf.hrl").
- -define(plg(PL,Key),proplists:get_value(Key,PL,"")).
- %% ------------------------ v Public Result from DPM v ------------------
- main() ->
- {ok,Body} = process_ipn(),
- Tag = wf:q(item_number),
- _ReceiptURL = ppb:payment_processed(Tag,Body).
- process_ipn() ->
- Sandbox = false,
- SandboxURL = sandbox_url(Sandbox),
- Body = wf:to_list(wf:request_body()),
- NewBody = "cmd=_notify-validate&" ++ Body,
- NewURL = "https://www" ++ SandboxURL ++ ".paypal.com/cgi-bin/webscr?" ++ NewBody,
- Request = {
- NewURL,
- []
- },
- HTTPOpts = [
- {autoredirect,true}
- ],
- Opts = [
- {body_format,list},
- {full_result,false}
- ],
- case httpc:request(get,Request,HTTPOpts,Opts) of
- {ok, {200,"VERIFIED"}} ->
- {ok,Body}; %% REturn the original info that was sent
- {ok, {200,"INVALID"}} ->
- {error,paypal_said_invalid};
- {ok, {Code,Result}} ->
- {error,{{http_code,Code},Result}};
- {error, Reason} ->
- {error, Reason}
- end.
- %% ------------------------ ^ Private Form from DPM ^ ----------------
- sandbox_url(true) -> ".sandbox";
- sandbox_url(_) -> "".
- form(Email,InvoiceNum,Amount,Description,ReturnURL,RelayHost) ->
- Sandbox = false,
- SandboxURL = sandbox_url(Sandbox),
- Amount2 = ppb:dollars(Amount),
- HiddenFields = [
- {cmd,"_xclick"},
- {currency_code,"USD"},
- {business,Email},
- {item_name,Description},
- {item_number,InvoiceNum},
- {amount,Amount2},
- {return_url,ReturnURL},
- {cancel_url,ReturnURL},
- {ipn_notification_url,"http://" ++ RelayHost ++ "/ppb/authnet/nitro"}
- ],
- [
- "<form name=paypal method=post action=\"https://www" ++ SandboxURL ++ ".paypal.com/cgi-bin/webscr\">",
- lists:map(fun({Field,Val}) ->
- ["<input type=hidden name=\"",wf:to_list(Field),"\" value=\"",wf:html_encode(wf:to_list(Val)),"\">"]
- end,HiddenFields),
- #singlerow{cells=[
- #tablecell{text="Amount to be billed:"},
- #tablecell{text=["$",Amount2]}
- ]},
- "<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' />",
- "<img alt=\"\" border=0 width=1 height=1 src=\"https://www.paypal.com/en_US/scr/pixel.gif\" />",
- "</form>"
- ].
- %% build_button(InvoiceNum,Amount,Description) ->
- %% Fields = [
- %% {"METHOD","BMCreateButton"},
- %% {"BUTTONCODE","ENCRYPTED"},
- %% {"BUTTONTYPE","BUYNOW"},
- %% {"L_BUTTONVAR1","
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement