private async Task <IActionResult> GetThreeDsPaymentAsync(string sessionId)
        {
            GetPaymentResponse payment = await _checkoutApi.Payments.GetAsync(sessionId);

            //if (payment.Approved)
            //{
            //    return Redirect(_appSettings.ClientURL + "customer/payment-success");
            //}
            //else
            //{
            //    return Redirect(_appSettings.ClientURL + "customer/payment-failure");
            //}
            if (!payment.Approved)
            {
                if (payment.Actions != null)
                {
                    List <Checkout.Payments.PaymentActionSummary> paymentActionSummaries =
                        payment.Actions.ToList();

                    if (!string.IsNullOrEmpty(paymentActionSummaries[0].ResponseCode))
                    {
                        paymentActionSummaries[0].ResponseSummary = new PaymentStatusCodes().GetPaymentStatus(paymentActionSummaries[0].ResponseCode);
                    }
                }
            }

            if (payment.Approved)
            {
                CustomerRegistration customer = _customerService.GetCustomerwithEmail(
                    ((Checkout.Payments.CustomerResponse)payment.Customer).Email);

                await _paymentResponseService.InsertPaymentDetails(new PaymentResponseDto {
                    Amount            = Convert.ToDecimal(payment.Amount),
                    Cardscheme        = ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme,
                    Currency          = payment.Currency,
                    CardType          = ((Checkout.Payments.CardSourceResponse)payment.Source).CardType,
                    PaymentCustomerId = ((Checkout.Payments.CustomerResponse)payment.Customer).Id,
                    PaymentSourceId   = ((Checkout.Payments.CardSourceResponse)payment.Source).Id,
                    TransactionId     = payment.Id,
                    PaymentDate       = payment.RequestedOn,
                    PaymentStatus     = "Approved",
                    CustomerId        = customer.Id,
                    Card            = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).Last4),
                    TransactionType = ((Checkout.Payments.CardSourceResponse)payment.Source).Type,
                    OrderId         = 0
                });
            }
            return(Ok(payment));
        }
示例#2
0
        public async Task <IActionResult> PayOrder([FromBody] WalletHistoryDto walletHistoryDto)
        {
            try
            {
                var customerID = await _UsersService.getCustomerID(walletHistoryDto.CustomerID);

                if (walletHistoryDto.isExistingCard.Value)
                {
                    Checkout.Payments.PaymentResponse paymentResponse = walletHistoryDto.PaymentResponseSource;
                    string TrasnsactionId         = paymentResponse.Payment.Id;
                    string TransactionDescription = ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Scheme
                                                    + "****" + ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Last4;


                    await _PaymentResponseService.InsertPaymentDetails(new PaymentResponseDto
                    {
                        Amount            = Convert.ToDecimal(paymentResponse.Payment.Amount),
                        Cardscheme        = ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Scheme,
                        Currency          = paymentResponse.Payment.Currency,
                        CardType          = ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).CardType,
                        PaymentCustomerId = ((Checkout.Payments.CustomerResponse)paymentResponse.Payment.Customer).Id,
                        PaymentSourceId   = ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Id,
                        TransactionId     = paymentResponse.Payment.Id,
                        PaymentDate       = paymentResponse.Payment.ProcessedOn,
                        PaymentStatus     = "Approved",
                        CustomerId        = customerID,
                        Card            = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Last4),
                        TransactionType = ((Checkout.Payments.CardSourceResponse)paymentResponse.Payment.Source).Type,
                        OrderId         = walletHistoryDto.OrderID.Value
                    });
                }
                else
                {
                    if (walletHistoryDto.SourceId != null)
                    {
                        Checkout.Payments.GetPaymentResponse payment = walletHistoryDto.SourceId;

                        if (walletHistoryDto.SaveCard)
                        {
                            List <GetPaymentCardsDto> paymentCards = _paymentCardsService.GetPaymentByCustomer(walletHistoryDto.CustomerID);
                            var itemExists = paymentCards.Find(p => p.CardType == ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme &&
                                                               p.Expyear == Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryYear) &&
                                                               p.Expmonth == Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryMonth) &&
                                                               p.last4digits == Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).Last4)
                                                               );
                            if (itemExists == null)
                            {
                                await _paymentCardsService.InsertPaymentCards(
                                    new PaymentCardsDto
                                {
                                    CardCustomerId = ((Checkout.Payments.CustomerResponse)payment.Customer).Id,
                                    CardSourceId   = ((Checkout.Payments.CardSourceResponse)payment.Source).Id,
                                    CardType       = ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme,
                                    CustomerId     = customerID,
                                    Expyear        = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryYear),
                                    Expmonth       = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).ExpiryMonth),
                                    last4digits    = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).Last4)
                                }
                                    );
                            }
                        }
                        string TrasnsactionId         = payment.Id;
                        string TransactionDescription = ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme
                                                        + "****" + ((Checkout.Payments.CardSourceResponse)payment.Source).Last4;

                        await _PaymentResponseService.InsertPaymentDetails(new PaymentResponseDto
                        {
                            Amount            = Convert.ToDecimal(payment.Amount),
                            Cardscheme        = ((Checkout.Payments.CardSourceResponse)payment.Source).Scheme,
                            Currency          = payment.Currency,
                            CardType          = ((Checkout.Payments.CardSourceResponse)payment.Source).CardType,
                            PaymentCustomerId = ((Checkout.Payments.CustomerResponse)payment.Customer).Id,
                            PaymentSourceId   = ((Checkout.Payments.CardSourceResponse)payment.Source).Id,
                            TransactionId     = payment.Id,
                            PaymentDate       = payment.RequestedOn,
                            PaymentStatus     = "Approved",
                            CustomerId        = customerID,
                            Card            = Convert.ToInt32(((Checkout.Payments.CardSourceResponse)payment.Source).Last4),
                            TransactionType = ((Checkout.Payments.CardSourceResponse)payment.Source).Type,
                            OrderId         = walletHistoryDto.OrderID.Value
                        });
                    }
                }
                if (walletHistoryDto.OrderWalletPaymentAmount > 0)
                {
                    OrderPaymentDto OrderPaymentDto = new OrderPaymentDto
                    {
                        CustomerId  = walletHistoryDto.CustomerID,
                        OrderAmount = walletHistoryDto.OrderWalletPaymentAmount.ToString(),
                        OrderId     = walletHistoryDto.OrderID.Value.ToString()
                    };
                    await _WalletHistoryService.OrderWalletPayment(OrderPaymentDto);
                }
                await _OrdersService.UpdatePaymentStatus(Convert.ToInt32(walletHistoryDto.OrderID));
            }

            catch (Exception err)
            {
                return(BadRequest(new GenericResultDto <string> {
                    Result = err.Message
                }));
            }
            return(Ok(new GenericResultDto <string> {
                Result = "Insert successfully"
            }));
        }