Пример #1
0
        public void Fail_When_Notification_Data_Is_Wrong()
        {
            // Arrange
            PayUrlController controller = new PayUrlController(null);

            PaymentNotificationData data = new PaymentNotificationData();

            // Act
            var result = controller.PaymentNotification(data);

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode, "Bad StatusCode");
            Assert.AreEqual("FAIL", result.Content.ReadAsStringAsync().Result, "Unexpected content");
        }
Пример #2
0
        public void PaymentNotification_Success()
        {
            // Arrange
            PayUrlController controller = new PayUrlController(null);

            PaymentNotificationData data = new PaymentNotificationData()
            {
                mnt_id             = "44",
                mnt_transaction_id = "ORDER-1025"
            };

            // Act
            var result = controller.PaymentNotification(data);

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode, "Bad StatusCode");
            Assert.AreEqual("SUCCESS", result.Content.ReadAsStringAsync().Result, "Unexpected content");
        }
Пример #3
0
        public HttpResponseMessage PaymentNotification(PaymentNotificationData data)
        {
            string content = "FAIL";

            if (data != null && !string.IsNullOrEmpty(data.mnt_id) && !string.IsNullOrEmpty(data.mnt_transaction_id))
            {
                content = "SUCCESS";

                if (_processor != null)
                {
                    _processor.ProcessNotification(data);
                }
            }

            var response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StringContent(content, Encoding.UTF8, "text/plain");

            return(response);
        }
Пример #4
0
        public void ProcessNotification(PaymentNotificationData data)
        {
            try
            {
                int orderId = 0;
                if (int.TryParse(data.mnt_transaction_id, out orderId))
                {
                    var orderApiClient = ByDesignAPIHelper.CreateOrderAPIClient();
                    var orderApiCred   = orderApiClient.CreateCredentials();
                    var response       = orderApiClient.GetOrderInfo_V2(orderApiCred, orderId);

                    if (response.Success > 0)
                    {
                        int custNum = 0;
                        if (int.TryParse(response.CustomerNumber, out custNum))
                        {
                            if (custNum >= 2000)
                            {
                                var orderDetailsResponse = orderApiClient.GetOrderDetailsInfo_V2(orderApiCred, orderId);
                                if (orderDetailsResponse.Success == 0)
                                {
                                    throw new InvalidOperationException(orderDetailsResponse.Message);
                                }

                                if (orderDetailsResponse.OrderDetailsResponse
                                    .Any(x => x.ProductID.Equals(Properties.Settings.Default.Freedom_VipKitItemId)))
                                {
                                    // change customer type
                                    var onlineApiClient = ByDesignAPIHelper.CreateOnlineAPIClient();
                                    var onlineApiCred   = onlineApiClient.CreateCredentials();

                                    var types         = onlineApiClient.GetCustomerTypes(onlineApiCred);
                                    var preferredType = types.FirstOrDefault(x => x.Abbreviation.Equals(CustomerType_Preferred));
                                    if (preferredType != null)
                                    {
                                        onlineApiClient.SetCustomerType(onlineApiCred, response.CustomerNumber, preferredType.ID);
                                    }
                                }
                            }
                        }

                        OrderStatus currentStatus = OrderStatus.Unknown;
                        if (Enum.TryParse(response.Status, out currentStatus))
                        {
                            if (currentStatus == OrderStatus.Entered)
                            {
                                orderApiClient.SetStatusPosted(orderApiCred, orderId, 0);

                                using (BiWellEntities context = new BiWellEntities())
                                {
                                    order_payment payment = new order_payment
                                    {
                                        order_id   = orderId,
                                        amount     = decimal.Parse(data.mnt_amount, CultureInfo.InvariantCulture),
                                        created_at = DateTime.UtcNow
                                    };

                                    context.order_payment.Add(payment);
                                    context.SaveChanges();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _looger.Log(ex.Message);
            }
        }
Пример #5
0
 public void ProcessNotification(PaymentNotificationData data)
 {
     // NOTHING TODO
 }