public static MundipaggResponse <string> Create(MundipaggCreditCardData creditCardInfo) { string creditCardEndpoint = $"{MUNDIPAGG_CORE_HOST_ADDRESS}/customers/{CustomerId}/cards"; NameValueCollection header = new NameValueCollection { { "Authorization", Authorization } }; WebResponse <string> result = RestClient.SendHttpWebRequest <string>(creditCardInfo, HttpVerb.Post, HttpContentType.Json, creditCardEndpoint, header, true); MundipaggResponse <string> response = new MundipaggResponse <string> { Success = result.IsSuccessStatusCode }; if (result.IsSuccessStatusCode) { MundipaggCreditCardData creditCardData = Serializer.NewtonsoftDeserialize <MundipaggCreditCardData>(result.ResponseData); response.ResponseData = creditCardData.Token; } else { dynamic deserializedResult = Serializer.DynamicDeserialize(result.ResponseData); response.Error = deserializedResult.message; } return(response); }
public static MundipaggResponse <bool> Delete(string creditCardKey) { string creditCardEndpoint = $"{MUNDIPAGG_CORE_HOST_ADDRESS}/customers/{CustomerId}/cards/{creditCardKey}"; NameValueCollection header = new NameValueCollection { { "Authorization", Authorization } }; WebResponse <string> result = RestClient.SendHttpWebRequest <string>(null, HttpVerb.Delete, HttpContentType.Json, creditCardEndpoint, header, true); MundipaggResponse <bool> response = new MundipaggResponse <bool> { Success = result.IsSuccessStatusCode }; if (result.IsSuccessStatusCode) { MundipaggCreditCardData creditCardData = Serializer.NewtonsoftDeserialize <MundipaggCreditCardData>(result.ResponseData); response.ResponseData = string.IsNullOrWhiteSpace(creditCardData.Status) == false && "delete".Equals(creditCardData.Status, StringComparison.OrdinalIgnoreCase) == true; } else { if (result.StatusCode == HttpStatusCode.NotFound) { return new MundipaggResponse <bool> { Success = true, ResponseData = true } } ; dynamic deserializedResult = Serializer.DynamicDeserialize(result.RawData); response.Error = deserializedResult.message; } return(response); }
public void CreateCreditCard_Test() { MundipaggCreditCardData creditCardData = new MundipaggCreditCardData { BillingAddress = null, Number = "5547157866507129", HolderName = "Unit Test FC Customer", ExpiryMonth = 1, ExpiryYear = 18, CardCvv = "422" }; MundipaggResponse <string> createCreditCardResponse = CreditCard.Create(creditCardData); Assert.IsTrue(createCreditCardResponse.Success); Assert.IsNotNull(createCreditCardResponse.ResponseData); Assert.IsNull(createCreditCardResponse.Error); _createdCreditCardKey = createCreditCardResponse.ResponseData; }