예제 #1
0
        public void TestChargeCreditCardAmount()
        {
            foreach (string values in GenerateRandomString(1, 5))
            {
                transactionRequest.amount = Convert.ToDecimal(values);
                response = ChargeCreditCard.Run(apiLoginId, transactionKey, GetAmount(), transactionRequest);
                Assert.IsNotNull(response);
                Assert.AreEqual(response.messages.resultCode, messageTypeEnum.Ok);
            }
            foreach (string values in GenerateNegativeString(1, 5))
            {
                if (values != "")
                {
                    transactionRequest.amount = Convert.ToDecimal(values);
                }
                else
                {
                    transactionRequest.amount = 0;
                }

                response = ChargeCreditCard.Run(apiLoginId, transactionKey, GetAmount(), transactionRequest);
                Assert.IsNotNull(response);
                Assert.AreNotEqual(response.messages.resultCode, messageTypeEnum.Ok);
            }
        }
예제 #2
0
        public JsonResult SavePaymentRecord(IList <OrderNow> values)
        {
            if (values != null)
            {
                decimal amount   = GeneralModel.GetTotalAmount(values);
                var     response = ChargeCreditCard.Run(amount);
                if (response.refId != null)
                {
                    Order newOrder = new Order();
                    newOrder.userId     = Convert.ToInt32(Session["UserId"].ToString());
                    newOrder.dateTime   = DateTime.Now.ToString("HH:mm tt dd/MM/yyyy");
                    newOrder.status     = "Pending";
                    newOrder.totalPrice = amount.ToString();
                    newOrder.transId    = response.refId;

                    using (FoodOrderDbContext db = new FoodOrderDbContext())
                    {
                        db.Orders.Add(newOrder);
                        db.SaveChanges();
                    }

                    foreach (var item in values)
                    {
                        decimal itemid   = GeneralModel.GetItemID(item.Name);
                        decimal orderId  = GeneralModel.GetOrderId();
                        decimal quantity = item.count;
                        GeneralModel.SavetoItemDetials(itemid, orderId, quantity);
                        GeneralModel.UpdateQuantity(itemid, quantity);
                    }
                }
                return(Json(new { result = 1 }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new { result = 0 }, JsonRequestBehavior.AllowGet));
        }
예제 #3
0
        public ActionResult Pay()
        {
            //firstName = "John",

            //lastName = "Doe",
            string apiLoginId        = WebConfigurationManager.AppSettings["ApiLoginID"];
            string apiTransactionKey = WebConfigurationManager.AppSettings["ApiTransactionKey"];

            ChargeCreditCard.Run(apiLoginId, apiTransactionKey, 1000);
            return(RedirectToAction("Index"));
        }
예제 #4
0
        public void TestChargeCreditCardTerminalNumber()
        {
            foreach (string values in GenerateRandomString(4, 5000))
            {
                transactionRequest.terminalNumber = values;

                response = ChargeCreditCard.Run(apiLoginId, transactionKey, GetAmount(), transactionRequest);
                Assert.IsNotNull(response);
                Assert.AreEqual(response.messages.resultCode, messageTypeEnum.Ok);
            }
            foreach (string values in GenerateNegativeString(1, 50))
            {
                transactionRequest.solution.id = values;

                response = ChargeCreditCard.Run(apiLoginId, transactionKey, GetAmount(), transactionRequest);
                Assert.IsNotNull(response);
                Assert.AreNotEqual(response.messages.resultCode, messageTypeEnum.Ok);
            }
        }
예제 #5
0
        public void TestChargeCreditCardCreditCardNumber()
        {
            string[] possibleValues = { "41111111111111111", "411111111111" };
            foreach (string values in possibleValues)
            {
                transactionRequest.payment = new paymentType
                {
                    Item = new creditCardType
                    {
                        cardNumber     = values,
                        expirationDate = "0718",
                        cardCode       = "123"
                    }
                };

                response = ChargeCreditCard.Run(apiLoginId, transactionKey, GetAmount(), transactionRequest);
                Assert.IsNotNull(response);
                Assert.AreNotEqual(response.messages.resultCode, messageTypeEnum.Ok);
            }
        }
예제 #6
0
 public void TestChargeCreditInvoiceNumber()
 {
     foreach (string values in GenerateRandomString(2, 20))
     {
         transactionRequest.order = new orderType {
             invoiceNumber = values
         };
         response = ChargeCreditCard.Run(apiLoginId, transactionKey, GetAmount(), transactionRequest);
         Assert.IsNotNull(response);
         Assert.AreEqual(response.messages.resultCode, messageTypeEnum.Ok);
     }
     foreach (string values in GenerateNegativeString(1, 20))
     {
         transactionRequest.order = new orderType {
             invoiceNumber = values
         };
         response = ChargeCreditCard.Run(apiLoginId, transactionKey, GetAmount(), transactionRequest);
         Assert.IsNotNull(response);
         Assert.AreNotEqual(response.messages.resultCode, messageTypeEnum.Ok);
     }
 }
예제 #7
0
 public ActionResult Checkout(List <CartItemArray> arr, int total)
 {
     using (FoodOrderEntities db = new FoodOrderEntities())
     {
         var response = ChargeCreditCard.Run(total);
         if (response != null && response.check == true)
         {
             Order order = new Order();
             order.transId    = response.response;
             order.userId     = Convert.ToInt32(Session["UserID"].ToString());
             order.status     = "Pending";
             order.dateTime   = DateTime.Now.ToString("HH:mm tt dd/MM/yyyy");
             order.totalPrice = total.ToString();
             db.Orders.Add(order);
             db.SaveChanges();
             int id = Convert.ToInt32(order.orderId);
             foreach (var item in arr)
             {
                 OrderDetail orderDetail = new OrderDetail();
                 orderDetail.orderId  = id;
                 orderDetail.itemId   = item.id;
                 orderDetail.quantity = item.qty.ToString();
                 db.OrderDetails.Add(orderDetail);
                 db.SaveChanges();
                 var foodItem = db.FoodItems.Where(x => x.itemId == item.id).FirstOrDefault();
                 foodItem.quantity = (Convert.ToInt32(foodItem.quantity) - item.qty).ToString();
                 db.SaveChanges();
             }
             return(Content("true"));
         }
         else
         {
             return(Content("false"));
         }
     }
 }
예제 #8
0
 public ANetApiResponse TestChargeCreditCard()
 {
     return(ChargeCreditCard.Run(apiLoginId, transactionKey, GetAmount()));
 }
예제 #9
0
        public HttpResponseMessage Add(HttpRequestMessage request, PaymentViewModel paymentlist)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage Httpresponse = null;
                if (!string.IsNullOrEmpty(paymentlist.sloginUserInfo))
                {
                    var existingUserDb = _userRepository.GetSingleByUsername(paymentlist.sloginUserInfo);
                    if (existingUserDb != null)
                    {
                        var userrestaurantDb = _userrestaurantRepository.GetAll().Where(userrest => userrest.UserId == existingUserDb.ID).ToList();
                        foreach (var userrestaurant in userrestaurantDb)
                        {
                            var subscriptiondb = _subscriptionRepository.GetSingle(userrestaurant.RestaurantId);
                            if (paymentlist != null)
                            {
                                var response = (createTransactionResponse)ChargeCreditCard.Run(paymentlist);
                                //validate
                                if (response != null)
                                {
                                    if (response.messages.resultCode == messageTypeEnum.Ok)
                                    {
                                        if (response.transactionResponse.messages != null)
                                        {
                                            var subscriptionDb = _subscriptionRepository.GetSingle(subscriptiondb.ID);

                                            if (subscriptionDb == null)
                                            {
                                                Httpresponse = request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid Subscription.");
                                            }
                                            else
                                            {
                                                Subscription newsubscription = new Subscription();
                                                SubscriptionViewModel subscriptionvm = new SubscriptionViewModel();
                                                subscriptionvm.SubscriptionPlanId = Convert.ToInt32(paymentlist.iPlanID.ToString());
                                                subscriptionvm.StartDate = DateTime.UtcNow;
                                                subscriptionvm.EndDate = GetPlanIntervalEnddate(paymentlist.iPlanID);
                                                subscriptionvm.TransId = response.transactionResponse.transId.ToString();
                                                subscriptionDb.UpdateSubscription(subscriptionvm);

                                                _subscriptionRepository.Edit(subscriptionDb);
                                                _unitOfWork.Commit();
                                                Httpresponse = request.CreateResponse(HttpStatusCode.OK, response.transactionResponse);
                                            }
                                        }
                                        else
                                        {
                                            if (response.transactionResponse.errors != null)
                                            {
                                                Httpresponse = request.CreateResponse(HttpStatusCode.BadRequest, response.transactionResponse.errors);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (response.transactionResponse != null && response.transactionResponse.errors != null)
                                        {
                                            Httpresponse = request.CreateResponse(HttpStatusCode.BadRequest, response.transactionResponse.errors);
                                        }
                                        else
                                        {
                                        }
                                    }
                                }
                                else
                                {
                                    Httpresponse = request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Payment");
                                }
                            }
                        }
                    }
                }

                return Httpresponse;
            }));
        }
예제 #10
0
        //[Authorize(Policy = PermissionsList.PermissionsOrderAdd)]
        public async Task <IActionResult> AddOrder([FromBody] OrderModel order)
        {
            var         dishNames = order.Dishes.Select(d => d.Name).ToList();
            List <Dish> dishes    = (List <Dish>) await _orderRepository.GetDishList(dishNames);

            bool isPaid = false;

            if (dishes.Count == 0 ||
                User.Identity.Name != null ||
                !ModelState.IsValid)
            {
                return(BadRequest());
            }

            Guid orderId = Guid.NewGuid();

            decimal          totalPrice  = 0;
            var              lineItems   = new List <lineItemType>();
            List <OrderDish> orderDishes = new List <OrderDish>();

            var  userId    = User.Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).FirstOrDefault();
            User orderUser = await _userRepository.GetUserById(userId.Value);

            Order newOrder = new Order()
            {
                Id                  = orderId,
                User                = orderUser,
                OrderTime           = DateTime.Now,
                OrderExpirationTime = DateTime.Now.AddHours(1),
                IsForDelivery       = order.IsForDelivery,
                IsCancelled         = false,
                IsClosed            = false
            };


            dishes.ForEach(dish =>
            {
                var quantity = order.Dishes.Where(d => d.Name == dish.Name).FirstOrDefault().Quantity;
                lineItems.Add(new lineItemType
                {
                    itemId    = dish.Id.ToString(),
                    name      = dish.Name,
                    quantity  = quantity,
                    unitPrice = (decimal)dish.DishPrice
                });

                orderDishes.Add(new OrderDish
                {
                    Id       = Guid.NewGuid(),
                    Dish     = dish,
                    Order    = newOrder,
                    Quantity = quantity
                });

                totalPrice += (decimal)dish.DishPrice * quantity;
            });

            newOrder.TotalPrice = (float)totalPrice;
            newOrder.OrderItems = orderDishes;

            switch (order.PaymentType)
            {
            case PaymentTypes.CreditCard:
            {
                var creditCard = new creditCardType
                {
                    cardNumber     = order.CreditCard.CardNumber,
                    expirationDate = order.CreditCard.ExpirationDate,
                    cardCode       = order.CreditCard.CCV
                };

                var billingAddress = new customerAddressType
                {
                    firstName = order.BillingAddressModel.FirstName,
                    lastName  = order.BillingAddressModel.LastName,
                    address   = order.BillingAddressModel.Address,
                    city      = order.BillingAddressModel.City,
                    zip       = order.BillingAddressModel.ZIP
                };

                var response = ChargeCreditCard.Run(creditCard, billingAddress, lineItems, totalPrice);
                if (response.messages.resultCode != messageTypeEnum.Ok)
                {
                    return(BadRequest(new { error = "Couldn't process transaction" }));
                }
                else
                {
                    isPaid = true;
                }
                break;
            }

            case PaymentTypes.Cash:
            {
                break;
            }
            }

            newOrder.IsPaid = isPaid;

            _orderRepository.Create(newOrder);

            if (order.IsForDelivery)
            {
                Address address = await _addressRepository.GetById(order.DeliveryAddress.Id);

                if (address == null)
                {
                    address = new Address()
                    {
                        Id      = Guid.NewGuid(),
                        Name    = order.DeliveryAddress.Name,
                        City    = await _cityRepository.GetById(order.DeliveryAddress.City.Id),
                        Country = await _countryRepository.GetById(order.DeliveryAddress.Country.Id),
                        Street  = order.DeliveryAddress.Street
                    };

                    _addressRepository.Create(address);
                }

                Delivery delivery = new Delivery()
                {
                    Id = Guid.NewGuid(),
                    DeliveryAddress = address,
                    Order           = newOrder,
                    IsDelivered     = false
                };

                _deliveryRepository.Create(delivery);
            }

            return(Ok(new { order_id = orderId }));
        }
예제 #11
0
        private static void RunMethod(string methodName)
        {
            // These are default transaction keys.
            // You can create your own keys in seconds by signing up for a sandbox account here: https://developer.authorize.net/sandbox/
            string apiLoginId     = "5KP3u95bQpv";
            string transactionKey = "4Ktq966gC55GAX7S";

            string transactionAmount;
            string transactionId = string.Empty;

            switch (methodName)
            {
            case "ValidateCustomerPaymentProfile":
                ValidateCustomerPaymentProfile.Run(apiLoginId, transactionKey);
                break;

            case "UpdateCustomerShippingAddress":
                UpdateCustomerShippingAddress.Run(apiLoginId, transactionKey);
                break;

            case "UpdateCustomerProfile":
                UpdateCustomerProfile.Run(apiLoginId, transactionKey);
                break;

            case "UpdateCustomerPaymentProfile":
                UpdateCustomerPaymentProfile.Run(apiLoginId, transactionKey);
                break;

            case "GetCustomerShippingAddress":
                GetCustomerShippingAddress.Run(apiLoginId, transactionKey);
                break;

            case "GetCustomerProfileIds":
                GetCustomerProfileIds.Run(apiLoginId, transactionKey);
                break;

            case "GetCustomerProfile":
                GetCustomerProfile.Run(apiLoginId, transactionKey);
                break;

            case "GetCustomerPaymentProfile":
                GetCustomerPaymentProfile.Run(apiLoginId, transactionKey);
                break;

            case "DeleteCustomerShippingAddress":
                DeleteCustomerShippingAddress.Run(apiLoginId, transactionKey);
                break;

            case "DeleteCustomerProfile":
                DeleteCustomerProfile.Run(apiLoginId, transactionKey);
                break;

            case "DeleteCustomerPaymentProfile":
                DeleteCustomerPaymentProfile.Run(apiLoginId, transactionKey);
                break;

            case "CreateCustomerShippingAddress":
                CreateCustomerShippingAddress.Run(apiLoginId, transactionKey);
                break;

            case "CreateCustomerProfileFromTransaction":
                CreateCustomerProfileFromTransaction.Run(apiLoginId, transactionKey);
                break;

            case "GetTransactionDetails":
                GetTransactionDetails.Run(apiLoginId, transactionKey);
                break;

            case "GetTransactionList":
                GetTransactionList.Run(apiLoginId, transactionKey);
                break;

            //case "CreateAnApplePayTransaction":
            //    CreateAnApplePayTransaction.Run(apiLoginId, transactionKey);
            //    break;
            case "DecryptVisaCheckoutData":
                DecryptVisaCheckoutData.Run(apiLoginId, transactionKey);
                break;

            case "CreateVisaCheckoutTransaction":
                CreateVisaCheckoutTransaction.Run(apiLoginId, transactionKey);
                break;

            case "ChargeCreditCard":
                ChargeCreditCard.Run(apiLoginId, transactionKey);
                break;

            case "CaptureOnly":
                CaptureOnly.Run(apiLoginId, transactionKey);
                break;

            case "CapturePreviouslyAuthorizedAmount":
                Console.WriteLine("Enter An Transaction Amount");
                transactionAmount = Console.ReadLine();

                Console.WriteLine("Enter An Transaction ID");
                transactionId = Console.ReadLine();

                CapturePreviouslyAuthorizedAmount.Run(apiLoginId, transactionKey, Convert.ToDecimal(transactionAmount), transactionId);
                break;

            case "CaptureFundsAuthorizedThroughAnotherChannel":
                CaptureFundsAuthorizedThroughAnotherChannel.Run(apiLoginId, transactionKey);
                break;

            case "AuthorizeCreditCard":
                AuthorizeCreditCard.Run(apiLoginId, transactionKey);
                break;

            case "Refund":
                Console.WriteLine("Enter An Transaction Amount");
                transactionAmount = Console.ReadLine();

                Console.WriteLine("Enter An Transaction ID");
                transactionId = Console.ReadLine();

                RefundTransaction.Run(apiLoginId, transactionKey, Convert.ToDecimal(transactionAmount), transactionId);
                break;

            case "Void":
                Console.WriteLine("Enter An Transaction ID");
                transactionId = Console.ReadLine();

                VoidTransaction.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "DebitBankAccount":
                DebitBankAccount.Run(apiLoginId, transactionKey);
                break;

            case "CreditBankAccount":
                Console.WriteLine("Enter An Transaction ID");
                transactionId = Console.ReadLine();

                CreditBankAccount.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "ChargeCustomerProfile":
                ChargeCustomerProfile.Run(apiLoginId, transactionKey);
                break;

            case "ChargeTokenizedCard":
                ChargeTokenizedCreditCard.Run(apiLoginId, transactionKey);
                break;

            case "PayPalVoid":
                PayPalVoid.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "PayPalAuthorizeCapture":
                PayPalAuthorizeCapture.Run(apiLoginId, transactionKey);
                break;

            case "PayPalAuthorizeCaptureContinue":
                PayPalAuthorizeCaptureContinue.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "PayPalAuthorizeOnly":
                PayPalAuthorizeOnly.Run(apiLoginId, transactionKey);
                break;

            case "PayPalAuthorizeOnlyContinue":
                PayPalAuthorizeCaptureContinue.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "PayPalCredit":
                PayPalCredit.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "PayPalGetDetails":
                PayPalGetDetails.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "PayPalPriorAuthorizationCapture":
                PayPalPriorAuthorizationCapture.Run(apiLoginId, transactionKey, transactionId);
                break;

            case "CancelSubscription":
                CancelSubscription.Run(apiLoginId, transactionKey);
                break;

            case "CreateSubscription":
                CreateSubscription.Run(apiLoginId, transactionKey);
                break;

            case "GetSubscriptionList":
                GetListSubscriptions.Run(apiLoginId, transactionKey);
                break;

            case "GetSubscriptionStatus":
                GetSubscriptionStatus.Run(apiLoginId, transactionKey);
                break;

            case "UpdateSubscription":
                UpdateSubscription.Run(apiLoginId, transactionKey);
                break;

            case "CreateCustomerProfile":
                CreateCustomerProfile.Run(apiLoginId, transactionKey);
                break;

            case "CreateCustomerPaymentProfile":
                CreateCustomerPaymentProfile.Run(apiLoginId, transactionKey);
                break;

            case "GetUnsettledTransactionList":
                GetUnsettledTransactionList.Run(apiLoginId, transactionKey);
                break;

            case "GetBatchStatistics":
                GetBatchStatistics.Run(apiLoginId, transactionKey);
                break;

            case "GetSettledBatchList":
                GetSettledBatchList.Run(apiLoginId, transactionKey);
                break;

            default:
                ShowUsage();
                break;
            }
        }