public bool UpdateLinksRelated(LinksRelated links)
 {
     _unitOfWork.Repository <LinksRelated>().Update(links);
     return(_unitOfWork.Save());
 }
Пример #2
0
        public IActionResult ExecutePaymentPayPal(InfoPayment infoPayment)
        {
            APIResponseData responseData = new APIResponseData();

            responseData.StatusCode = 0;
            responseData.Message    = "Failed.";
            try
            {
                var payment = _PaypalServices.ExecutePayment(infoPayment.PaymentId, infoPayment.PayerId);

                var result = _TransactionsService.GetTransactionById(infoPayment.TranId);
                result.PaymentCardToken = infoPayment.PaymentToken;
                result.StripeCustomerId = infoPayment.PayerId;
                result.Status           = payment.state;
                result.ModifiedDate     = DateTime.Now;

                _TransactionsService.UpdateTransactions(result);


                foreach (var tran in payment.transactions)
                {
                    foreach (var item in tran.related_resources)
                    {
                        var RelatedTrans = new RelatedTransactionDetails()
                        {
                            totalAmount                 = Convert.ToDecimal(item.sale.amount.total),
                            TransID                     = result.ID.ToString(),
                            currency                    = item.sale.amount.currency,
                            IdRelatedSale               = item.sale.id,
                            payment_mode                = item.sale.payment_mode,
                            state                       = item.sale.state,
                            protection_eligibility      = item.sale.protection_eligibility,
                            protection_eligibility_type = item.sale.protection_eligibility_type,
                            parent_payment              = item.sale.parent_payment,
                        };
                        _IRelatedTransaction.InsertRelatedTransactionDetails(RelatedTrans);
                        foreach (var link in item.sale.links)
                        {
                            var LinksRelated = new LinksRelated()
                            {
                                href   = link.href,
                                method = link.method,
                                rel    = link.rel,
                                IdRelatedTransaction = RelatedTrans.ID,
                            };
                            linksRelatedService.InsertLinksRelated(LinksRelated);
                        }
                    }
                }


                // Hint: You can save the transaction details to your database using payment/buyer info
                responseData.StatusCode  = 1;
                responseData.Message     = "Success";
                responseData.Result.Data = new
                {
                    TransactionId = infoPayment.TranId,
                    Status        = payment.state
                };

                var PaymentLogs = new PaymentLogs()
                {
                    Data         = Newtonsoft.Json.JsonConvert.SerializeObject(payment),
                    Error        = "Success",
                    PaymentType  = "PAYPAL",
                    FunctionName = "ExecutePaymentPayPal",
                    TransID      = infoPayment.TranId
                };
                _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 == null ? "" : excep?.InnerExceptions[0]?.Response;
                    var     PaymentLogs = new PaymentLogs()
                    {
                        Data         = Newtonsoft.Json.JsonConvert.SerializeObject(infoPayment),
                        Error        = sourceEx,
                        PaymentType  = "PAYPAL",
                        FunctionName = "ExecutePaymentPayPal",
                        TransID      = infoPayment.TranId
                    };
                    _PaymentLogsService.InsertPaymentLogs(PaymentLogs);
                }
                else
                {
                    var PaymentLogs = new PaymentLogs()
                    {
                        //Data = Newtonsoft.Json.JsonConvert.SerializeObject(infoPayment),
                        Data         = Newtonsoft.Json.JsonConvert.SerializeObject(infoPayment),
                        Error        = ex.InnerException.Message,
                        PaymentType  = "PAYPAL",
                        FunctionName = "ExecutePaymentPayPal",
                        TransID      = infoPayment.TranId
                    };
                    _PaymentLogsService.InsertPaymentLogs(PaymentLogs);
                }


                EmailHelpers.SendEmail(new Common.DTO.ErrorInfo()
                {
                    Section   = $"ExecutePaymentPayPal <br /> TransactionID : {infoPayment.TranId}",
                    Exception = ex
                });
            }

            return(Ok(responseData));
        }
 public void InsertLinksRelated(LinksRelated links)
 {
     _unitOfWork.Repository <LinksRelated>().Add(links);
     //return _unitOfWork.Save();
 }