public void EncodeClientAdd() { URLEncoder urlEncoder = new URLEncoder(); Client c = new Client(); c.Description = "Prueba"; c.Email = "*****@*****.**"; string expected = "email=javicantos22%40hotmail.es&description=Prueba"; string reply = urlEncoder.Encode<Client>(c); Assert.AreEqual(expected, reply); }
public void EncodeClientUpdate() { URLEncoder urlEncoder = new URLEncoder(); Client c = new Client(); c.Description = "Javier"; c.Email = "*****@*****.**"; c.Id = "client_bbe895116de80b6141fd"; string expected = "email=javicantos33%40hotmail.es&description=Javier&id=client_bbe895116de80b6141fd"; string reply = urlEncoder.Encode<Client>(c); Assert.AreEqual(expected, reply); }
/// <summary> /// Create an HttpClientRest-object /// </summary> /// <param name="apiUrl">API Endpoint URL</param> /// <param name="apiKey">Private key</param> public HttpClientRest(string apiUrl, string apiKey) { this._apiUrl = apiUrl; this._apiKey = apiKey; try { Uri uri = new Uri(apiUrl); } catch { throw new PaymillException("ApiURL is not a valid format Uri"); } this._urlEncoder = new URLEncoder(); }
public ActionResult Index() { ViewBag.Message = "Modifique esta plantilla para poner en marcha su aplicación ASP.NET MVC."; Paymill.ApiKey = "9a4129b37640ea5f62357922975842a1"; HttpClient client = Paymill.Client; /* // listado de clientes var task = client.GetAsync(Paymill.ApiUrl + "/clients").ContinueWith( (result) => { var response = result.Result; response.EnsureSuccessStatusCode(); var task2 = response.Content .ReadAsAsync<JObject>() .ContinueWith(readResult => { var jsonArray = readResult.Result; var lstOffers = new List<Client>(); lstOffers = Newtonsoft.Json.JsonConvert .DeserializeObject<List<Client>>(jsonArray["data"].ToString()); foreach (Client cliente in lstOffers) { Console.WriteLine("Name: {0}", cliente.Description); int i = 0; } }); });*/ /* // nuevo cliente Client c = new Client(); c.Description = "Prueba"; c.Email="*****@*****.**"; string json = Newtonsoft.Json.JsonConvert.SerializeObject(c).ToLower(); HttpContent content = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); task = client.PostAsync(Paymill.ApiUrl + "/clients", content).ContinueWith( (result) => { var response = result.Result; response.EnsureSuccessStatusCode(); var task2 = response.Content .ReadAsAsync<JObject>() .ContinueWith(readResult => { var jsonArray = readResult.Result; Client cteNuevo = Newtonsoft.Json.JsonConvert .DeserializeObject<Client>(jsonArray["data"].ToString()); Console.WriteLine("Name: {0}", cteNuevo.Id); Console.WriteLine("Name: {0}", cteNuevo.Email); }); });*/ // nueva oferta Offer off = new Offer(); off.Amount = 4200; off.Currency = "eur"; off.Interval = Offer.TypeInterval.WEEK; off.Name = "Oferta"; off.Trial_Period_Days = 3; string peticion = new URLEncoder().Encode<Offer>(off); var content = new StringContent(peticion); content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); var task = client.PostAsync(Paymill.ApiUrl + "/offers", content).ContinueWith( (result) => { var response = result.Result; response.EnsureSuccessStatusCode(); var task2 = response.Content .ReadAsAsync<JObject>() .ContinueWith(readResult => { var jsonArray = readResult.Result; Offer cteNuevo = Newtonsoft.Json.JsonConvert .DeserializeObject<Offer>(jsonArray["data"].ToString()); Console.WriteLine("Name: {0}", cteNuevo.Id); Console.WriteLine("Name: {0}", cteNuevo.Name); }); }); return View(); }
public void EncodeOfferAdd() { URLEncoder urlEncoder = new URLEncoder(); Offer offer = new Offer(); offer.Amount = 1500; offer.Currency = "eur"; offer.Interval = Offer.TypeInterval.MONTH; offer.Name = "Prueba API"; offer.Trial_Period_Days = 3; string expected = "amount=1500¤cy=eur&interval=month&name=Prueba+API"; string reply = urlEncoder.EncodeOfferAdd(offer); Assert.AreEqual(expected, reply); }
public void EncodeTransaction() { URLEncoder urlEncoder = new URLEncoder(); Transaction transaction = new Transaction(); transaction.Token = "098f6bcd4621d373cade4e832627b4f6"; transaction.Amount = 3500; transaction.Currency = "EUR"; transaction.Description = "Prueba"; string expected = "amount=3500¤cy=EUR&token=098f6bcd4621d373cade4e832627b4f6&description=Prueba"; string reply = urlEncoder.EncodeTransaction(transaction); Assert.AreEqual(expected, reply); }
public void EncodeSubscriptionUpdate() { URLEncoder urlEncoder = new URLEncoder(); Subscription subscription = new Subscription(); subscription.Cancel_At_Period_End = true; subscription.Id = "sub_569df922b4506cd73030"; string expected = "cancel_at_period_end=True"; string reply = urlEncoder.EncodeSubscriptionUpdate(subscription); Assert.AreEqual(expected, reply); }
public void EncodeSubscriptionAdd() { URLEncoder urlEncoder = new URLEncoder(); Subscription subscription = new Subscription(); subscription.Client = new Client() { Id = "client_bbe895116de80b6141fd" }; subscription.Offer = new Offer() { Id = "offer_32008ddd39954e71ed48" }; subscription.Payment = new Payment() { Id = "pay_81ec02206e9b9c587513" }; string expected = "client=client_bbe895116de80b6141fd&offer=offer_32008ddd39954e71ed48&payment=pay_81ec02206e9b9c587513"; string reply = urlEncoder.EncodeSubscriptionAdd(subscription); Assert.AreEqual(expected, reply); }
public void EncodeRefund() { URLEncoder urlEncoder = new URLEncoder(); Refund refund = new Refund(); refund.Amount = 500; refund.Description = "Prueba"; refund.Transaction = new Transaction() { Id = "tran_a7c93a1e5b431b52c0f0" }; string expected = "amount=500&description=Prueba"; string reply = urlEncoder.EncodeRefund(refund); Assert.AreEqual(expected, reply); }
public void EncodePreauthorization() { URLEncoder urlEncoder = new URLEncoder(); Preauthorization preauthorization = new Preauthorization(); preauthorization.Amount = 3500; preauthorization.Currency = "EUR"; preauthorization.Payment = new Payment() { Id = "pay_4c159fe95d3be503778a" }; string expected = "amount=3500¤cy=EUR&payment=pay_4c159fe95d3be503778a"; string reply = urlEncoder.EncodePreauthorization(preauthorization); Assert.AreEqual(expected, reply); }
public void EncodeOfferUpdate() { URLEncoder urlEncoder = new URLEncoder(); Offer offer = new Offer(); offer.Name = "Oferta 48"; offer.Id = "offer_6eea405f83d4d3098604"; string expected = "amount=0&interval=week&name=Oferta+48"; string reply = urlEncoder.EncodeOfferAdd(offer); Assert.AreEqual(expected, reply); }