示例#1
0
        public static void AssignHeaders(HttpRequestHeaders headers, IdPayGatewayAccount account)
        {
            var api = account.IsTestAccount ? SandBoxApiKey : account.Api;

            headers.AddOrUpdate(ApiKey, api);

            if (account.IsTestAccount)
            {
                headers.AddOrUpdate(SandBoxKey, "1");
            }
            else if (headers.Contains(SandBoxKey))
            {
                headers.Remove(SandBoxKey);
            }
        }
示例#2
0
        public static async Task <PaymentRequestResult> CreateRequestResult(
            HttpResponseMessage responseMessage,
            IHttpContextAccessor httpContextAccessor,
            IdPayGatewayAccount account)
        {
            var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse();

            if (!responseMessage.IsSuccessStatusCode)
            {
                var errorModel = JsonConvert.DeserializeObject <IdPayErrorModel>(response);

                return(PaymentRequestResult.Failed(errorModel.ToString(), account.Name));
            }

            var result = JsonConvert.DeserializeObject <IdPayRequestResultModel>(response);

            return(PaymentRequestResult.Succeed(new GatewayRedirect(httpContextAccessor, result.Link), account.Name));
        }
示例#3
0
        public static async Task <PaymentRequestResult> CreateRequestResult(
            HttpResponseMessage responseMessage,
            HttpContext httpContext,
            IdPayGatewayAccount account)
        {
            var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse();

            if (!responseMessage.IsSuccessStatusCode)
            {
                var errorModel = JsonConvert.DeserializeObject <IdPayErrorModel>(response);

                return(PaymentRequestResult.Failed(errorModel.ToString(), account.Name));
            }

            var result = JsonConvert.DeserializeObject <IdPayRequestResultModel>(response);

            var transporterDescriptor = GatewayTransporterDescriptor.CreateRedirect(result.Link);

            var transporter = new DefaultGatewayTransporter(httpContext, transporterDescriptor);

            return(PaymentRequestResult.Succeed(transporter, account.Name));
        }