public bool UpdateRefundPaypal(RefundPaypal links)
 {
     _unitOfWork.Repository <RefundPaypal>().Update(links);
     return(_unitOfWork.Save());
 }
Пример #2
0
        public IActionResult RefundPaypal(string TransId)
        {
            var             trans        = _TransactionsService.GetTransactionById(TransId);
            APIResponseData responseData = new APIResponseData();

            responseData.StatusCode  = 0;
            responseData.Message     = "Failed.";
            responseData.Result.Data = new
            {
                TransactionId = TransId,
                Status        = "Fail"
            };
            try
            {
                var RelatedTrans = _IRelatedTransaction.GetRelatedTransactionDetails(TransId).OrderByDescending(x => x.create_time).FirstOrDefault();
                if (RelatedTrans != null)
                {
                    var refund = _PaypalServices.RefundPayment(RelatedTrans.IdRelatedSale, RelatedTrans.parent_payment);
                    responseData.StatusCode  = 1;
                    responseData.Message     = "Success";
                    responseData.Result.Data = new
                    {
                        TransactionId = TransId,
                        Status        = refund.state
                    };

                    var RefundPaypal = new RefundPaypal()
                    {
                        reason         = refund.reason,
                        description    = refund.description,
                        state          = refund.state,
                        parent_payment = refund.parent_payment,
                        RefundID       = refund.id,
                        sale_id        = refund.sale_id,
                        TransID        = TransId
                    };
                    RefundserviceRepository.InsertRefundPaypal(RefundPaypal);

                    var PaymentLogs = new PaymentLogs()
                    {
                        Data         = Newtonsoft.Json.JsonConvert.SerializeObject(refund),
                        Error        = "Success",
                        PaymentType  = "PAYPAL",
                        FunctionName = "RefundPaypal",
                        TransID      = TransId
                    };
                    _PaymentLogsService.InsertPaymentLogs(PaymentLogs);
                }
            }
            catch (Exception ex)
            {
                responseData.StatusCode = 0;
                responseData.Message    = "Something went wrong, please try again.";
                var typeEx = ex.GetType();
                if (typeEx.FullName == "PayPal.PayPalException")
                {
                    dynamic excep       = ex.InnerException;
                    dynamic sourceEx    = excep.InnerExceptions[0].Response;
                    var     PaymentLogs = new PaymentLogs()
                    {
                        Data         = Newtonsoft.Json.JsonConvert.SerializeObject(trans),
                        Error        = sourceEx,
                        PaymentType  = "PAYPAL",
                        FunctionName = "RefundPaypal",
                        TransID      = TransId
                    };
                    _PaymentLogsService.InsertPaymentLogs(PaymentLogs);
                }
                else
                {
                    var PaymentLogs = new PaymentLogs()
                    {
                        Data         = Newtonsoft.Json.JsonConvert.SerializeObject(trans),
                        Error        = ex.InnerException.Message,
                        PaymentType  = "PAYPAL",
                        FunctionName = "RefundPaypal",
                        TransID      = TransId
                    };
                    _PaymentLogsService.InsertPaymentLogs(PaymentLogs);
                }

                EmailHelpers.SendEmail(new Common.DTO.ErrorInfo()
                {
                    Section   = $"AQ RefundPaypal PaymentType: PAYPAL <br /> TransactionID : {TransId}",
                    Exception = ex
                });
            }
            return(Ok(responseData));
        }
 public void InsertRefundPaypal(RefundPaypal refund)
 {
     _unitOfWork.Repository <RefundPaypal>().Add(refund);
 }