流程
- 申請帳號
- 到 PayPal Developer 開通開發帳號
- 沙盒測試網址加上 sandbox 即可
https://www.sandbox.paypal.com
https://ipnpb.sandbox.paypal.com - 針對開發人員的 PayPal 和 IPN(交易狀態更新)介紹
--
開啟 IPN (交易狀態更新、即時付款通知)
個人檔案 → 我的銷售工具 → 交易狀態更新
--
自訂付款
1 2 3 4 5 6 7 8 9 |
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="alanb@alanb.com"> <input type="hidden" name="item_name" value="doodad from alanb.com"> <input type="hidden" name="amount" value="4.99"> <input type="hidden" name="return" value="http://alanb.com/doodads/thanks.html"> <input type="hidden" name="cancel_return" value="http://alanb.com/doodads/canceled.html"> <input type="image" border="0" name="submit" src="http://images.paypal.com/images/x-click-but5.gif" alt="請使用 PayPal 付款 - 快捷、免費和安全的付款方式!"> </form> |
- business :
- amount :
- return :
- cancel_return :
一個實際案例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
$Form = ' <!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <form id="idForm" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_self"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="pc-facilitator@hoyo.idv.tw"> <INPUT TYPE="hidden" name="charset" value="utf-8"> <INPUT TYPE="hidden" name="lc" value="zh_TW"> <INPUT TYPE="hidden" NAME="currency_code" value="TWD"> <input type="hidden" name="custom" value="'. $Orders_id .':'. $token .'"> <input type="hidden" name="item_name" value="'. $ProductName .'"> <input type="hidden" name="amount" value="'. $price .'"> <input type="hidden" name="notify_url" value="'. PapPal_NotifyURL .'"> <input type="hidden" name="return" value="'. PapPal_ReturnURL .'"> <input type="hidden" name="cancel_return" value="'. PayPal_CancelReturnURL .'"> </form> <script type="text/javascript">document.getElementById("idForm").submit();</script> </body> </html> '; echo $Form; |
- notify_url: 設定 IPN 返回網址
- return: 成功付款返回網址
- cancel_return: 取消交易返回網址
--
IPN
將接收的 IPN $_POST 轉成陣列
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
Array ( [mc_gross] => 1000 [protection_eligibility] => Ineligible [address_status] => confirmed [payer_id] => 8G7HV3SJCPXAQ [address_street] => 71566176 Sky E137 S [payment_date] => 22:00:29 May 31, 2017 PDT [payment_status] => Pending [charset] => windows-1252 [address_zip] => W185744 [first_name] => [address_country_code] => HK [address_name] => [notify_version] => 3.8 [custom] => : [payer_status] => verified [business] => pc-facilitator@hoyo.idv.tw [address_country] => Hong Kong [address_city] => Posta [quantity] => 1 [verify_sign] => AOH.JxXLRThnyE4tyiz8f.cTKbR2AH5k6c0WNm5135Ot-LokNPpc1yzK [payer_email] => pc@hoyo.idv.tw [txn_id] => 2FA122351Y010023B [payment_type] => instant [last_name] => [address_state] => Libisia [receiver_email] => pc-facilitator@hoyo.idv.tw [receiver_id] => WJVDVGB4S5DES [pending_reason] => multi_currency [txn_type] => web_accept [item_name] => 1250 [mc_currency] => TWD [item_number] => [residence_country] => HK [test_ipn] => 1 [transaction_subject] => [payment_gross] => [ipn_track_id] => a72c1c50acff4 ) |
--
驗證 IPN 是否屬實
- https://ipnpb.paypal.com/cgi-bin/webscr?cmd=_notify-validate&
VERIFIED 有效,INVALID 無效
--
REST API
--
輔助資源
--
4,574 total views, 3 views today