1

asp.netプロジェクトでpaypalapiを実装する方法を見つけようとしています。

基本的に、私が達成しようとしているのは、ユーザーが送金するページと支払いがチェックされるページを作成することです。

お支払いを確認する方法が見つかりませんでした。

SQLデータベースにデータを挿入するために支払いが行われたかどうかを確認する必要があり、支払い/確認方法を使用してデータベースを悪用したくないため、これは私のプロジェクトの重要なステップです。

誰かが私を導くことができますか?

前もって感謝します、

4

1 に答える 1

3

PayPal IPN(即時支払い通知)をお探しだと思います。それはまさにこの目的のために意図されています。

基本的に、PayPalはサイトの特別なページ/ハンドラーを呼び出し、トランザクションが正常に完了し、ユーザーに製品を安全にリリースできることを表明します。ハンドシェイクが発生する方法により、この呼び出しを信頼できます。

サンプルIPNハンドラー

このコードはPayPalのドキュメントから直接引用したものですが、私はそのバリエーションを自分で実装し、「宣伝どおり」に機能することを検証できます。

using System;
using System.IO;
using System.Text;
using System.Net;
using System.Web;

public partial class csIPNexample : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Post back to either sandbox or live
        string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
        string strLive = "https://www.paypal.com/cgi-bin/webscr";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);

        //Set values for the request back
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
        string strRequest = Encoding.ASCII.GetString(param);
        strRequest += "&cmd=_notify-validate";
        req.ContentLength = strRequest.Length;

        //for proxy
        //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
        //req.Proxy = proxy;

        //Send the request to PayPal and get the response
        StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
        streamOut.Write(strRequest);
        streamOut.Close();
        StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
        string strResponse = streamIn.ReadToEnd();
        streamIn.Close();

        if (strResponse == "VERIFIED")
        {
            //check the payment_status is Completed
            //check that txn_id has not been previously processed
            //check that receiver_email is your Primary PayPal email
            //check that payment_amount/payment_currency are correct
            //process payment
        }
        else if (strResponse == "INVALID")
        {
            //log for manual investigation
        }
        else
        {
            //log response/ipn data for manual investigation
        }
    }
}
于 2013-02-26T17:42:39.840 に答える