Exemplo n.º 1
0
        public async Task <ActionResult <SubmitPaymentResponse> > CreatePaymentAsync([FromBody] SubmitPaymentRequest paymentRequest)
        {
            PaymentProcessorSubmitPaymentRequest paymentProcessorRequest = new PaymentProcessorSubmitPaymentRequest(paymentRequest.AccountNumber, paymentRequest.PaymentAmount);

            var request = new HttpRequestMessage(HttpMethod.Post, AmqpSidecarUri);

            request.Content = new ObjectContent <PaymentProcessorSubmitPaymentRequest>(paymentProcessorRequest, new JsonMediaTypeFormatter());
            var serviceResponse = await this._httpClient.SendAsync(request);

            if (!serviceResponse.IsSuccessStatusCode)
            {
                Console.WriteLine($"Error in request: {serviceResponse}");
                return(new SubmitPaymentResponse(String.Empty, "Error"));
            }

            // an asynchronous call is marked here as Pending because we don't know the result. downstream services will handle updating
            return(new SubmitPaymentResponse(paymentProcessorRequest.PaymentId, "Pending"));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <SubmitPaymentResponse> > CreatePaymentSync([FromBody] SubmitPaymentRequest paymentRequest)
        {
            PaymentProcessorSubmitPaymentRequest paymentProcessorRequest = new PaymentProcessorSubmitPaymentRequest(paymentRequest.AccountNumber, paymentRequest.PaymentAmount);

            var request = new HttpRequestMessage(HttpMethod.Post, PaymentProcessorUri);

            request.Content = new ObjectContent <PaymentProcessorSubmitPaymentRequest>(paymentProcessorRequest, new JsonMediaTypeFormatter());
            var serviceResponse = await this._httpClient.SendAsync(request);

            if (!serviceResponse.IsSuccessStatusCode)
            {
                Console.WriteLine($"Error in request: {serviceResponse}");
                return(new SubmitPaymentResponse(String.Empty, "Error"));
            }

            // because this call is synchronous, we can return the actual values from the finished process
            PaymentProcessorSubmitPaymentResponse paymentProcessorResponse = await serviceResponse.Content.ReadAsAsync <PaymentProcessorSubmitPaymentResponse>();

            return(new SubmitPaymentResponse(paymentProcessorResponse.PaymentId, paymentProcessorResponse.PaymentStatus));
        }