Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added get card validation endpoint #209

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion MangoPay.SDK.Tests/ApiCardPreAuthorizationsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using NUnit.Framework;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace MangoPay.SDK.Tests
Expand Down Expand Up @@ -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);
Expand Down
34 changes: 34 additions & 0 deletions MangoPay.SDK.Tests/ApiCardsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {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()
Expand Down
1 change: 0 additions & 1 deletion MangoPay.SDK.Tests/ApiPayInsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
var wallet = await this.GetJohnsWallet();
var user = await this.GetJohn();

var payInPost = new PayInPayPalPostDTO(user.Id, new Money { Amount = 1000, Currency = CurrencyIso.EUR }, new Money { Amount = 0, Currency = CurrencyIso.EUR }, wallet.Id, "http://test/test");

Check warning on line 68 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'

Check warning on line 68 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'

var payIn = await this.Api.PayIns.CreatePayPalAsync(payInPost);

Check warning on line 70 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Check warning on line 70 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Assert.IsTrue(payIn.Id.Length > 0);
Assert.IsTrue(payIn.PaymentType == PayInPaymentType.PAYPAL);
Expand Down Expand Up @@ -197,12 +197,12 @@
PostalCode = "11222",
Region = "Region"
};
var payInPost = new PayInPayPalPostDTO(user.Id, new Money { Amount = 1000, Currency = CurrencyIso.EUR }, new Money { Amount = 0, Currency = CurrencyIso.EUR }, wallet.Id, "http://test/test")

Check warning on line 200 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'

Check warning on line 200 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'
{
ShippingAddress = new ShippingAddress("recipient name", AddressForShippingAddress)
};

var payIn = await this.Api.PayIns.CreatePayPalAsync(payInPost);

Check warning on line 205 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Check warning on line 205 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Assert.IsNotNull(payIn.ShippingAddress);
Assert.AreEqual("recipient name", payIn.ShippingAddress.RecipientName);
Expand Down Expand Up @@ -786,7 +786,6 @@

Assert.IsNotNull(createPayIn.ReturnURL);
Assert.IsNotNull(createPayIn.RedirectURL);
Assert.IsNotNull(createPayIn.TemplateURL);


var getPayIn = await this.Api.PayIns.GetDirectDebitAsync(createPayIn.Id);
Expand Down Expand Up @@ -921,15 +920,15 @@
var wallet = await this.GetJohnsWallet();
var user = await this.GetJohn();

var payInPost = new PayInPayPalPostDTO(user.Id, new Money { Amount = 1000, Currency = CurrencyIso.EUR }, new Money { Amount = 0, Currency = CurrencyIso.EUR }, wallet.Id, "http://test/test");

Check warning on line 923 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'

Check warning on line 923 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'

payIn = await this.Api.PayIns.CreatePayPalAsync(payInPost);

Check warning on line 925 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Check warning on line 925 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Assert.IsTrue(payIn.Id.Length > 0);
Assert.IsTrue(payIn.PaymentType == PayInPaymentType.PAYPAL);
Assert.IsTrue(payIn.ExecutionType == PayInExecutionType.WEB);

var getPayIn = await this.Api.PayIns.GetPayPalAsync(payIn.Id);

Check warning on line 931 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.GetPayPalAsync(string)' is obsolete: 'GetPayPalAsync is deprecated, please use GetPayPalWebAsync instead.'

Check warning on line 931 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.GetPayPalAsync(string)' is obsolete: 'GetPayPalAsync is deprecated, please use GetPayPalWebAsync instead.'

Assert.IsNotNull(getPayIn);
Assert.IsTrue(getPayIn.Id == payIn.Id);
Expand Down Expand Up @@ -958,14 +957,14 @@
Region = "Region"
};

var payInPost = new PayInPayPalPostDTO(user.Id, new Money { Amount = 1000, Currency = CurrencyIso.EUR }, new Money { Amount = 0, Currency = CurrencyIso.EUR }, wallet.Id, "http://test/test")

Check warning on line 960 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'

Check warning on line 960 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'
{
ShippingAddress = new ShippingAddress("recipient name", addressForShippingAddress)
};

payIn = await this.Api.PayIns.CreatePayPalAsync(payInPost);

Check warning on line 965 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Check warning on line 965 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

var getPayIn = await this.Api.PayIns.GetPayPalAsync(payIn.Id);

Check warning on line 967 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.GetPayPalAsync(string)' is obsolete: 'GetPayPalAsync is deprecated, please use GetPayPalWebAsync instead.'

Check warning on line 967 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.GetPayPalAsync(string)' is obsolete: 'GetPayPalAsync is deprecated, please use GetPayPalWebAsync instead.'

Assert.IsNotNull(getPayIn.ShippingAddress);
Assert.AreEqual("recipient name", getPayIn.ShippingAddress.RecipientName);
Expand Down
2 changes: 2 additions & 0 deletions MangoPay.SDK.Tests/ApiUsersTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace MangoPay.SDK.Tests
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion MangoPay.SDK.Tests/ApiWalletsTest.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
33 changes: 2 additions & 31 deletions MangoPay.SDK.Tests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -998,36 +998,7 @@ protected async Task<string> 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);
}

/// <param name="cardRegistration">CardRegistration instance.</param>
/// <returns>Registration data.</returns>
protected async Task<string> 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");

Expand Down Expand Up @@ -1055,7 +1026,7 @@ protected async Task<CardRegistrationDTO> 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";

Expand Down
1 change: 1 addition & 0 deletions MangoPay.SDK/Core/APIs/ApiBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down
9 changes: 9 additions & 0 deletions MangoPay.SDK/Core/APIs/ApiCards.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,14 @@ public async Task<CardValidationDTO> ValidateAsync(string cardId, CardValidation
return await CreateObjectAsync<CardValidationDTO, CardValidationPostDTO>(MethodKey.CardValidation,
cardValidation, entitiesId: cardId);
}

/// <summary>Get card validation.</summary>
/// <param name="cardId">Card identifier.</param>
/// <param name="cardValidationId">Card validation id</param>
/// <returns>Card validation instance returned from API.</returns>
public async Task<CardValidationDTO> GetCardValidationAsync(string cardId, string cardValidationId)
{
return await this.GetObjectAsync<CardValidationDTO>(MethodKey.GetCardValidation, cardId, cardValidationId);
}
}
}
1 change: 1 addition & 0 deletions MangoPay.SDK/Core/Enumerations/MethodKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum MethodKey
CardRegistrationSave,
CardPreauthorizations,
CardValidation,
GetCardValidation,
CardTransactions,
CardByFingerprintGet,
EventsAll,
Expand Down
2 changes: 1 addition & 1 deletion MangoPay.SDK/Core/RestTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private async Task<U> DoRequestAsync<U, T>(string urlMethod, T entity = default,

if (this._responseCode == 200)
{
_log.Debug("Response object: " + responseObject.ToString());
_log.Debug("Response object: " + responseObject);
}

SetLastRequestInfo(restRequest, restResponse);
Expand Down
85 changes: 49 additions & 36 deletions MangoPay.SDK/Entities/GET/CardValidationDTO.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary> The unique identifier of the user at the source of the transaction. </summary>
public string AuthorId { get; set; }

/// <summary> The unique identifier of the user at the source of the transaction.
public string AuthorId;

/// <summary> 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;
/// <summary> The URL to which users are to be redirected to proceed to 3DS2 validation.
public string SecureModeRedirectURL;
/// <summary> Whether or not the SecureMode was used.
public Boolean SecureModeNeeded;
/// <summary> The IP address of the end user initiating the transaction, in IPV4 or IPV6 format
public string IpAddress;
/// <summary> Information about the browser used by the end user (author) to perform the payment.
public BrowserInfo BrowserInfo;
/// <summary> 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). </summary>
public string SecureModeReturnUrl { get; set; }

/// <summary> The URL to which users are to be redirected to proceed to 3DS2 validation. </summary>
public string SecureModeRedirectURL { get; set; }

/// <summary> Whether or not the SecureMode was used. </summary>
public Boolean SecureModeNeeded { get; set; }

/// <summary> The IP address of the end user initiating the transaction, in IPV4 or IPV6 format </summary>
public string IpAddress { get; set; }

/// <summary> Information about the browser used by the end user (author) to perform the payment. </summary>
public BrowserInfo BrowserInfo { get; set; }

/// <summary> Whether the card is valid or not. </summary>
public string Validity { get; set; }

/// <summary> 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;
/// <summary> The 3DS protocol version applied to the transaction.
public string Applied3DSVersion;
/// <summary>
public TransactionStatus Status;
/// indicates a transaction made to perform a strong customer authentication without debiting the card. </summary>
public TransactionType Type { get; set; }

/// <summary> The 3DS protocol version applied to the transaction. </summary>
public string Applied3DSVersion { get; set; }

/// <summary> The status of the transaction. </summary>
public TransactionStatus Status { get; set; }

/// <summary> The code indicating the result of the operation. This information is mostly
/// used to handle errors or for filtering purposes.
public string ResultCode;

/// <summary> The explanation of the result code.
public string ResultMessage;
/// used to handle errors or for filtering purposes. </summary>
public string ResultCode { get; set; }

/// <summary> The explanation of the result code. </summary>
public string ResultMessage { get; set; }

/// <summary> Allowed values: VISA, MASTERCARD, CB, MAESTRO
///
/// The card network to use, as chosen by the cardholder, in case of co-branded card products. </summary>
public string PreferredCardNetwork { get; set; }

/// <summary> The date and time at which successful authorization occurred. If authorization failed, the value is null. </summary>
[JsonConverter(typeof(UnixDateTimeConverter))]
public DateTime? AuthorizationDate { get; set; }

/// <summary> Information about the card used for the transaction. </summary>
public CardInfo CardInfo { get; set; }
}
}
Loading