Esempio n. 1
0
        private static async Task <(string, SCAData)> GetPaymentInitiationAuthorisationSCAStatus(string bicFi, string psuIPAddress, string psuUserAgent, string psuCorporateId, string paymentService, string paymentProduct, string paymentId, string authId)
        {
            Console.WriteLine("Get Payment Initiation Authorisation SCA Status");
            var apiClient = CreateGenericApiClient(bicFi, psuIPAddress, psuUserAgent, psuCorporateId);

            var response = await apiClient.GetAsync($"/psd2/paymentinitiation/v1/{paymentService}/{paymentProduct}/{paymentId}/authorisations/{authId}");

            var responseContent = await response.Content.ReadAsStringAsync();

            if (!response.IsSuccessStatusCode)
            {
                throw new HttpRequestException($"ERROR: statusCode={(int)response.StatusCode} Message={responseContent}");
            }
            Console.WriteLine($"resultStatusCode: {(int)response.StatusCode}");
            Console.WriteLine($"resultBody: {responseContent}");
            Console.WriteLine();

            var responseBody = JsonConvert.DeserializeObject <dynamic>(responseContent);
            var scaData      = new SCAData();

            if (responseBody.challengeData != null && responseBody.challengeData.data != null)
            {
                scaData.Token = responseBody.challengeData.data[0];
            }
            else if (responseBody.challengeData != null && responseBody.challengeData.image != null)
            {
                scaData.Image = responseBody.challengeData.image;
            }
            return(responseBody.scaStatus, scaData);
        }
Esempio n. 2
0
        private static async Task <(SCAMethod, string, SCAData)> UpdatePSUDataForPaymentInitiation(string bicFi, string psuIPAddress, string psuUserAgent, string psuId, string psuCorporateId, string paymentService, string paymentProduct, string paymentId, string authId, string authenticationMethodId)
        {
            Console.WriteLine("Update PSU Data For Payment Initiation");
            var apiClient = CreateGenericApiClient(bicFi, psuIPAddress, psuUserAgent, psuCorporateId);

            if (!string.IsNullOrEmpty(psuId))
            {
                apiClient.DefaultRequestHeaders.Add("PSU-ID", psuId);
            }

            var jsonBody = $"{{\"authenticationMethodId\": \"{authenticationMethodId}\"}}";

            var response = await apiClient.PutAsync($"/psd2/paymentinitiation/v1/{paymentService}/{paymentProduct}/{paymentId}/authorisations/{authId}", new StringContent(jsonBody, Encoding.UTF8, "application/json"));

            var responseContent = await response.Content.ReadAsStringAsync();

            if (!response.IsSuccessStatusCode)
            {
                throw new HttpRequestException($"ERROR: statusCode={(int)response.StatusCode} Message={responseContent}");
            }
            Console.WriteLine($"resultStatusCode: {(int)response.StatusCode}");
            Console.WriteLine($"resultBody: {responseContent}");
            Console.WriteLine();

            var responseBody = JsonConvert.DeserializeObject <dynamic>(responseContent);

            string scaStatus = responseBody.scaStatus;

            var scaData      = new SCAData();
            var headerValues = response.Headers.GetValues("aspsp-sca-approach");
            var scaApproach  = headerValues.FirstOrDefault();
            var method       = SCAMethod.UNDEFINED;

            if (scaApproach.Equals("REDIRECT"))
            {
                try
                {
                    scaData.RedirectUri = responseBody._links.scaOAuth.href;
                    method = SCAMethod.OAUTH_REDIRECT;
                }
                catch (RuntimeBinderException)
                {
                    try
                    {
                        scaData.RedirectUri = responseBody._links.scaRedirect.href;
                        method = SCAMethod.REDIRECT;
                    }
                    catch (RuntimeBinderException)
                    {
                    }
                }
            }
            else if (scaApproach.Equals("DECOUPLED"))
            {
                method = SCAMethod.DECOUPLED;
                try
                {
                    scaData.Token = responseBody.challengeData.data[0];
                }
                catch (RuntimeBinderException)
                {
                    try
                    {
                        scaData.Image = responseBody.challengeData.image;
                    }
                    catch (RuntimeBinderException)
                    {
                    }
                }
            }
            return(method, scaStatus, scaData);
        }