コード例 #1
0
        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);
        }
コード例 #2
0
        private void SetupProcessPaymentData(ProcessOrderRequestData orderData)
        {
            var receiptData = new ReceiptDataBuilder().Build();

            receiptData.AmountPaid = orderData.PayableAmount;
            SetupMock(orderData, receiptData);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public OrderRequestDataBuilder()
 {
     orderData = new ProcessOrderRequestData
     {
         OrderNumber         = "ON285345",
         UserId              = "ID3728AI",
         PayableAmount       = 100M,
         PaymentGateway      = PaymentGatewayEnum.GoldenPayPayment,
         OptionalDescription = "Order weight = 3.14"
     };
 }
コード例 #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));
            }
        }
コード例 #6
0
        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!");
            }
        }
コード例 #7
0
        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
        }
コード例 #8
0
 private void SetupMock(ProcessOrderRequestData orderData, ReceiptData receiptData)
 {
     paymentGatewayServiceMock
     .Setup(s => s.ProcessPaymentData(orderData))
     .Returns(receiptData);
 }