Exemplo n.º 1
0
        //Task<ApiResponse<PaymentResponse>> IComGateApi.CreatePayment(BaseComGatePayment payment, Payer payer, string ComGateAPIEndpointUrl)
        //{
        //	throw new NotImplementedException();
        //}

        public async Task <ApiResponse <PaymentResponse> > CreatePaymentAsync(BaseComGatePayment payment, Payer payer, string ComGateAPIEndpointUrl)
        {
            PaymentRequest paymentRequest = _requestBuilder
                                            .CreatePaymentRequest(payment, payer)
                                            .SetMerchant(this.Merchant)
                                            .SetEnviroment(this.IsTestEnviroment)
                                            .SetSecret(this.Secret);

            using (var httpClient = HttpClientFactory.CreateHttpClient(Core.Domain.Enums.ComGateHttpClient.HttpClient))
            {
                _paymentLogger.LogPayment(paymentRequest);
                var content = _serializer.Serialize <PaymentRequest>(paymentRequest);

                httpClient.BaseAddress = new Uri(ComGateAPIEndpointUrl);

                var response = await httpClient.PostAsync("create", content);

                if (response.IsSuccessStatusCode)
                {
                    var responseContent = await response.Content.ReadAsStringAsync();

                    return(_serializer.Deserialize <PaymentResponse>(responseContent));
                }
                else
                {
                    throw new Exception("Cannot create payment");
                }
            }
        }