Manoj Maharana

Manoj Maharana

  • NA
  • 362
  • 123.6k

How do i get transaction id from Paypal using mvc 4 c#

Feb 22 2017 3:43 AM

How do i get transaction id from Paypal using mvc 4 c#. I have tried a lot of the code but not working. Here is the sample of the code:

in web.config: 

  1. <add key="CancelPurchaseUrl" value="http://localhost:5799/Unit/Index" />  
  2. <add key="ReturnUrl" value="http://localhost:5799/Unit/GetResponse" />  
  3. <add key="NotifyUrl" value="http://localhost:5799/Unit/GetResponse" />  
  4. <add key="CurrencyCode" value="USD" />  
  5. <add key="UseSandbox" value="true" />  
  6. <add key="SendToReturnURL" value="true" />  
Here is the code:
  1. public ActionResult GetResponse()  
  2.         {  
  3.   
  4. try  
  5.             {  
  6.                 //ID, TransactionID, TransactionDate, Amount, UnitID, UserEmail, TransactionType  
  7.                 string TransactionID = "NO";  
  8.                 string TransactionDate = System.DateTime.Now.ToString();  
  9.                 string UnitID = Session["UnitID"].ToString();  
  10.                 string Amount = Session["payamount"].ToString();  
  11.                 string UserEmail = Session["UserEmailMain"].ToString();  
  12.                 string TransactionType = "Paypal";  
  13.                 string Quantity = Session["Quantity"].ToString();  
  14.   
  15.                 PayPalModel model = new PayPalModel();  
  16.                 model.TransactionID = TransactionID;  
  17.                 model.TransactionDate = TransactionDate;  
  18.                 model.UnitId = UnitID;  
  19.                 model.Amount = Amount;  
  20.                 model.UserEmail = UserEmail;  
  21.                 model.TransactionType = TransactionType;  
  22.                 model.Quantity = Quantity;  
  23.   
  24.                 Transaction items = new Transaction();  
  25.                 items.TransactionID = model.TransactionID;  
  26.                 items.TransactionDate = Convert.ToDateTime(model.TransactionDate);  
  27.                 items.UnitID = Convert.ToInt32(model.UnitId);  
  28.                 items.Amount = model.Amount;  
  29.                 items.UserEmail = model.UserEmail;  
  30.                 items.TransactionType = model.TransactionType;  
  31.                 items.Quantity = Convert.ToInt32(model.Quantity);  
  32.   
  33.                 //int insertresult = objAdmin.InsertTransaction(items);  
  34.             }  
  35.             catch { }  
  36.             return RedirectToAction("Index");  
  37.         }  

here i want to return the transactionid ..

so any suggestions???

 

Answers (2)