日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

PHP中集成PayPal标准支付

發布時間:2024/4/17 php 61 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP中集成PayPal标准支付 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前兩天一個客戶需要在網站上集成PayPal支付功能,查了一下資料,簡單記錄如下:

PayPal支付功能其實一直在更新文檔和接口,這里說的是一個簡單的支付功能大概流程如下

1,在網站的結賬頁面,設置一個提交到PayPal網站的form,里面有一些金額,商品名稱,商家收款賬號、結賬成功后返回URL等內容,

2,用戶結賬時,通過點擊‘使用PayPal結賬’的按鈕到達PayPal的結賬頁面,輸入自己的PayPal用戶名和密碼并確認支付

3,PayPal會根據是否支付成功來決定返回網站的哪個頁面,并在后臺對網站的某個頁面發起post請求,這個動作稱作IPN,告訴網站這筆付款的到賬情況,比如completed即為完成付款

4,網站收到PayPal的notify通知后,即可給用戶發貨或者其他的處理邏輯

這里有一張圖來解釋

更為簡單的流程圖

我們要完成整個流程,其實只需要兩個頁面來處理
  • checkout.php 這個頁面用來顯示購物車信息,并讓用戶點擊按鈕導航到PayPal進行支付
  • notify.php 這個頁面是用來接收PayPal的IPN信息的,判斷用戶的付款是否到賬等狀態,并處理網站收款之后的業務邏輯
  • 記錄一下代碼:

    checkout.php 這個頁面其實可以是HTML

    <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="ev_csrf" value="9878824eb2cf4f1075dfa43c216d7cec"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="charset" value="utf-8"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="business" value=sales@test.com> <input type="hidden" name="cancel_return" value=”http://www.test.com/checkout.html”> <input type="hidden" name="return" value=”http://www.test.com/thanks.html”> <input type="hidden" name="notify_url" value="http://www.test.com/notify.php"> <input type="hidden" name="custom" value="userid:31;ip:182.114.240.221"> <input type="hidden" name="item_number" value="ARO0101"> <input type="hidden" name="item_name" value="AD182m"> <input type="hidden" name="quantity" value="1"> <input type="hidden" name="amount" value="70"> <input type="submit" value="Checkout with PayPal"> </form> 這個form中包含了一些PayPal支付必須要加的項,需要注意的是notify.php是PayPal會在后臺進行調用的 notify.php這個頁面有兩個功能,一個是接收PayPal的post內容并加上標簽返回,一個是接收到PayPal的認證信息之后進行網站內部的邏輯處理

    $req = 'cmd=_notify-validate';
    foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
    }
    // post back to PayPal system to validate
    $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
    if (!$fp) {
    // HTTP ERROR

    } else {//HTTP OK
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    if (strcmp ($res, "VERIFIED") == 0) {

    //process business of website

    }
    else if (strcmp ($res, "INVALID") == 0) {
    // log for manual investigation

    }
    }
    fclose ($fp);
    }

    轉載于:https://www.cnblogs.com/wengyuli/archive/2012/02/05/2338910.html

    總結

    以上是生活随笔為你收集整理的PHP中集成PayPal标准支付的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。