2012-10-18 86 views
1

我正在嘗試將payflow pro與現有網站集成。使用PHP 5創建與PayPal服務器的HTTPS連接

沒有用於PHP的SDK,並且與PHP集成將需要使用Payflow HTTPS接口。開發指南(https://cms.paypal.com/cms_content/AU/en_AU/files/developer/PP_WPPPF_HTTPSInterface_Guide.pdf)表示,我需要編寫創建與PayPal服務器的HTTPS連接的代碼。我應該使用什麼方法來執行此操作,以及在連接建立後如何提交HTTPS請求?

回答

1

我終於能在這裏找到一個例子:https://ppmts.custhelp.com/app/answers/detail/a_id/618

<? 
$submiturl = "https://pilot-payflowpro.paypal.com/transaction:443/"; 

$plist="USER=****&VENDOR=****&PARTNER=****&PWD=****&TENDER=C&" . 
     "TRXTYPE=A&ACCT=5105105105105100&" . 
     "EXPDATE=1209&STREET= 123 MainSt.&CVV2=123&AMT=1.00"; 

$request_id = date('YmdGis'); 
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"; 

// Here's your custom headers; adjust appropriately for your setup: 
$headers[] = "Content-Type: text/namevalue"; // either text/namevalue or text/xml 
$headers[] = "X-VPS-Timeout: 30"; 
$headers[] = "X-VPS-VIT-OS-Name: Linux";  // Name of your Operating System (OS) 
$headers[] = "X-VPS-VIT-OS-Version: RHEL 4"; // OS Version 
$headers[] = "X-VPS-VIT-Client-Type: PHP/cURL"; // Language you are using 
$headers[] = "X-VPS-VIT-Client-Version: 0.01"; // For your info 
$headers[] = "X-VPS-VIT-Client-Architecture: x86"; // For your info 
$headers[] = "X-VPS-VIT-Integration-Product: MyApplication"; // For your info, application name 
$headers[] = "X-VPS-VIT-Integration-Version: 0.01"; // Application version 
$headers[] = "X-VPS-Request-ID: " . $request_id; 

$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $submiturl); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); 
curl_setopt($ch, CURLOPT_HEADER, 1); // tells curl to include headers in response 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable 
curl_setopt($ch, CURLOPT_TIMEOUT, 45); // times out after 45 secs 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // this line makes it work under https 
curl_setopt($ch, CURLOPT_POSTFIELDS, $plist); //adding POST data 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //verifies ssl certificate 
curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE); //forces closure of connection when done 
curl_setopt($ch, CURLOPT_POST, 1); //data sent as POST 

// $info = curl_getinfo($ch); //grabbing details of curl connection 

$result = curl_exec($ch); 
$headers = curl_getinfo($ch); 
curl_close($ch); 
echo $result; 
?> 
+0

+1非常感謝你;我一直在尋找一個簡單而有效的解決方案。 – thecommonthread

1

只需使用任何常規的發出HTTP請求的方法,例如捲曲或file_get_contents。如果底層傳輸層支持SSL安全連接,則向https://... URL發送請求將使SSL安全連接;否則傳輸層將失敗,說它不能建立HTTPS連接。

0

你有三個選擇:

1)您可以使用線上購物PHP SDK PayFlow作爲一個起點,如果你喜歡冒險的感覺:https://www.x.com/sites/default/files/OsC23PayPalPayFlow.zip

2)您可以通過開發者指南的payflow閱讀並製作您自己的手工API調用: https://cms.paypal.com/cms_content/US/en_US/files/developer/PP_PayflowPro_Guide.pdf

3)您可以給集成嚮導一個旋轉。我會自動生成代碼爲您提供:https://www.paypal-labs.com/integrationwizardccpayflow/main.php