Beispiel #1
0
        public async Task <BankServiceResponse> AuthorizationCodeAccessToken(BankServiceRequest request)
        {
            HttpRequestMessage requestMessage = new HttpRequestMessage();

            requestMessage.Method     = HttpMethod.Post;
            requestMessage.RequestUri = new Uri("https://ob.rbs.useinfinite.io/token");
            requestMessage.Content    = new FormUrlEncodedContent(
                new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("grant_type", "authorization_code"),
                new KeyValuePair <string, string>("client_id", "cwlrJ45Z6i9EWbvBVNozw4zJIzgLjUOIK613ceRg9I4="),
                new KeyValuePair <string, string>("client_secret", "nfP1TZaKVA5ByAoYFGI3IO_ZGoDyXVr7Xc8JyyugURo="),
                new KeyValuePair <string, string>("code", request.BodyParameters["code"])
            });
            requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", request.HeaderParameters["access_token"]);

            HttpResponseMessage responseMessage = await _httpClient.SendAsync(requestMessage);

            BankServiceResponse response = new BankServiceResponse()
            {
                StatusCode   = responseMessage.StatusCode,
                ReasonPhrase = responseMessage.ReasonPhrase,
                Content      = responseMessage.Content
            };

            return(response);
        }
Beispiel #2
0
        public async Task <BankServiceResponse> ClientCredentialsAccessToken(BankServiceRequest request)
        {
            HttpRequestMessage requestMessage = new HttpRequestMessage();

            requestMessage.Method     = HttpMethod.Post;
            requestMessage.RequestUri = new Uri("https://ob.rbs.useinfinite.io/token");
            requestMessage.Content    = new FormUrlEncodedContent(
                new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("grant_type", GrantType.ClientCredentials),
                new KeyValuePair <string, string>("client_id", _rbsClientInformation.ClientId),
                new KeyValuePair <string, string>("client_secret", _rbsClientInformation.ClientSecret),
                new KeyValuePair <string, string>("scope", _rbsClientInformation.Scope)
            });

            HttpResponseMessage responseMessage = await _httpClient.SendAsync(requestMessage);

            BankServiceResponse response = new BankServiceResponse()
            {
                StatusCode   = responseMessage.StatusCode,
                ReasonPhrase = responseMessage.ReasonPhrase,
                Content      = responseMessage.Content
            };

            return(response);
        }
Beispiel #3
0
        public async Task <BankServiceResponse> CreateAccountAccessConsents(BankServiceRequest request)
        {
            HttpRequestMessage requestMessage = new HttpRequestMessage();

            requestMessage.Method     = HttpMethod.Post;
            requestMessage.RequestUri = new Uri("https://ob.rbs.useinfinite.io/open-banking/v3.1/aisp/account-access-consents");
            requestMessage.Content    = new StringContent(
                @"{ 
                    ""Data"": {
                        ""Permissions"": [
                            ""ReadAccountsDetail"",
                            ""ReadBalances"",
                            ""ReadTransactionsCredits"",
                            ""ReadTransactionsDebits"",
                            ""ReadTransactionsDetail""
                        ]  
                    },
                    ""Risk"": {}
                }", Encoding.UTF8, "application/json");

            requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", request.HeaderParameters["access_token"]);

            HttpResponseMessage responseMessage = await _httpClient.SendAsync(requestMessage);

            BankServiceResponse response = new BankServiceResponse()
            {
                StatusCode   = responseMessage.StatusCode,
                ReasonPhrase = responseMessage.ReasonPhrase,
                Content      = responseMessage.Content
            };

            return(response);
        }
        public async Task <BankServiceResponse> AuthorizationCodeAccessToken(BankServiceRequest request)
        {
            HttpRequestMessage requestMessage = new HttpRequestMessage();

            requestMessage.Method     = HttpMethod.Post;
            requestMessage.RequestUri = new Uri("https://ob.coutts.useinfinite.io/token");
            requestMessage.Content    = new FormUrlEncodedContent(
                new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("grant_type", "authorization_code"),
                new KeyValuePair <string, string>("client_id", "TLWlvSLh_LrIifOg93FEavA6pejAosNAoS67IxxcsOA="),
                new KeyValuePair <string, string>("client_secret", "LDdy9kuYLAahzT3mBvAQz3NYfcg0tdrhkfOzDNnaS4A="),
                new KeyValuePair <string, string>("code", request.BodyParameters["code"])
            });
            requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", request.HeaderParameters["access_token"]);

            HttpResponseMessage responseMessage = await _httpClient.SendAsync(requestMessage);

            BankServiceResponse response = new BankServiceResponse()
            {
                StatusCode   = responseMessage.StatusCode,
                ReasonPhrase = responseMessage.ReasonPhrase,
                Content      = responseMessage.Content
            };

            return(response);
        }
Beispiel #5
0
        public async Task <BaseAccessToken> ClientCredentialsAccessToken()
        {
            BaseAccessToken result = null;

            BankServiceRequest  request  = new BankServiceRequest();
            BankServiceResponse response = await _bankService.ClientCredentialsAccessToken(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                JsonDocument responseJson = JsonDocument.Parse(await response.Content.ReadAsStringAsync());

                result = new BaseAccessToken()
                {
                    AccessToken = responseJson.RootElement.GetProperty("access_token").GetString(),
                    TokenType   = responseJson.RootElement.GetProperty("token_type").GetString(),
                    ExpiresIn   = responseJson.RootElement.GetProperty("expires_in").GetInt64().ToString(),
                    Scope       = responseJson.RootElement.GetProperty("scope").GetString()
                };
            }

            var cachedClient = await _cachingService.GetAsync <CacheClientModel>(_rackleClientCacheKey);

            if (!cachedClient.BankCodesClientTokens.ContainsKey(Provider.Natwest.Value))
            {
                cachedClient.BankCodesClientTokens.Add(Provider.Natwest.Value, result);
            }
            else
            {
                cachedClient.BankCodesClientTokens[Provider.Natwest.Value] = result;
            }
            await _cachingService.SetAsync <CacheClientModel>(_rackleClientCacheKey, cachedClient);

            return(result);
        }
Beispiel #6
0
        public async Task <BankServiceResponse> AuthorizationCodeAccessToken(BankServiceRequest request)
        {
            HttpRequestMessage requestMessage = new HttpRequestMessage();

            requestMessage.Method     = HttpMethod.Post;
            requestMessage.RequestUri = new Uri("https://ob.natwest.useinfinite.io/token");
            requestMessage.Content    = new FormUrlEncodedContent(
                new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("grant_type", "authorization_code"),
                new KeyValuePair <string, string>("client_id", "wDK0S-Tn7W483OvWEuiSjzBAe2gGafQNzE8URZa7xWY="),
                new KeyValuePair <string, string>("client_secret", "9QD6OPRmlWjU9k5g27wpaQ51LpL4coTdLCZ_u6wsv5o="),
                new KeyValuePair <string, string>("code", request.BodyParameters["code"])
            });
            requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", request.HeaderParameters["access_token"]);

            HttpResponseMessage responseMessage = await _httpClient.SendAsync(requestMessage);

            BankServiceResponse response = new BankServiceResponse()
            {
                StatusCode   = responseMessage.StatusCode,
                ReasonPhrase = responseMessage.ReasonPhrase,
                Content      = responseMessage.Content
            };

            return(response);
        }
        public async Task <BankServiceResponse> AuthorizationCodeAccessToken(BankServiceRequest request)
        {
            HttpRequestMessage requestMessage = new HttpRequestMessage();

            requestMessage.Method     = HttpMethod.Post;
            requestMessage.RequestUri = new Uri("https://ob.sandbox.natwestinternational.com/token");
            requestMessage.Content    = new FormUrlEncodedContent(
                new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("grant_type", "authorization_code"),
                new KeyValuePair <string, string>("client_id", "fGo_5jXCm6QSXc7qgZIZhhXEHU4ogEFjZY06ENnc1Io="),
                new KeyValuePair <string, string>("client_secret", "wMaOw3bsbVh_zS2q1QQLE3ju6BwBUObLMS1v9GtqQEE="),
                new KeyValuePair <string, string>("code", request.BodyParameters["code"])
            });
            requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", request.HeaderParameters["access_token"]);

            HttpResponseMessage responseMessage = await _httpClient.SendAsync(requestMessage);

            BankServiceResponse response = new BankServiceResponse()
            {
                StatusCode   = responseMessage.StatusCode,
                ReasonPhrase = responseMessage.ReasonPhrase,
                Content      = responseMessage.Content
            };

            return(response);
        }
        public async Task <BaseAccessToken> AuthorizationCodeAccessToken(string code, string userId)
        {
            BaseAccessToken result = null;

            BankServiceRequest request = new BankServiceRequest()
            {
                BodyParameters   = new Dictionary <string, string>(),
                HeaderParameters = new Dictionary <string, string>()
            };

            request.BodyParameters.Add("code", code);
            request.HeaderParameters.Add("access_token", "");

            BankServiceResponse response = await _bankService.AuthorizationCodeAccessToken(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                JsonDocument responseJson = JsonDocument.Parse(await response.Content.ReadAsStringAsync());

                result = new BaseAccessToken()
                {
                    AccessToken  = responseJson.RootElement.GetProperty("access_token").GetString(),
                    TokenType    = responseJson.RootElement.GetProperty("token_type").GetString(),
                    ExpiresIn    = responseJson.RootElement.GetProperty("expires_in").GetInt64().ToString(),
                    Scope        = responseJson.RootElement.GetProperty("scope").GetString(),
                    RefreshToken = responseJson.RootElement.GetProperty("refresh_token").GetString()
                };
            }

            //var cachedUser = await _cachingService.GetAsync<CacheUserModel>("UserId-" + _authContext.UserId);
            var cachedUser = await _cachingService.GetAsync <CacheUserModel>("UserId-" + userId);

            if (!cachedUser.BankCodesTokens.ContainsKey(Provider.RBS.Value))
            {
                cachedUser.BankCodesTokens.Add(Provider.RBS.Value, result);
            }
            else
            {
                cachedUser.BankCodesTokens[Provider.RBS.Value] = result;
            }

            //await _cachingService.SetAsync<CacheUserModel>("UserId-" + _authContext.UserId, cachedUser);

            var customerProfileRequestIntegrationEvent = new CustomerProfileRequestIntegrationEvent {
                ProviderIdTokens = new Dictionary <int, string>(), UserId = Guid.Parse(userId)
            };
            await _cachingService.SetAsync <CacheUserModel>("UserId-" + userId, cachedUser);

            foreach (var rec in cachedUser.BankCodesTokens)
            {
                customerProfileRequestIntegrationEvent.ProviderIdTokens.Add(rec.Key, rec.Value.AccessToken);
            }

            await _integrationEventService.PublishThroughEventBusAsync(customerProfileRequestIntegrationEvent);

            return(result);
        }
Beispiel #9
0
        public async Task <BankServiceResponse> GetDirectDebits(BankServiceRequest request)
        {
            HttpRequestMessage requestMessage = new HttpRequestMessage();

            requestMessage.Method                = HttpMethod.Get;
            requestMessage.RequestUri            = new Uri("https://ob.rbs.useinfinite.io/open-banking/v3.1/aisp/accounts/" + request.HeaderParameters["account_id"] + "/direct-debits");
            requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", request.HeaderParameters["access_token"]);

            HttpResponseMessage responseMessage = await _httpClient.SendAsync(requestMessage);

            BankServiceResponse response = new BankServiceResponse()
            {
                StatusCode   = responseMessage.StatusCode,
                ReasonPhrase = responseMessage.ReasonPhrase,
                Content      = responseMessage.Content
            };

            return(response);
        }
Beispiel #10
0
        public async Task <ConsentInfo> CreateAccountAccessConsents()
        {
            ConsentInfo result = null;

            BankServiceRequest request = new BankServiceRequest()
            {
                HeaderParameters = new Dictionary <string, string>()
            };

            var cachedClient = await _cachingService.GetAsync <CacheClientModel>(_rackleClientCacheKey);

            request.HeaderParameters.Add("access_token", cachedClient.BankCodesClientTokens[Provider.Coutts.Value].AccessToken);

            BankServiceResponse response = await _bankService.CreateAccountAccessConsents(request);

            if (response.StatusCode == System.Net.HttpStatusCode.Created)
            {
                JsonDocument responseJson = JsonDocument.Parse(await response.Content.ReadAsStringAsync());

                result = new ConsentInfo()
                {
                    ConsentId            = responseJson.RootElement.GetProperty("Data").GetProperty("ConsentId").GetString(),
                    CreationDateTime     = responseJson.RootElement.GetProperty("Data").GetProperty("CreationDateTime").GetString(),
                    Status               = responseJson.RootElement.GetProperty("Data").GetProperty("Status").GetString(),
                    StatusUpdateDateTime = responseJson.RootElement.GetProperty("Data").GetProperty("StatusUpdateDateTime").GetString(),
                };
            }

            var cachedUser = await _cachingService.GetAsync <CacheUserModel>("UserId-" + _authContext.UserId);

            if (!cachedUser.BankCodesConsentInfos.ContainsKey(Provider.Coutts.Value))
            {
                cachedUser.BankCodesConsentInfos.Add(Provider.Coutts.Value, result);
            }
            else
            {
                cachedUser.BankCodesConsentInfos[Provider.Coutts.Value] = result;
            }

            await _cachingService.SetAsync <CacheUserModel>("UserId-" + _authContext.UserId, cachedUser);

            return(result);
        }
Beispiel #11
0
        public async Task <BankServiceResponse> ProcessPaymentAsync(ProcessPaymentRequest request)
        {
            var response = new BankServiceResponse
            {
                PaymentId = Guid.NewGuid().ToString()
            };
            var value = _random.Next(0, 2);

            if (value == 0)
            {
                response.HttpStatusCode = HttpStatusCode.InternalServerError;
                response.HttpMessage    = "bank service return an error";
                response.PaymentStatus  = "expired";
            }
            else
            {
                response.HttpStatusCode          = HttpStatusCode.OK;
                response.HttpMessage             = "success";
                response.IsSuccessHttpStatusCode = true;
                response.PaymentStatus           = "success";
            }

            return(await Task.FromResult(response));
        }
Beispiel #12
0
        public async Task <CustomerProfile> GetCustomerProfile(string accessToken, Guid userId)
        {
            CustomerProfile    result  = new CustomerProfile();
            BankServiceRequest request = new BankServiceRequest()
            {
                HeaderParameters = new Dictionary <string, string>()
            };

            request.HeaderParameters.Add("access_token", accessToken);
            request.HeaderParameters.Add("account_id", "");

            BankServiceResponse accountResponse = await _bankService.GetAccounts(request);

            if (accountResponse.StatusCode == HttpStatusCode.OK)
            {
                JsonDocument accountResponseJson = JsonDocument.Parse(await accountResponse.Content.ReadAsStringAsync());
                result.Accounts = new List <Account>();

                foreach (JsonElement accountElement in accountResponseJson.RootElement.GetProperty("Data").GetProperty("Account").EnumerateArray())
                {
                    // Account bilgisi doldurma kısmı
                    Account account = new Account
                    {
                        ProviderAccountId      = accountElement.GetProperty("AccountId").GetString(),
                        AccountTypeId          = AccountType.GetInstanceByName(accountElement.GetProperty("AccountType").GetString()).Value,
                        CurrencyTypeId         = CurrencyType.GetInstanceByName(accountElement.GetProperty("Currency").GetString()).Value,
                        AccountIdentifications = new List <AccountIdentification>()
                    };
                    foreach (JsonElement accountDetailElement in accountElement.GetProperty("Account").EnumerateArray())
                    {
                        account.Name = accountDetailElement.GetProperty("Name").GetString();
                        if (accountDetailElement.GetProperty("SchemeName").GetString() == "UK.OBIE.IBAN")
                        {
                            account.AccountIdentifications.Add(new AccountIdentification()
                            {
                                AccountIdentificationTypeId = AccountIdentificationType.IBAN.Value,
                                Identification = accountDetailElement.GetProperty("Identification").GetString()
                            });
                        }
                        else if (accountDetailElement.GetProperty("SchemeName").GetString() == "UK.OBIE.SortCodeAccountNumber")
                        {
                            account.AccountIdentifications.Add(new AccountIdentification()
                            {
                                AccountIdentificationTypeId = AccountIdentificationType.SortCode.Value,
                                Identification = accountDetailElement.GetProperty("Identification").GetString()
                            });
                        }
                    }

                    // Account için Transaction bilgisi doldurma kısmı
                    request.HeaderParameters["account_id"] = account.ProviderAccountId;
                    BankServiceResponse transactionResponse = await _bankService.GetTransactions(request);

                    if (transactionResponse.StatusCode == HttpStatusCode.OK)
                    {
                        JsonDocument transactionResponseJson = JsonDocument.Parse(await transactionResponse.Content.ReadAsStringAsync());
                        account.Transactions = new List <Transaction>();
                        foreach (JsonElement transactionElement in transactionResponseJson.RootElement.GetProperty("Data").GetProperty("Transaction").EnumerateArray())
                        {
                            Transaction transaction = new Transaction
                            {
                                ProviderTransactionId = transactionElement.GetProperty("TransactionId").GetString(),
                                Description           = transactionElement.GetProperty("TransactionInformation").GetString(),
                                Date              = transactionElement.GetProperty("BookingDateTime").GetDateTime().ToString(),
                                Amount            = transactionElement.GetProperty("Amount").GetProperty("Amount").GetString(),
                                TransactionType   = TransactionType.GetInstanceByName(transactionElement.GetProperty("CreditDebitIndicator").GetString()).Value,
                                TransactionStatus = TransactionStatus.GetInstanceByName(transactionElement.GetProperty("Status").GetString()).Value
                            };

                            JsonElement merchant;
                            if (transactionElement.TryGetProperty("MerchantDetails", out merchant))
                            {
                                transaction.MerchantCategory = MerchantCategory.GetInstanceByCode(int.Parse(merchant.GetProperty("MerchantCategoryCode").GetString())).Value;
                            }

                            account.Transactions.Add(transaction);
                        }
                    }

                    // Account için Balance bilgisi doldurma kısmı
                    BankServiceResponse balanceResponse = await _bankService.GetBalances(request);

                    if (balanceResponse.StatusCode == HttpStatusCode.OK)
                    {
                        JsonDocument balanceResponseJson = JsonDocument.Parse(await balanceResponse.Content.ReadAsStringAsync());
                        account.Balances = new List <Balance>();
                        foreach (JsonElement balanceElement in balanceResponseJson.RootElement.GetProperty("Data").GetProperty("Balance").EnumerateArray())
                        {
                            Balance balance = new Balance
                            {
                                Amount       = balanceElement.GetProperty("Amount").GetProperty("Amount").GetString(),
                                BalanceType  = BalanceType.GetInstanceByName(balanceElement.GetProperty("Type").GetString()).Value,
                                CurrencyType = CurrencyType.GetInstanceByName(balanceElement.GetProperty("Amount").GetProperty("Currency").GetString()).Value
                            };
                            account.Balances.Add(balance);
                        }
                    }
                    result.Accounts.Add(account);
                }
            }
            result.ProviderId      = Provider.RBS.Value;
            result.UserId          = userId;
            result.UpdateTimestamp = DateTime.Now;
            return(result);
        }