php 接入 paypal 支付

來源:互聯網
上載者:User

第一步、開啟https://www.paypal.com/官網,申請一個paypal帳號。
第二步、登入帳號,並進入https://developer.paypal.com/developer/accounts/。可以看到你申請帳號自動配屬的兩個測試帳號,帳號類別分別是:BUSINESS和PERSONAL,PERSONAL的帳號裡面有$9999。
第三步、給兩個帳號設定密碼,點擊帳號展開,然後點擊Profile,彈出帳號資訊框,進行設定密碼等屬性。
第四步、在項目支付頁面寫入下面代碼
(paypal的測試環境網域名稱為www.sandbox.paypal.com,正式網域名稱為www.paypal.com。)

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="paypal"><input type="hidden" name="cmd" value="_xclick"><input type="hidden" name="business" value="paypal收款帳號"><input type="hidden" name="item_name" value="商品名稱-PCB Online Payment"><input type="hidden" name="item_number" value="可以寫入訂單ID(備選項)"><input type="hidden" name="cancel_return" value="取消支付返回url">    <input type="hidden" name="notify_url" value="支付完成返回url">   <input type="hidden" name="return" value="支付完成返回url">  <!-- 貨幣種類,USD為美元 --><input type="hidden" name="currency_code" value="USD"><!-- 支付金額 --><input type="hidden" name="amount" value="8.88"><input type="submit" value="立即支付" class="sbtn4" /></form>

第五步、處理返回資訊
確認“payment_status”為“Completed”,因為系統也會 為其他結果(如“Pending”或“Failed”)發送 IPN。
檢查“txn_id”是否未重複,以防止欺詐者重複使用舊的已 完成的交易。
驗證“receiver_email”是已在您的PayPal賬戶中註冊的電子郵件地址,以防止將付款發送到欺詐者的賬 戶 。
檢查其他交易詳情(如物品號和價格),以確認價格未改變完成了以上檢查後,您可以使用 IPN 資料更新您的資料庫,並處理購物。
如果收到“無效”通知,則應將其視為可疑通知,並應對其進行調查。

/***處理返回資訊的方法*/public function notify(){        if ($this->user_id == false){            $this->redirect('user/login');        }        $result = $_POST;        $order_id = $result['item_number'];        if ($order_id){            $order = D('order')->find($order_id);            $this->assign('order_num',$order['order_num']);            //1、先更新訂單狀態            if (($order['pay_status'] == 0) && ($result['payment_status'] == 'Completed') ){// 支付成功                $this->update_order($result);            }            //2、才能添加支付記錄            if ($order['pay_status'] == 0){                $this->add_payment_logs($result);            }        }        $this->assign('order_id',$order_id);        $this->assign('payment_status',$result['payment_status']);        $this->assign('payment_gross',$result['payment_gross']);        $this->assign('seo_title','notify');        $this->display();    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.