0

またどこでミスをしているのか理解できません。私はこのコードを実行しています:

<form id="frm" action="https://www.sandbox.paypal.com/cgi-bin/webscr">

<input id="cmd" name="cmd" type="hidden" value="_xclick" />
<input id="business" name="business" type="hidden"   value="anilcs_1361585097_biz@gmail.com" />
<input id="no_shipping" name="no_shipping" type="hidden" value="" />
 <input id="return" name="return" type="hidden" value="http://localhost:1552/Home/IPN"/>
<input id="cancel_return" name="cancel_return" type="hidden" value="http://localhost:1552/SportsStore/CancelFromPaypal" />
 <input id="notify_url" name="notify_url" type="hidden" value="http://localhost:1552/SportsStore/NotifyFromPaypal" />
 <input id="currency_code" name="currency_code" type="hidden" value="USD" />
 <input id="item_Name" name="item_Name" type="hidden" value="test" />
 <input id="amount" name="amount" type="hidden" value="10" />
 <input type="submit" value="PayPal">
</form>

正常に動作しており、VERIFIEDステータスを取得しています。

このコードを実行すると:

<form id="frm" action="https://www.sandbox.paypal.com/cgi-bin/webscr">

@*<input id="cmd" name="cmd" type="hidden" value="_xclick" />*@
<input id="cmd" name="cmd" type="hidden" value="_cart"/>
<input type="hidden" name="upload" value="1"/>
<input id="business" name="business" type="hidden" value="anilcs_1361585097_biz@gmail.com" />
@*<input id="no_shipping" name="no_shipping" type="hidden" value="" />*@
<input id="return" name="return" type="hidden" value="http://localhost:1552/Home/IPN" />
<input id="cancel_return" name="cancel_return" type="hidden" value="http://localhost:1552/SportsStore/CancelFromPaypal" />
<input id="notify_url" name="notify_url" type="hidden" value="http://localhost:1552/SportsStore/NotifyFromPaypal" />
<input id="currency_code" name="currency_code" type="hidden" value="USD" />

<input type="hidden" name="item_name_1" value="Football T-Shirt"/>
<input type="hidden" name="quantity_1" value="4"/>
<input type="hidden" name="amount_1" value="1.00"/>
<input type="hidden" name="on0_1" value="Color"/>
<input type="hidden" name="os0_1" value="Red"/>
<input type="hidden" name="on1_1" value="Size"/>
<input type="hidden" name="os1_1" value="Small"/>

<input type="hidden" name="item_name_2" value="Notebook"/>
<input type="hidden" name="quantity_2" value="2"/>
<input type="hidden" name="amount_2" value="2.00"/>
<input type="hidden" name="on0_2" value="Number of Pages"/>
<input type="hidden" name="os0_2" value="200"/>
<input type="hidden" name="on1_2" value="Type"/>
<input type="hidden" name="os1_2" value="3 Ring"/>
<input type="submit" value="PayPal">
</form>

からステータスを取得します

http://www.arunrana.net/2012/01/paypal-integration-in-mvc3-and-razor.html

これはC#の私のコードです

public ActionResult IPN()
    {

        try
        {
            var formVals = new Dictionary<string, string>();
            formVals.Add("cmd", "_notify-validate");


            string response = GetPayPalResponse(formVals, true);

            if (response == "VERIFIED")
            {

            }

        }
        catch (Exception ex)
        {
        }

        return View();
    }
    [HttpPost]
    string GetPayPalResponse(Dictionary<string, string> formVals, bool useSandbox)
    {

        string paypalUrl = useSandbox
                               ? "https://www.sandbox.paypal.com/cgi-bin/webscr"
                               : "https://www.paypal.com/cgi-bin/webscr";


        var req = (HttpWebRequest)WebRequest.Create(paypalUrl);

        // Set values for the request back
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";

       // byte[] param = Request.BinaryRead(Request.ContentLength);
       // byte[] param = Request.BinaryRead(HttpContext.Request.ContentLength);
        byte[] param = Request.BinaryRead(HttpContext.Request.ContentLength);
        string strRequest = Encoding.ASCII.GetString(param);

        var sb = new StringBuilder();
        sb.Append(strRequest);

        foreach (string key in formVals.Keys)
        {
            sb.AppendFormat("&{0}={1}", key, formVals[key]);
        }
        strRequest += sb.ToString();
        req.ContentLength = strRequest.Length;

        //for proxy
        //WebProxy proxy = new WebProxy(new Uri("http://urlort#");
        //req.Proxy = proxy;
        //Send the request to PayPal and get the response
        string response = "";
        using (var streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII))
        {
            streamOut.Write(strRequest);
            streamOut.Close();
            using (var streamIn = new StreamReader(req.GetResponse().GetResponseStream()))
            {
                response = streamIn.ReadToEnd();
            }
        }

        return response;
    }
}
4

0 に答える 0