diff --git a/MangoPay.SDK.Tests/ApiCardPreAuthorizationsTest.cs b/MangoPay.SDK.Tests/ApiCardPreAuthorizationsTest.cs index 52a8a7f..48bfb1f 100644 --- a/MangoPay.SDK.Tests/ApiCardPreAuthorizationsTest.cs +++ b/MangoPay.SDK.Tests/ApiCardPreAuthorizationsTest.cs @@ -7,6 +7,7 @@ using NUnit.Framework; using System; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace MangoPay.SDK.Tests @@ -178,7 +179,8 @@ public async Task Test_CardPreAuthorizationTransactions_Get() }; await Api.PayIns.CreatePreauthorizedDirectAsync(payIn); - + + Thread.Sleep(2000); var preAuthTransactions = await this.Api.CardPreAuthorizations.GetTransactionsAsync(cardPreAuthorization.Id, new Pagination(1, 10)); Assert.NotNull(preAuthTransactions); diff --git a/MangoPay.SDK.Tests/ApiCardsTest.cs b/MangoPay.SDK.Tests/ApiCardsTest.cs index 8eb7656..28d8c4f 100644 --- a/MangoPay.SDK.Tests/ApiCardsTest.cs +++ b/MangoPay.SDK.Tests/ApiCardsTest.cs @@ -85,6 +85,40 @@ public async Task Test_Card_Validation() Assert.IsNotNull(validated); Assert.IsNotNull(validated.Id); } + + [Test] + public async Task Test_Get_Card_Validation() + { + var john = await GetJohn(); + var wallet = + new WalletPostDTO(new List {john.Id}, "WALLET IN EUR WITH MONEY", CurrencyIso.EUR); + var johnsWallet = await Api.Wallets.CreateAsync(wallet); + var cardRegistrationPost = + new CardRegistrationPostDTO(johnsWallet.Owners[0], CurrencyIso.EUR); + var cardRegistration = await Api.CardRegistrations.CreateAsync(cardRegistrationPost); + var cardRegistrationPut = new CardRegistrationPutDTO(); + cardRegistrationPut.RegistrationData = await GetPaylineCorrectRegistartionData(cardRegistration); + cardRegistration = await Api.CardRegistrations.UpdateAsync(cardRegistrationPut, cardRegistration.Id); + + var cardValidation = new CardValidationPostDTO( + john.Id, + "http://www.example.com/", + "2001:0620:0000:0000:0211:24FF:FE80:C12C", + getBrowserInfo(), + "Test card validate" + ); + + Assert.IsNotNull(cardRegistration, "Card is null!"); + + var validatedResponse = await Api.Cards.ValidateAsync(cardRegistration.CardId, cardValidation); + Assert.IsNotNull(validatedResponse); + Assert.IsNotNull(validatedResponse.Id); + var getCardValidation = + await Api.Cards.GetCardValidationAsync(cardRegistration.CardId, validatedResponse.Id); + Assert.IsNotNull(getCardValidation); + Assert.IsNotNull(getCardValidation.Id); + Assert.AreEqual(getCardValidation.Id, validatedResponse.Id); + } [Test] public async Task Test_Card_GetByFingerprint_Paginated() diff --git a/MangoPay.SDK.Tests/ApiPayInsTest.cs b/MangoPay.SDK.Tests/ApiPayInsTest.cs index 69f91dd..e9ef73d 100644 --- a/MangoPay.SDK.Tests/ApiPayInsTest.cs +++ b/MangoPay.SDK.Tests/ApiPayInsTest.cs @@ -786,7 +786,6 @@ public async Task Test_PayIns_DirectDebit_Create_Get() Assert.IsNotNull(createPayIn.ReturnURL); Assert.IsNotNull(createPayIn.RedirectURL); - Assert.IsNotNull(createPayIn.TemplateURL); var getPayIn = await this.Api.PayIns.GetDirectDebitAsync(createPayIn.Id); diff --git a/MangoPay.SDK.Tests/ApiUsersTest.cs b/MangoPay.SDK.Tests/ApiUsersTest.cs index a323d3e..1246051 100644 --- a/MangoPay.SDK.Tests/ApiUsersTest.cs +++ b/MangoPay.SDK.Tests/ApiUsersTest.cs @@ -11,6 +11,7 @@ using System.IO; using System.Reflection; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace MangoPay.SDK.Tests @@ -899,6 +900,7 @@ public async Task Test_Users_GetTransactionsForBankAccount() var sort = new Sort(); sort.AddField("CreationDate", SortDirection.desc); + Thread.Sleep(2000); var transactions = await Api.Users.GetTransactionsForBankAccountAsync(bankAccountId, pagination, filter, sort); Assert.IsTrue(transactions.Count > 0); diff --git a/MangoPay.SDK.Tests/ApiWalletsTest.cs b/MangoPay.SDK.Tests/ApiWalletsTest.cs index 8ef7503..9880418 100644 --- a/MangoPay.SDK.Tests/ApiWalletsTest.cs +++ b/MangoPay.SDK.Tests/ApiWalletsTest.cs @@ -1,4 +1,5 @@ -using MangoPay.SDK.Core; +using System.Threading; +using MangoPay.SDK.Core; using MangoPay.SDK.Core.Enumerations; using MangoPay.SDK.Entities; using MangoPay.SDK.Entities.GET; @@ -63,6 +64,8 @@ public async Task Test_Wallets_Transactions() { Type = TransactionType.PAYIN }; + + Thread.Sleep(2000); var transactions = await Api.Wallets.GetTransactionsAsync(wallet.Id, pagination, filter, null); Assert.IsTrue(transactions.Count == 1); diff --git a/MangoPay.SDK.Tests/BaseTest.cs b/MangoPay.SDK.Tests/BaseTest.cs index 0c721aa..c8989b3 100644 --- a/MangoPay.SDK.Tests/BaseTest.cs +++ b/MangoPay.SDK.Tests/BaseTest.cs @@ -998,36 +998,7 @@ protected async Task GetPaylineCorrectRegistartionData(CardRegistrationD }; request.AddParameter("data", cardRegistration.PreregistrationData); request.AddParameter("accessKeyRef", cardRegistration.AccessKey); - request.AddParameter("cardNumber", "4970105191923460"); - request.AddParameter("cardExpirationDate", "1224"); - request.AddParameter("cardCvx", "123"); - - // Payline requires TLS - ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; - - var response = await client.ExecuteAsync(request); - - var responseString = response.Content; - - if (response.StatusCode == HttpStatusCode.OK) - return responseString; - - throw new Exception(responseString); - } - - /// CardRegistration instance. - /// Registration data. - protected async Task GetPaylineCorrectRegistartionDataForDeposit(CardRegistrationDTO cardRegistration) - { - var client = new RestClient(cardRegistration.CardRegistrationURL); - - var request = new RestRequest - { - Method = Method.Post - }; - request.AddParameter("data", cardRegistration.PreregistrationData); - request.AddParameter("accessKeyRef", cardRegistration.AccessKey); - request.AddParameter("cardNumber", "4970105181818183"); + request.AddParameter("cardNumber", "4970107111111119"); request.AddParameter("cardExpirationDate", "1224"); request.AddParameter("cardCvx", "123"); @@ -1055,7 +1026,7 @@ protected async Task GetCardRegistrationForDeposit() var cardRegistration = await this.Api.CardRegistrations.CreateAsync(cardRegistrationPostDto); var cardRegistrationPut = new CardRegistrationPutDTO(); - var registrationData = await this.GetPaylineCorrectRegistartionDataForDeposit(cardRegistration); + var registrationData = await this.GetPaylineCorrectRegistartionData(cardRegistration); cardRegistrationPut.RegistrationData = registrationData; cardRegistrationPut.Tag = "DefaultTag - Updated"; diff --git a/MangoPay.SDK/Core/APIs/ApiBase.cs b/MangoPay.SDK/Core/APIs/ApiBase.cs index 8a74705..55b4a07 100644 --- a/MangoPay.SDK/Core/APIs/ApiBase.cs +++ b/MangoPay.SDK/Core/APIs/ApiBase.cs @@ -41,6 +41,7 @@ public abstract class ApiBase { MethodKey.CardPreauthorizations, new ApiEndPoint("/cards/{0}/preauthorizations", RequestType.GET)}, { MethodKey.CardTransactions, new ApiEndPoint("/cards/{0}/transactions", RequestType.GET)}, { MethodKey.CardValidation, new ApiEndPoint("/cards/{0}/validation", RequestType.POST) }, + { MethodKey.GetCardValidation, new ApiEndPoint("/cards/{0}/validation/{1}", RequestType.GET) }, { MethodKey.PayinsCardWebCreate, new ApiEndPoint("/payins/card/web", RequestType.POST)}, { MethodKey.PayinsCardWebGetCardData, new ApiEndPoint("/payins/card/web/{0}/extended/", RequestType.GET)}, diff --git a/MangoPay.SDK/Core/APIs/ApiCards.cs b/MangoPay.SDK/Core/APIs/ApiCards.cs index 36b6d6e..67f655a 100644 --- a/MangoPay.SDK/Core/APIs/ApiCards.cs +++ b/MangoPay.SDK/Core/APIs/ApiCards.cs @@ -65,5 +65,14 @@ public async Task ValidateAsync(string cardId, CardValidation return await CreateObjectAsync(MethodKey.CardValidation, cardValidation, entitiesId: cardId); } + + /// Get card validation. + /// Card identifier. + /// Card validation id + /// Card validation instance returned from API. + public async Task GetCardValidationAsync(string cardId, string cardValidationId) + { + return await this.GetObjectAsync(MethodKey.GetCardValidation, cardId, cardValidationId); + } } } diff --git a/MangoPay.SDK/Core/Enumerations/MethodKey.cs b/MangoPay.SDK/Core/Enumerations/MethodKey.cs index 03a8558..8073422 100644 --- a/MangoPay.SDK/Core/Enumerations/MethodKey.cs +++ b/MangoPay.SDK/Core/Enumerations/MethodKey.cs @@ -14,6 +14,7 @@ public enum MethodKey CardRegistrationSave, CardPreauthorizations, CardValidation, + GetCardValidation, CardTransactions, CardByFingerprintGet, EventsAll, diff --git a/MangoPay.SDK/Core/RestTool.cs b/MangoPay.SDK/Core/RestTool.cs index ca9da30..a1826b9 100644 --- a/MangoPay.SDK/Core/RestTool.cs +++ b/MangoPay.SDK/Core/RestTool.cs @@ -273,7 +273,7 @@ private async Task DoRequestAsync(string urlMethod, T entity = default, if (this._responseCode == 200) { - _log.Debug("Response object: " + responseObject.ToString()); + _log.Debug("Response object: " + responseObject); } SetLastRequestInfo(restRequest, restResponse); diff --git a/MangoPay.SDK/Entities/GET/CardValidationDTO.cs b/MangoPay.SDK/Entities/GET/CardValidationDTO.cs index 194b071..2c69f5d 100644 --- a/MangoPay.SDK/Entities/GET/CardValidationDTO.cs +++ b/MangoPay.SDK/Entities/GET/CardValidationDTO.cs @@ -1,48 +1,61 @@ using System; +using MangoPay.SDK.Core; using MangoPay.SDK.Core.Enumerations; +using Newtonsoft.Json; namespace MangoPay.SDK.Entities.GET { - public class CardValidationDTO: EntityBase + public class CardValidationDTO : EntityBase { + /// The unique identifier of the user at the source of the transaction. + public string AuthorId { get; set; } - /// The unique identifier of the user at the source of the transaction. - public string AuthorId; - /// The URL to which users are automatically returned after - /// 3DS2 if it is triggered (i.e., if the SecureModeNeeded parameter is set to true). - public string SecureModeReturnUrl; - - /// The URL to which users are to be redirected to proceed to 3DS2 validation. - public string SecureModeRedirectURL; - - /// Whether or not the SecureMode was used. - public Boolean SecureModeNeeded; - - /// The IP address of the end user initiating the transaction, in IPV4 or IPV6 format - public string IpAddress; - - /// Information about the browser used by the end user (author) to perform the payment. - public BrowserInfo BrowserInfo; - - /// Whether the card is valid or not. - public string Validity; - + /// 3DS2 if it is triggered (i.e., if the SecureModeNeeded parameter is set to true). + public string SecureModeReturnUrl { get; set; } + + /// The URL to which users are to be redirected to proceed to 3DS2 validation. + public string SecureModeRedirectURL { get; set; } + + /// Whether or not the SecureMode was used. + public Boolean SecureModeNeeded { get; set; } + + /// The IP address of the end user initiating the transaction, in IPV4 or IPV6 format + public string IpAddress { get; set; } + + /// Information about the browser used by the end user (author) to perform the payment. + public BrowserInfo BrowserInfo { get; set; } + + /// Whether the card is valid or not. + public string Validity { get; set; } + /// The type of transaction. In the specific case of the Card Validation object, this value - /// indicates a transaction made to perform a strong customer authentication without debiting the card. - public TransactionType Type; - - /// The 3DS protocol version applied to the transaction. - public string Applied3DSVersion; - - /// - public TransactionStatus Status; - + /// indicates a transaction made to perform a strong customer authentication without debiting the card. + public TransactionType Type { get; set; } + + /// The 3DS protocol version applied to the transaction. + public string Applied3DSVersion { get; set; } + + /// The status of the transaction. + public TransactionStatus Status { get; set; } + /// The code indicating the result of the operation. This information is mostly - /// used to handle errors or for filtering purposes. - public string ResultCode; - - /// The explanation of the result code. - public string ResultMessage; + /// used to handle errors or for filtering purposes. + public string ResultCode { get; set; } + + /// The explanation of the result code. + public string ResultMessage { get; set; } + + /// Allowed values: VISA, MASTERCARD, CB, MAESTRO + /// + /// The card network to use, as chosen by the cardholder, in case of co-branded card products. + public string PreferredCardNetwork { get; set; } + + /// The date and time at which successful authorization occurred. If authorization failed, the value is null. + [JsonConverter(typeof(UnixDateTimeConverter))] + public DateTime? AuthorizationDate { get; set; } + + /// Information about the card used for the transaction. + public CardInfo CardInfo { get; set; } } } \ No newline at end of file