Esempio n. 1
0
        public IActionResult ExecutePayment(string paymentId, string PayerID)
        {
            var payment = _PaypalServices.ExecutePayment(paymentId, PayerID);

            // Hint: You can save the transaction details to your database using payment/buyer info
            return(Ok());
        }
Esempio n. 2
0
        public IActionResult ExecutePayment(string paymentId, string token, string PayerID)
        {
            Payment payment = _PaypalServices.ExecutePayment(paymentId, PayerID);

            if (payment.state == "approved")
            {
                int SubId = Convert.ToInt32(payment.transactions[0].custom);

                var model = subscriptionService.GetBusiness_SubscriptionById(SubId);

                model.PaidAmount          = Convert.ToDecimal(payment.transactions[0].amount.total);
                model.Currency            = payment.transactions[0].amount.currency;
                model.PaymentReceived     = true;
                model.PaymentVia          = payment.payer.payment_method;
                model.PaymentReceipt      = payment.id;
                model.PaymentReceivedDate = Convert.ToDateTime(payment.create_time);
                model.PaymentNotes        = payment.cart + " - " + payment.transactions[0].related_resources[0].sale.payment_mode;

                var response = subscriptionService.MapViewModelToBusiness_Subscription(model, model.IdentityUserId, true);

                try
                {
                    StringBuilder str = new StringBuilder();

                    str.Append("<p>Your Payment is processed successfully.</p><br>");
                    str.Append("<table cellspacing='0' cellpadding='0' border='0' style='width:100%;'>");
                    str.Append("<tbody>");
                    str.Append("<tr><td style='width: 80px;font-weight:bold'>Email: </td><td>" + model.IdentityUserId + "</td></tr>");
                    str.Append("<tr><td style='width: 80px;font-weight:bold'>Paid Amount: </td><td>" + model.PaidAmount.ToString("#,##0.00") + "</td></tr>");
                    str.Append("<tr><td style='width: 80px;font-weight:bold'>Currency: </td><td>" + model.Currency + "</td></tr>");
                    str.Append("<tr><td style='width: 80px;font-weight:bold'>PaymentVia: </td><td>" + model.PaymentVia + "</td></tr>");
                    str.Append("<tr><td style='width: 80px;font-weight:bold'>Payment Receipt: </td><td>" + model.PaymentReceipt + "</td></tr>");
                    str.Append("<tr><td style='width: 80px;font-weight:bold'>Payment Received Date: </td><td>" + Convert.ToDateTime(payment.create_time) + "</td></tr>");
                    str.Append("</tbody>");
                    str.Append("</table>");
                    new Email().SendEmail("*****@*****.**", "Pharmix Subscription Email", str.ToString());
                    new Email().SendEmail(model.IdentityUserId, "Pharmix Subscription Email", str.ToString());
                }
                catch { }
            }
            return(Ok());
        }
Esempio n. 3
0
        public IActionResult ExecutePayment(string paymentId, string token, string PayerID)
        {
            Payment payment = _PaypalServices.ExecutePayment(paymentId, PayerID);

            if (payment.state == "approved")
            {
                int PackagePlanId = Convert.ToInt32(payment.transactions[0].custom);
                var plan          = packagePlanService.GetPackagePlanById(PackagePlanId);

                DateTime StartDate = DateTime.Now;
                DateTime EndDate   = DateTime.Now;
                if (plan.Duration == "Monthly")
                {
                    EndDate = DateTime.Now.AddMonths(1);
                }
                else if (plan.Duration == "Annual")
                {
                    EndDate = DateTime.Now.AddYears(1);
                }

                Business_Subscription model = new Business_Subscription
                {
                    IdentityUserId      = CurrentUserName,
                    PackagePlanId       = PackagePlanId,
                    StartDate           = StartDate,
                    EndDate             = EndDate,
                    PaidAmount          = Convert.ToDecimal(payment.transactions[0].amount.total),
                    Currency            = payment.transactions[0].amount.currency,
                    PaymentReceived     = true,
                    PaymentVia          = payment.payer.payment_method,
                    PaymentReceipt      = payment.id,
                    PaymentReceivedDate = Convert.ToDateTime(payment.create_time),
                    PaymentNotes        = payment.cart + " - " + payment.transactions[0].related_resources[0].sale.payment_mode
                };

                var response = subscriptionService.MapViewModelToBusiness_Subscription(model, CurrentUserName, true);
            }
            return(Ok());
        }
        public IActionResult ExecutePayment(string paymentId, string token, string PayerID, Guid id, Guid dataGuid)
        {
            var payment = _paypalServices.ExecutePayment(paymentId, PayerID);

            var vChalet = _dbContext.Chalet.Where(x => x.unique_id == id).FirstOrDefault();

            if (vChalet == null)
            {
                return(RedirectToAction("Cancel"));
            }

            var vHelperData = _dbContext.ReservationDataHelper.Where(x => x.unique_id == dataGuid).LastOrDefault();

            if (vHelperData == null)
            {
                return(RedirectToAction("Cancel"));
            }

            var vReservation = new ReservationModel()
            {
                dt           = DateTime.Now,
                chalet_id    = vChalet.chalet_id,
                dt_from      = vHelperData.dt_from,
                dt_to        = vHelperData.dt_to,
                is_full_day  = vHelperData.is_full_day,
                amount       = vHelperData.amount,
                currency     = vHelperData.currency,
                people_count = vHelperData.people_count,
                color        = vHelperData.color,
                user_id      = vHelperData.user_id
            };

            _dbContext.Reservation.Add(vReservation);
            _dbContext.SaveChanges();

            return(Ok());
        }
        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));
        }