public RedirectResult ReturnURL() { StringBuilder log = new StringBuilder(); log.Append(UtilityResource.ReturnURLstart.Replace("{MethodName}", UtilityResource.ReturnURL)); LogManagers.LogManagers.WriteTraceLog(log); string cancelRequest = Request.Query["cancel"]; PayPalResponseModel model = new PayPalResponseModel(); try { if (string.IsNullOrWhiteSpace(cancelRequest)) { var result = _paypalservice.ExecutePayment(Request.Query["PayerID"], Request.Query["paymentId"]); model.Id = result.id; model.CreateTime = DateTime.Parse(result.create_time); model.UpdateTime = DateTime.Parse(result.update_time); model.Intent = result.intent; model.PaymentMethod = result.payer.payment_method; model.PayerId = result.payer.payer_info.payer_id; model.Amount = decimal.Parse(result.transactions[0].amount.total.ToString()); model.Currency = result.transactions[0].amount.currency; model.Description = result.transactions[0].description; model.Status = result.state; model.InvoiceNumber = result.transactions[0].invoice_number; var JSONRes = JsonConvert.SerializeObject(result); model.FullResponse = JSONRes; var res = _playerservice.SavePayPalResponse(model); log.Append(UtilityResource.ExecutedSuccessfully.Replace("{MethodName}", UtilityResource.ReturnURL)); LogManagers.LogManagers.WriteTraceLog(log); return(RedirectToSuccess(model)); } else { log.Append(UtilityResource.ReturnToCancel.Replace("{MethodName}", UtilityResource.ReturnURL)); LogManagers.LogManagers.WriteTraceLog(log); return(RedirectToCancel()); } } catch (Exception ex) { log.Append(UtilityResource.ErrorInMethod.Replace("{MethodName}", UtilityResource.ReturnURL).Replace("{ErrorMessage}", ex.Message)); LogManagers.LogManagers.WriteErrorLog(ex); return(RedirectToFailed(ex.ToString())); } }
/// <summary> /// Save PayPal Response in database /// </summary> /// <param name="model"></param> /// <returns></returns> public string SavePayPalResponse(PayPalResponseModel model) { StringBuilder log = new StringBuilder(); string response = string.Empty; string requestParameter = "Id = " + model.Id + ", " + "CreateTime = " + model.CreateTime + ", " + "UpdateTime = " + model.UpdateTime + ", " + "Intent = " + model.Intent + ", " + "PaymentMethod = " + model.PaymentMethod + ", " + "PayerId = " + model.PayerId + ", " + "Amount = " + model.Amount + ", " + "Currency = " + model.Currency + ", " + "Description = " + model.Description + ", " + "Status = " + model.Status + "FullResponse = " + model.FullResponse; log.Append(UtilityResource.LogServiceStartMessage.Replace("{MethodName}", UtilityResource.SavePaypalResonseService).Replace("{RequestParameter}", requestParameter)); try { this._dbContext.Database.OpenConnection(); DbCommand cmd = this._dbContext.Database.GetDbConnection().CreateCommand(); cmd.CommandText = UtilityResource.SavePaypalResonseSP; DbParameter Id = cmd.CreateParameter(); Id.DbType = DbType.String; Id.ParameterName = "@Id"; Id.Value = model.Id; cmd.Parameters.Add(Id); DbParameter CreateTime = cmd.CreateParameter(); CreateTime.DbType = DbType.DateTime; CreateTime.ParameterName = "@CreateTime"; CreateTime.Value = model.CreateTime; cmd.Parameters.Add(CreateTime); DbParameter UpdateTime = cmd.CreateParameter(); UpdateTime.DbType = DbType.DateTime; UpdateTime.ParameterName = "@UpdateTime"; UpdateTime.Value = model.UpdateTime; cmd.Parameters.Add(UpdateTime); DbParameter Intent = cmd.CreateParameter(); Intent.DbType = DbType.String; Intent.ParameterName = "@Intent"; Intent.Value = model.Intent; cmd.Parameters.Add(Intent); DbParameter PaymentMethod = cmd.CreateParameter(); PaymentMethod.DbType = DbType.String; PaymentMethod.ParameterName = "@PaymentMethod"; PaymentMethod.Value = model.PaymentMethod; cmd.Parameters.Add(PaymentMethod); DbParameter PayerId = cmd.CreateParameter(); PayerId.DbType = DbType.String; PayerId.ParameterName = "@PayerId"; PayerId.Value = model.PayerId; cmd.Parameters.Add(PayerId); DbParameter Amount = cmd.CreateParameter(); Amount.DbType = DbType.Decimal; Amount.ParameterName = "@Amount"; Amount.Value = model.Amount; cmd.Parameters.Add(Amount); DbParameter Currency = cmd.CreateParameter(); Currency.DbType = DbType.String; Currency.ParameterName = "@Currency"; Currency.Value = model.Currency; cmd.Parameters.Add(Currency); DbParameter Description = cmd.CreateParameter(); Description.DbType = DbType.String; Description.ParameterName = "@Description"; Description.Value = model.Description; cmd.Parameters.Add(Description); DbParameter Status = cmd.CreateParameter(); Status.DbType = DbType.String; Status.ParameterName = "@Status"; Status.Value = model.Status; cmd.Parameters.Add(Status); DbParameter InvoiceNumber = cmd.CreateParameter(); InvoiceNumber.DbType = DbType.String; InvoiceNumber.ParameterName = "@InvoiceNumber"; InvoiceNumber.Value = model.InvoiceNumber; cmd.Parameters.Add(InvoiceNumber); DbParameter FullResponse = cmd.CreateParameter(); FullResponse.DbType = DbType.String; FullResponse.ParameterName = "@FullResponse"; FullResponse.Value = model.FullResponse; cmd.Parameters.Add(FullResponse); log.Append(UtilityResource.SPExecutionStart.Replace("{SPName}", UtilityResource.SavePaypalResonseSP)); cmd.CommandType = CommandType.StoredProcedure; var reader = cmd.ExecuteScalar(); log.Append(UtilityResource.SPExecutionEnd.Replace("{SPName}", UtilityResource.SavePaypalResonseSP)); response = UtilityResource.TransactionMessage; log.Append(UtilityResource.ServiceExecutedSuccessfully.Replace("{MethodName}", UtilityResource.SavePaypalResonseService)); } catch (Exception ex) { log.Append(UtilityResource.ErrorInMethod.Replace("{MethodName}", UtilityResource.SavePayPalResponse).Replace("{ErrorMessage}", ex.Message)); LogManagers.LogManagers.WriteErrorLog(ex); response = ex.Message; } finally { LogManagers.LogManagers.WriteTraceLog(log); this._dbContext.Database.CloseConnection(); } return(response); }
public RedirectResult RedirectToSuccess(PayPalResponseModel model) { return(RedirectPermanent(UtilityResource.PayPalSuccess + model.Id)); }