public ReturnObject <int> ConfirmPayment(ConfirmPaymentObject confirmPaymentObject) { ReturnObject <int> response; if (authManager.CanDoOperation(confirmPaymentObject.ClientId, Constants.OPERATION_PAYMENT_CONFIRM)) { response = paymentManager.ConfirmPayment(confirmPaymentObject, DateTime.Now); } else { log.WarnFormat("The client: {0} tried to access to ConfirmPayment and does not has access", confirmPaymentObject.ClientId); response = new ReturnObject <int>(0); response.addWarnMsg("Access denied"); response.Code = ReturnObject <int> .RETURN_CODE_UNAUTHORIZED; } return(response); }
public ReturnObject <int> ConfirmPayment(ConfirmPaymentObject confirmPaymentObject, DateTime date) { //create the object to return later ReturnObject <int> response = new ReturnObject <int>(0); try { //check if have all the data needed in the object if (String.IsNullOrWhiteSpace(confirmPaymentObject.GatewayReference) || String.IsNullOrWhiteSpace(confirmPaymentObject.GatewayResponse)) { log.InfoFormat("reference {0} or response{1} are empty", confirmPaymentObject.GatewayReference, confirmPaymentObject.GatewayResponse); response.addErrorMsg(Properties.Settings.Default.errorMessageMisingInfo); response.Code = ReturnObject <int> .RETURN_CODE_BAD_REQUEST; return(response); } //check if the entities are in the db PaymentStatus status = paymentDao.GetPaymentStatusById(confirmPaymentObject.StatusId); Payment payment = paymentDao.GetPaymentById(confirmPaymentObject.PaymentId); Client client = paymentDao.GetClientById(confirmPaymentObject.ClientId); //of one of them are missing exit with message if (status == null || client == null) { log.InfoFormat("status {0} or client {1} are null", status, client); response.addErrorMsg(Properties.Settings.Default.errorMessageMisingData); response.Code = ReturnObject <int> .RETURN_CODE_BAD_REQUEST; return(response); } //check if the payment got exist in the db, if not exit with message if (payment == null) { log.InfoFormat("payment id {0} not found", confirmPaymentObject.PaymentId); response.addErrorMsg(Properties.Settings.Default.errorMessagePaymentNotFound); response.Code = ReturnObject <int> .RETURN_CODE_NOT_FOUND; return(response); } //chack that the status of the payment is the one that can be changed if (payment.payment_status_id != Constants.PAYMENT_STATUS_NEW_ID) { log.WarnFormat("payment {0} has not status new", payment); response.addErrorMsg(Properties.Settings.Default.errorMessageUnchangebleStatus); response.Code = ReturnObject <int> .RETURN_CODE_PRECONDITION_FAILED; return(response); } //create the GatewayPaymentData and confirm the payment Payment updated = paymentDao.ConfirmPaymentAddingGatewayPaymentData(payment, status, confirmPaymentObject.GatewayResponse, confirmPaymentObject.GatewayReference, date); response.set(updated.payment_id); response.Code = ReturnObject <int> .RETURN_CODE_OK; log.InfoFormat("the payment {0} have been confirm with the status {1}", updated, status); return(response); } //handling validation errors catch (System.Data.Entity.Validation.DbEntityValidationException e) { log.ErrorFormat("exception {0} was thrown when ConfirmPayment, message: {1} trace: {2}", e, e.Message, e.StackTrace); response.addWarnMsg(Properties.Settings.Default.warnFieldsNotValid); response.Code = ReturnObject <int> .RETURN_CODE_BAD_REQUEST; return(response); } catch (Exception e) { log.ErrorFormat("exception {0} was thrown when ConfirmPayment, message: {1} trace: {2}", e, e.Message, e.StackTrace); response.addErrorMsg(Properties.Settings.Default.errorMessageInternalError); response.Code = ReturnObject <int> .RETURN_CODE_INTERNAL_ERROR; return(response); } }