public void TestGetToken() { TokenMultiRequest req = new TokenMultiRequest() { PAN = this.testPan, ExpMonth = this.testExpMonth, ExpYear = this.testExpYear }; RPGClient client = new RPGClient(this.config.AppSettings.Settings["PrivateToken"].Value, this.uri); TokenMultiResponse response = client.TokenMulti.CreateAsync(req).Result; Assert.IsNotNull(response.Token); Assert.IsFalse(String.IsNullOrEmpty(response.Token.Token)); TokenMultiResponse tokenResponse = client.TokenMulti.GetAsync(response.Token.Token).Result; Assert.AreEqual((int)HttpStatusCode.OK, tokenResponse.StatusCode); Assert.IsNotNull(tokenResponse.Token); Assert.AreEqual(response.Token.Token, tokenResponse.Token.Token); tokenResponse = client.TokenMulti.GetAsync("InvalidToken").Result; Assert.AreEqual((int)HttpStatusCode.BadRequest, tokenResponse.StatusCode); tokenResponse = client.TokenMulti.GetAsync("tm_invalidtoken").Result; Assert.AreEqual((int)HttpStatusCode.NotFound, tokenResponse.StatusCode); client = new RPGClient("InvalidKey", this.uri); tokenResponse = client.TokenMulti.CreateAsync(req).Result; Assert.AreEqual((int)HttpStatusCode.Unauthorized, tokenResponse.StatusCode); }
public void TestDisable() { RPGClient client = new RPGClient("myKey", "http://www.borgun.is/", new HttpMessageHandlerMock()); TokenMultiResponse response = client.TokenMulti.DisableAsync("testtoken").Result; Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode); Assert.IsNull(response.Token); }
public async Task <TokenMultiResponse> DisableAsync(string token) { TokenMultiResponse tokenRes = new TokenMultiResponse(); HttpResponseMessage httpRes = await this.client.PutAsync("api/token/multi/" + token + "/disable", null); tokenRes.StatusCode = (int)httpRes.StatusCode; return(tokenRes); }
public void TestCreate() { TokenMultiRequest req = new TokenMultiRequest() { PAN = "4242424242424242", ExpMonth = "01", ExpYear = "20" }; RPGClient client = new RPGClient("myKey", "http://www.borgun.is/", new HttpMessageHandlerMock()); TokenMultiResponse response = client.TokenMulti.CreateAsync(req).Result; Assert.AreEqual((int)HttpStatusCode.Created, response.StatusCode); Assert.IsFalse(String.IsNullOrEmpty(response.Uri)); Assert.IsNotNull(response.Token); Assert.AreEqual("TestTokenMulti", response.Token.Token); }
public async Task <TokenMultiResponse> GetAsync(string token) { TokenMultiResponse tokenRes = new TokenMultiResponse(); HttpResponseMessage httpRes = await this.client.GetAsync("api/token/multi/" + token); tokenRes.StatusCode = (int)httpRes.StatusCode; if (httpRes.IsSuccessStatusCode) { TokenMultiInfo info = await httpRes.Content.ReadAsAsync <TokenMultiInfo>(); tokenRes.Token = info; } else { tokenRes.Message = await httpRes.Content.ReadAsStringAsync(); } return(tokenRes); }
public void TestCreateToken() { TokenMultiRequest req = new TokenMultiRequest() { PAN = this.testPan, ExpMonth = this.testExpMonth, ExpYear = this.testExpYear }; RPGClient client = new RPGClient(this.config.AppSettings.Settings["PrivateToken"].Value, this.uri); TokenMultiResponse response = client.TokenMulti.CreateAsync(req).Result; Assert.AreEqual((int)HttpStatusCode.Created, response.StatusCode); Assert.IsFalse(String.IsNullOrEmpty(response.Uri)); Assert.IsNotNull(response.Token); Assert.IsTrue(!String.IsNullOrEmpty(response.Token.Token)); Assert.AreEqual(this.uri + "api/token/multi/" + response.Token.Token, response.Uri); req.PAN = "1234567890123456"; response = client.TokenMulti.CreateAsync(req).Result; Assert.AreEqual((int)HttpStatusCode.BadRequest, response.StatusCode); Assert.IsNull(response.Token); Assert.IsFalse(String.IsNullOrEmpty(response.Message)); Assert.AreEqual("{\"Message\":\"PAN: InvalidFormat\"}", response.Message); req.PAN = null; req.ExpMonth = null; req.ExpYear = null; response = client.TokenMulti.CreateAsync(req).Result; Assert.AreEqual((int)HttpStatusCode.BadRequest, response.StatusCode); Assert.IsNull(response.Token); Assert.IsFalse(String.IsNullOrEmpty(response.Message)); Assert.AreEqual("{\"Message\":\"PAN: InvalidFormat; ExpMonth: Invalid expiration date\"}", response.Message); client = new RPGClient("InvalidKey", this.uri); response = client.TokenMulti.CreateAsync(req).Result; Assert.AreEqual((int)HttpStatusCode.Unauthorized, response.StatusCode); }
public async Task <TokenMultiResponse> CreateAsync(TokenMultiRequest req) { TokenMultiResponse tokenRes = new TokenMultiResponse(); HttpResponseMessage httpRes = await this.client.PostAsJsonAsync("api/token/multi", req); tokenRes.StatusCode = (int)httpRes.StatusCode; if (httpRes.IsSuccessStatusCode) { tokenRes.Token = await httpRes.Content.ReadAsAsync <TokenMultiInfo>(); if (httpRes.Headers.Location != null) { tokenRes.Uri = httpRes.Headers.Location.AbsoluteUri; } } else { tokenRes.Message = await httpRes.Content.ReadAsStringAsync(); } return(tokenRes); }
public async Task <TokenMultiResponse> CreateAsync(TokenMultiRequest req) { // See notes in PaymentAPI if (req.VerifyCard != null && req.VerifyCard.Currency != Currency.JPY.ToString()) { req.VerifyCard.CheckAmount *= 100; } var tokenRes = new TokenMultiResponse(); var resp = await DefaultPolly.Policy() .ExecuteAsync(() => _client.PostAsJsonAsync("token/multi", req)) .ConfigureAwait(false); await HandleErrorResponseAsync(resp).ConfigureAwait(false); tokenRes.Token = await resp.Content.ReadAsAsync <TokenMultiInfo>().ConfigureAwait(false); if (resp.Headers.Location != null) { tokenRes.Uri = resp.Headers.Location.AbsoluteUri; } return(tokenRes); }