如何在成功交易后从PayPal获取收据编号

时间:2017-12-02 10:12:52

标签: c# .net

我刚才提到了这个链接http://www.geeksblood.com/integrate-paypal-in-asp-net/。此代码适用于成功交易PayPal显示收据编号。我想将收据编号存储在数据库中,因此如何从PayPal获取收据编号。

[HttpPost]
public void Plans(UserRegistreModel model)
{
        string ramount = Convert.ToString(model.Amount);
        TempData["model"] = model;
        string redirecturl = "";
        string firstName = model.FirstName;
        //string amount = Convert.ToString(model.Amount);
        //string productInfo = "HRMS";
        string itemInfo = "test";
        string email = model.Email;
        string phone = model.Contact;
        string middleName = model.MiddleName;
        string lastName = model.LastName;
        string Noofemp = model.NoOfEmployees;
        string FirmName = model.FirmName;
        string price = model.price;
        string package = model.package;
        string amount = Convert.ToString(model.Amount);
        redirecturl += "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=" +
        ConfigurationManager.AppSettings["paypalemail"].ToString();
        TempData["message"] = model.Payment;
        //First name i assign static based on login details assign this value
        redirecturl += "&first_name=" + firstName;

        //Product Name
        redirecturl += "&amount=" + amount;

        //Phone No
        redirecturl += "&night_phone_a=" + phone;

        //Product Name
        redirecturl += "&item_name=" + itemInfo;

        //Address
        redirecturl += "&email=" + email;
        //Business contact id
        //redirecturl += "&business=ritesh4714-facilitator@gmail.com";

        //Shipping charges if any
        //redirecturl += "&shipping=0";

        //Handling charges if any
        //redirecturl += "&handling=0";

        //Tax amount if any
        //redirecturl += "&tax=0";

        //Add quatity i added one only statically
        //redirecturl += "&quantity=1";

        //Success return page url
        redirecturl += "&return=" + ConfigurationManager.AppSettings["SuccessURL"].ToString();

        //Failed return page url
        redirecturl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();

        Response.Redirect(redirecturl);

}

1 个答案:

答案 0 :(得分:0)

您应该查找此主题"如何处理即时付款通知(IPN)消息"

作为文件https://developer.paypal.com/docs/classic/ipn/ht_ipn/

  

IPN是一种消息服务,可在您的帐户中发生任何类型的交易时向您发送通知。邮件由您的服务器接收和处理。

和C#示例https://github.com/paypal/ipn-code-samples/blob/master/C%23/paypal_ipn_mvc.cs

private void ProcessVerificationResponse(string verificationResponse)
{
    if (verificationResponse.Equals("VERIFIED"))
    {
        // check that Payment_status=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 (verificationResponse.Equals("INVALID"))
    {
        //Log for manual investigation
    }
    else
    {
        //Log error
    }
}

示例IPN消息和响应 https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNIntro/#a-sample-ipn-message-and-response