简体   繁体   中英

How to get receipt number from PayPal after the successful transaction

I have just referred this link http://www.geeksblood.com/integrate-paypal-in-asp-net/ . This code works fine with successful transaction PayPal shows receipt number. I want to store the receipt number in the database, so how do I get receipt number from 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);

}

You should look for this topic "How to process Instant Payment Notification (IPN) messages"

As document https://developer.paypal.com/docs/classic/ipn/ht_ipn/

IPN is a message service that sends you a notification when any type of transaction occurs in your account. The messages are received and processed by your server(s).

and C# example 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
    }
}

A Sample IPN Message and Response https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNIntro/#a-sample-ipn-message-and-response

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM