public ProcessOrderResponseData ProcessOrder(ProcessOrderRequestData orderData)
        {
            CreateOrderDraftData(orderData);

            var receipt = paymentGatewayService.ProcessPaymentData(orderData);

            var response = CreateDefaultResponsedata(orderData.OrderNumber, orderData.UserId);

            if (receipt != null)
            {
                response.PaymentAccepted = true;
                response.ReceiptData     = receipt;

                UpdateOrderDraftData(receipt);
            }
            else
            {
                response.PaymentAccepted = false;
                response.ErrorMessage    =
                    $"Payment gateway {orderData.PaymentGateway} was unable to process payment for order number {orderData.OrderNumber}. " +
                    $"For detailed information please check error logs";
            }

            return(response);
        }
Example #2
0
        private void SetupProcessPaymentData(ProcessOrderRequestData orderData)
        {
            var receiptData = new ReceiptDataBuilder().Build();

            receiptData.AmountPaid = orderData.PayableAmount;
            SetupMock(orderData, receiptData);
        }
        private ReceiptData SendGppPayment(ProcessOrderRequestData orderData)
        {
            CreatePaymentDraftData(orderData.OrderNumber, orderData.PayableAmount);

            //Do some other payment gateway specific actions here

            var url    = ConfigurationManager.AppSettings["GppGatewayUrl"];
            var result = GetPaymentGatewayResponse <ProcessOrderRequestData, PaymentGatewayResponseData>(orderData, url);

            if (result != null)
            {
                var receiptData = new ReceiptData
                {
                    ReceiptNumber = result.ReceiptNumber,
                    PaymentNumber = result.PaymentNumber,
                    AmountPaid    = result.AmountPaid,
                    DateProcessed = result.DateProcessed
                };

                UpdatePaymentDraftData(receiptData);
                return(receiptData);
            }

            return(null);
        }
 public OrderRequestDataBuilder()
 {
     orderData = new ProcessOrderRequestData
     {
         OrderNumber         = "ON285345",
         UserId              = "ID3728AI",
         PayableAmount       = 100M,
         PaymentGateway      = PaymentGatewayEnum.GoldenPayPayment,
         OptionalDescription = "Order weight = 3.14"
     };
 }
Example #5
0
        public HttpResponseMessage ProcessOrder([FromBody] ProcessOrderRequestData orderData)
        {
            try
            {
                var service = serviceLocator.GetInstance <IProcessOrderOperation>();

                var model = service.ProcessOrder(orderData);

                return(Request.CreateResponse(HttpStatusCode.OK, model));
            }
            catch (Exception e)
            {
                Logger.Error($"Method: ProcessOrderOperation, Exception: {e.Message}");
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }
        }
        public ReceiptData ProcessPaymentData(ProcessOrderRequestData orderData)
        {
            switch (orderData.PaymentGateway)
            {
            case PaymentGatewayEnum.BankTransferPayment:
                return(SendBtpPayment(orderData));

            case PaymentGatewayEnum.GoldenPayPayment:
                return(SendGppPayment(orderData));

            case PaymentGatewayEnum.PayPalPayment:
                return(SendPppPayment(orderData));

            default:
                throw new InvalidOperationException($"Payment gateway type {orderData.PaymentGateway} is invalid!");
            }
        }
        private void CreateOrderDraftData(ProcessOrderRequestData orderData)
        {
            //Added gateway validation, basically only for tests, because this case is handled earlier by FluentValidation
            var isGatewayIdValid =
                new List <PaymentGatewayEnum>
            {
                PaymentGatewayEnum.GoldenPayPayment,
                PaymentGatewayEnum.BankTransferPayment,
                PaymentGatewayEnum.PayPalPayment
            }
            .Contains(orderData.PaymentGateway);

            if (!isGatewayIdValid)
            {
                throw new InvalidOperationException($"Payment gateway type {orderData.PaymentGateway} is invalid!");
            }

            //Do some business logic here before sending to payment gateway,
            //for example, save order data as a draft to database with payment status "Unpaid", etc
        }
Example #8
0
 private void SetupMock(ProcessOrderRequestData orderData, ReceiptData receiptData)
 {
     paymentGatewayServiceMock
     .Setup(s => s.ProcessPaymentData(orderData))
     .Returns(receiptData);
 }