public ActionResult BraintreePayment(FormCollection collection) { Cart cart = CartSession; if (cart.BillingAddress == 0) { return(CurrentUmbracoPage()); } //Save order to database via API var addressList = GetAddresses(AddressType.BillingAddress); var billingAddresss = addressList.FirstOrDefault(x => x.Id == cart.BillingAddress); var user = AuthenticateTicket.GetCurrentUser(); var gateway = new BraintreeGateway { Environment = Braintree.Environment.SANDBOX, MerchantId = "zwcjj4ss488mzsy7", PublicKey = "yddq2ybzjk5xy2z5", PrivateKey = "5917ab582f1790eb830644e90927e1fa" }; //save cart to database //payment method , payment status , payment type , cart //use the order in trans string nonceFromTheClient = collection["payment_method_nonce"]; var request = new TransactionRequest() { BillingAddress = new AddressRequest() { FirstName = user.FirstName, LastName = user.LastName, StreetAddress = billingAddresss.StreetAddress, ExtendedAddress = billingAddresss.ExtendedStreetAddress, Locality = billingAddresss.Town, PostalCode = billingAddresss.PostCode, CountryCodeAlpha2 = "GB" }, OrderId = "Todo", Amount = Convert.ToDecimal(cart.GrandTotal), Channel = "Emeal", PaymentMethodNonce = nonceFromTheClient, Options = new TransactionOptionsRequest { SubmitForSettlement = true, PayeeEmail = user.Email } }; Result <Transaction> result = gateway.Transaction.Sale(request); //check trans status if successful update order status to paid // remove cart from session //send confr email to customer and company. // forward customer a thank you page return(CurrentUmbracoPage()); }
private IRestResponse ApiGet(string method) { var user = AuthenticateTicket.GetCurrentUser(); var client = new RestClient(_apiUrl); var request = new RestRequest(method, Method.GET); if (user != null) { request.AddHeader("Authorization", user.AccessCode); } var response = client.ExecuteAsync(request).Result; return(response); }
public ActionResult Login(LoginViewModel loginViewModel) { loginViewModel.CompanyId = 1; //ToDo = get companyID from Umbraco Setup. var apiUrl = "https://localhost:44324"; var method = "/Access/login"; var apiClient = new ApiClient(apiUrl); var response = apiClient.Post <LoggedUser, LoginViewModel>(method, loginViewModel); if (response != null) { AuthenticateTicket.AddAuthenticationTicket(response); } return(null); }
private IRestResponse ApiPost <T>(string method, T obj) { var user = AuthenticateTicket.GetCurrentUser(); var client = new RestClient(_apiUrl); var request = new RestRequest(method, Method.POST); var data = JsonConvert.SerializeObject(obj); if (user != null) { request.AddHeader("Authorization", user.AccessCode); } request.AddParameter("application/json; charset=utf-8", data, ParameterType.RequestBody); request.RequestFormat = DataFormat.Json; var response = client.ExecuteAsync(request).Result; return(response); }
public ActionResult Test() { var user = AuthenticateTicket.GetCurrentUser(); return(Json(user, JsonRequestBehavior.AllowGet)); }
public static AuthTicket GetInfos(byte[] ticket) { MemoryStream stream = new MemoryStream(ticket); BinaryReader binaryReader = new BinaryReader(stream); HttpClient client = new HttpClient(); int initiallenght = binaryReader.ReadInt32(); if (initiallenght == 20) { AuthTicket authTicket = new AuthTicket(); authTicket.gctoken = binaryReader.ReadUInt64().ToString(); binaryReader.ReadBytes(8); double tokengeneratednotday = (double)binaryReader.ReadUInt32() * 1000; authTicket.tokenGenerated = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(tokengeneratednotday).ToLocalTime(); if (binaryReader.ReadUInt32() != 24) { return(new AuthTicket()); } binaryReader.ReadBytes(8); uint p = binaryReader.ReadUInt32(); binaryReader.ReadBytes(4); authTicket.clientConnectionTime = binaryReader.ReadUInt32(); authTicket.clientConnectionCount = (int)binaryReader.ReadUInt32(); long ownershipTicketOffset = binaryReader.BaseStream.Position; uint ownershipTicketLength = binaryReader.ReadUInt32(); binaryReader.ReadBytes(4); authTicket.version = (int)binaryReader.ReadUInt32(); authTicket.AccountID = (int)binaryReader.ReadUInt32(); binaryReader.ReadBytes(4); authTicket.appID = (int)binaryReader.ReadUInt32(); uint ownershipTicketExternalIP = binaryReader.ReadUInt32(); uint ownershipTicketInternalIP = binaryReader.ReadUInt32(); uint ownershipFlags = binaryReader.ReadUInt32(); double ownershipTicketGeneratednotday = (double)binaryReader.ReadUInt32() * 1000; authTicket.ownershipTicketGenerated = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ownershipTicketGeneratednotday).ToLocalTime(); double ownershipTicketExpiresnotday = (double)binaryReader.ReadUInt32() * 1000; authTicket.ownershipTicketExpires = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ownershipTicketExpiresnotday).ToLocalTime(); ushort licenseCount = binaryReader.ReadUInt16(); int[] license = new int[licenseCount]; for (int i = 0; i < licenseCount; i++) { license[i] = (int)binaryReader.ReadUInt32(); } authTicket.licences = license; ushort dlcCount = binaryReader.ReadUInt16(); AuthTicketDlc[] authTicketDlcs = new AuthTicketDlc[dlcCount]; for (int i = 0; i < dlcCount; i++) { authTicketDlcs[i].appID = (int)binaryReader.ReadUInt32(); licenseCount = binaryReader.ReadUInt16(); int[] dlclicenses = new int[licenseCount]; for (int h = 0; h < licenseCount; h++) { dlclicenses[h] = (int)binaryReader.ReadUInt32(); } authTicketDlcs[i].licenses = dlclicenses; } authTicket.dlcs = authTicketDlcs; binaryReader.ReadBytes(2); if (binaryReader.BaseStream.Position + 128 == binaryReader.BaseStream.Length) { authTicket.signature = binaryReader.ReadBytes((int)(binaryReader.BaseStream.Position + 128)); } String Ticketresponse = client.GetAsync("https://api.steampowered.com/ISteamUserAuth/AuthenticateUserTicket/v1/?key=BB147E811A8CEA5DFEFEA578D7105230&appid=700330&ticket=" + GetSteamAuthTicket(ticket)).Result.Content.ReadAsStringAsync().Result; AuthenticateTicket ticketjson = AuthenticateTicket.FromJson(Ticketresponse); bool hasValidSignature = true; if (ticketjson.Response.Params != null) { hasValidSignature = ticketjson.Response.Params.Result == "OK"; authTicket.SteamID64 = long.Parse(ticketjson.Response.Params.Ownersteamid); } else { return(new AuthTicket()); } String userInfoResponse = client.GetAsync("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=BB147E811A8CEA5DFEFEA578D7105230&steamids=" + ticketjson.Response.Params.Ownersteamid).Result.Content.ReadAsStringAsync().Result; UserInfo info = UserInfo.FromJson(userInfoResponse); authTicket.nickname = info.Response.Players[0].Personaname; authTicket.isExpired = authTicket.ownershipTicketExpires < DateTime.Now; authTicket.isValid = !authTicket.isExpired & hasValidSignature; return(authTicket); } return(new AuthTicket()); }