//What will happen if the user clicks the confirmation button, the users entry information shall be sent and verified if correct //if the result is true then a message shall be displayed afirming that statement else another message shall display that something went wrong private async void OnConfirmationButtonClicked(object sender, EventArgs e) { var rest = new ManagerRESTService(new RESTService()); //account info to whom i am making the payment to var accountTo = new Payments.To { account_id = _userEntry.Text }; //bankid thats connected to the account specified on top to whom i am making the payment to var bankTo = new Payments.To { bank_id = _bankEntry.Text }; //currency chosen to make the payment var currencyTo = new Payments.Value { currency = _currencyEntry.Text }; //the amount that the user is willing to pay var amountTo = new Payments.Value { amount = _amountEntry.Text }; //a simple description of the transaction var descriptionTo = new Payments.Body { description = _descriptionEntry.Text }; //Sent to the RestService to verify the information received on this page to then be treated var result = await rest.MakePayment(accountTo, bankTo, currencyTo, amountTo, descriptionTo); Debug.WriteLine("result {0}", result); //if the result is false it will stay on the same page and show the message stated else it will change to the next page if (result) { try { await DisplayAlert("Confirmed", "Transaction Completed", "Ok"); } catch (Exception err) { Debug.WriteLine("Caught error: {0}.", err); } } else { await DisplayAlert("Alert", "Something happened :(", "OK"); } }
public async Task <bool> MakePayment(Payments.To accountTo, Payments.To bankTo, Payments.Value currencyTo, Payments.Value amountTo, Payments.Body descriptionTo) { return(await restService.MakePayment(accountTo, bankTo, currencyTo, amountTo, descriptionTo)); }
//The user should be autheticated to make a payment all these attributes are received from the payment page public async Task <bool> MakePayment(Payments.To accountTo, Payments.To bankTo, Payments.Value currencyTo, Payments.Value amountTo, Payments.Body descriptionTo) { //Url used to make the request to OpenBank var url = string.Format(Constants.PaymentUrl, AccountsPage.Bankid, AccountsPage.Accountid); //Token needed to verify the users authenticity var authToken = string.Format(" token=\"{0}\"", Token); //body that will be sent to the server containing the information the user added to the payment info body = "{ \"to\" :{\"bank_id\":\"" + bankTo.bank_id + "\",\"account_id\":\"" + accountTo.account_id + "\" }, \"value\":{ \"currency\": \"" + currencyTo.currency + "\", \"amount\":\"" + amountTo.amount + "\" }, \"description\":\"" + descriptionTo.description + "\"}"; otherbody = "{\"bank_id\":\"" + bankTo.bank_id + "\", \"account_id\":\"" + accountTo.account_id + "\",\"amount\":\"" + amountTo.amount + "\"}"; try { using (_client = new HttpClient()) { _client.MaxResponseContentBufferSize = 256000; //_client.DefaultRequestHeaders.Add("content-type", "application/json"); //Headers _client.DefaultRequestHeaders.Accept.Clear(); //_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("DirectLogin", authToken); //body // var content = new StringContent(body); //content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json"); /* var bodyList = new List<KeyValuePair<string, string>>(); * var toList = new List<KeyValuePair<string, string>>(); * var valueList = new List<KeyValuePair<string, string>>(); * * toList.Add(new KeyValuePair<string, string>("bank_id", bankTo.bank_id)); * toList.Add(new KeyValuePair<string, string>("account_id", accountTo.account_id)); * * valueList.Add(new KeyValuePair<string, string>("currency", currencyTo.currency)); * valueList.Add(new KeyValuePair<string, string>("amount", amountTo.amount)); * * bodyList.Add(new KeyValuePair<string, string>("to", toList.ToString())); * bodyList.Add(new KeyValuePair<string, string>("value", valueList.ToString())); * bodyList.Add(new KeyValuePair<string, string>("description", descriptionTo.description)); * * Debug.WriteLine("bodylist {0} ::: bodycount {1} \t::: Array{2} ::\t string {3}::",bodyList.Capacity, bodyList.Count, bodyList.ToArray(), bodyList.ToString()); * * HttpContent someContent = new FormUrlEncodedContent(bodyList);*/ var some = new StringContent(body, Encoding.UTF8, "application/json"); some.Headers.ContentType = new MediaTypeHeaderValue("application/json"); // HttpContent content = new StringContent(body, Encoding.UTF8, "application/json"); //content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); /* var formContent = new FormUrlEncodedContent(new[] * { * new KeyValuePair<string, string>("to", toList,toString), * new KeyValuePair<string, string>("value", valueList.ToString()), * new KeyValuePair<string, string>("description", descriptionTo.description) * }); * formContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");*/ Debug.WriteLine("content:: {0}", some.Headers.ContentDisposition); //Response message received from OpenBank HttpResponseMessage response = null; response = await _client.PostAsync(url, some); if (response != null && response.StatusCode != HttpStatusCode.Created) { Debug.WriteLine("BODY OF INFORMATION ADDED {0}", body); Debug.WriteLine("Error fetching data. Server returned status code: {0} ::: {1} :::: {2}", response.StatusCode, response.Content.Headers, response.Content.Headers.ContentDisposition); Debug.WriteLine("Requestmessage: {0}", response.RequestMessage); Debug.WriteLine("Requset uri {0}:", response.RequestMessage.RequestUri); Debug.WriteLine("Requst header: {0}:: Content::{1}", response.RequestMessage.Headers, response.RequestMessage.Content.Headers); return(false); } else { Debug.WriteLine(@" Payment successfull it works np."); return(true); } } } catch (Exception ex) { Debug.WriteLine(@" ERROR {0}", ex.Message); return(false); } }