From 8e51596d578f8de22b1fb207c54c13596662b14c Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Wed, 19 Jun 2024 17:49:54 +0300 Subject: [PATCH] added new payment method for Bancontact and added CardHolderName param to update card method --- MangoPay.SDK.Tests/ApiPayInsTest.cs | 31 ++++++++++++ MangoPay.SDK.Tests/BaseTest.cs | 26 ++++++++++ MangoPay.SDK/Core/APIs/ApiBase.cs | 1 + MangoPay.SDK/Core/APIs/ApiPayIns.cs | 17 +++++++ MangoPay.SDK/Core/Enumerations/MethodKey.cs | 1 + .../Core/Enumerations/PayInPaymentType.cs | 2 + .../Entities/GET/PayInBancontactWebDTO.cs | 28 +++++++++++ .../Entities/GET/PayInGiropayWebDTO.cs | 4 +- .../POST/PayInBancontactWebPostDTO.cs | 48 +++++++++++++++++++ MangoPay.SDK/Entities/PUT/CardPutDTO.cs | 5 ++ 10 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 MangoPay.SDK/Entities/GET/PayInBancontactWebDTO.cs create mode 100644 MangoPay.SDK/Entities/POST/PayInBancontactWebPostDTO.cs diff --git a/MangoPay.SDK.Tests/ApiPayInsTest.cs b/MangoPay.SDK.Tests/ApiPayInsTest.cs index 565fcc1a..60c30f6f 100644 --- a/MangoPay.SDK.Tests/ApiPayInsTest.cs +++ b/MangoPay.SDK.Tests/ApiPayInsTest.cs @@ -499,6 +499,37 @@ public async Task Test_PayIns_Create_GiropayWeb() } } + [Test] + public async Task Test_PayIns_Create_BancontactWeb() + { + try + { + var user = await GetJohn(); + var payIn = await GetNewPayInBancontactWeb(); + var fetched = await Api.PayIns.GetBancontactAsync(payIn.Id); + + Assert.IsTrue(payIn.Id.Length > 0); + Assert.AreEqual(PayInPaymentType.BCMC, payIn.PaymentType); + Assert.AreEqual(PayInExecutionType.WEB, payIn.ExecutionType); + Assert.IsTrue(payIn.DebitedFunds is Money); + Assert.IsTrue(payIn.CreditedFunds is Money); + Assert.IsTrue(payIn.Fees is Money); + Assert.AreEqual(user.Id, payIn.AuthorId); + Assert.AreEqual(TransactionStatus.CREATED, payIn.Status); + Assert.AreEqual(TransactionType.PAYIN, payIn.Type); + Assert.AreEqual(TransactionNature.REGULAR, payIn.Nature); + + Assert.AreEqual(payIn.Id, fetched.Id); + Assert.IsNotNull(fetched.Id); + Assert.AreEqual(CultureCode.NL, fetched.Culture); + Assert.AreEqual(false, fetched.Recurring); + } + catch (Exception ex) + { + Assert.Fail(ex.Message); + } + } + [Test] public async Task Test_PayIns_Create_Legacy_IdealWeb() { diff --git a/MangoPay.SDK.Tests/BaseTest.cs b/MangoPay.SDK.Tests/BaseTest.cs index b0239670..4dd17b99 100644 --- a/MangoPay.SDK.Tests/BaseTest.cs +++ b/MangoPay.SDK.Tests/BaseTest.cs @@ -436,6 +436,12 @@ protected async Task GetNewPayInGiropayWeb() return await this.Api.PayIns.CreateGiropayWebAsync(payIn); } + protected async Task GetNewPayInBancontactWeb() + { + PayInBancontactWebPostDTO payIn = await GetPayInBancontactWebPost(); + return await this.Api.PayIns.CreateBancontactWebAsync(payIn); + } + protected async Task CreateLegacyIdealPayInCardWeb(string walletId) { var user = await this.GetJohn(); @@ -780,6 +786,26 @@ protected async Task GetPayInGiropayWebPost() return payIn; } + + protected async Task GetPayInBancontactWebPost() + { + var wallet = await GetJohnsWalletWithMoney(); + var user = await GetJohn(); + + var payIn = new PayInBancontactWebPostDTO( + user.Id, + new Money { Amount = 100, Currency = CurrencyIso.EUR }, + new Money { Amount = 20, Currency = CurrencyIso.EUR }, + wallet.Id, + "http://www.my-site.com/returnURL?transactionId=wt_71a08458-b0cc-468d-98f7-1302591fc238", + null, + null, + false, + CultureCode.NL + ); + + return payIn; + } protected async Task GetJohnsPayOutBankWire() { diff --git a/MangoPay.SDK/Core/APIs/ApiBase.cs b/MangoPay.SDK/Core/APIs/ApiBase.cs index fe5303e0..a0c75cf4 100644 --- a/MangoPay.SDK/Core/APIs/ApiBase.cs +++ b/MangoPay.SDK/Core/APIs/ApiBase.cs @@ -73,6 +73,7 @@ public abstract class ApiBase { MethodKey.PayinsKlarnaWebCreate, new ApiEndPoint("/payins/payment-methods/klarna", RequestType.POST)}, { MethodKey.PayinsIdealWebCreate, new ApiEndPoint("/payins/payment-methods/ideal", RequestType.POST)}, { MethodKey.PayinsGiropayWebCreate, new ApiEndPoint("/payins/payment-methods/giropay", RequestType.POST)}, + { MethodKey.PayinsBancontactWebCreate, new ApiEndPoint("/payins/payment-methods/bancontact", RequestType.POST)}, { MethodKey.PayinsRecurringRegistration, new ApiEndPoint("/recurringpayinregistrations", RequestType.POST)}, { MethodKey.PayinsGetRecurringRegistration, new ApiEndPoint("/recurringpayinregistrations/{0}", RequestType.GET)}, diff --git a/MangoPay.SDK/Core/APIs/ApiPayIns.cs b/MangoPay.SDK/Core/APIs/ApiPayIns.cs index 6c1d66f4..110dfade 100644 --- a/MangoPay.SDK/Core/APIs/ApiPayIns.cs +++ b/MangoPay.SDK/Core/APIs/ApiPayIns.cs @@ -174,6 +174,15 @@ public async Task CreateGiropayWebAsync(PayInGiropayWebPostD return await this.CreateObjectAsync( MethodKey.PayinsGiropayWebCreate, payIn, idempotentKey); } + + /// Creates new payin bancontact web. + /// Idempotent key for this request. + /// Object instance to be created. + /// Object instance returned from API. + public async Task CreateBancontactWebAsync(PayInBancontactWebPostDTO payIn, string idempotentKey = null) + { + return await this.CreateObjectAsync(MethodKey.PayinsBancontactWebCreate, payIn, idempotentKey); + } /// Gets PayIn entity by its identifier. /// PayIn identifier. @@ -327,6 +336,14 @@ public async Task GetGiropayAsync(string payInId) { return await this.GetObjectAsync(MethodKey.PayinsGet, entitiesId: payInId); } + + /// Gets PayIn Bancontact entity by its identifier. + /// PayIn identifier. + /// PayIn object returned from API. + public async Task GetBancontactAsync(string payInId) + { + return await this.GetObjectAsync(MethodKey.PayinsGet, entitiesId: payInId); + } /// Creates refund for PayIn object. /// Idempotent key for this request. diff --git a/MangoPay.SDK/Core/Enumerations/MethodKey.cs b/MangoPay.SDK/Core/Enumerations/MethodKey.cs index fe8c7fd1..1e040f68 100644 --- a/MangoPay.SDK/Core/Enumerations/MethodKey.cs +++ b/MangoPay.SDK/Core/Enumerations/MethodKey.cs @@ -48,6 +48,7 @@ public enum MethodKey PayinsKlarnaWebCreate, PayinsIdealWebCreate, PayinsGiropayWebCreate, + PayinsBancontactWebCreate, GetPaymentMethodMetadata, PayoutsBankwireCreate, PayoutsBankwireGet, diff --git a/MangoPay.SDK/Core/Enumerations/PayInPaymentType.cs b/MangoPay.SDK/Core/Enumerations/PayInPaymentType.cs index dd2144b1..6da3b898 100644 --- a/MangoPay.SDK/Core/Enumerations/PayInPaymentType.cs +++ b/MangoPay.SDK/Core/Enumerations/PayInPaymentType.cs @@ -50,5 +50,7 @@ public enum PayInPaymentType IDEAL, /// Giropay payment type GIROPAY, + /// Bancontact payment type + BCMC } } diff --git a/MangoPay.SDK/Entities/GET/PayInBancontactWebDTO.cs b/MangoPay.SDK/Entities/GET/PayInBancontactWebDTO.cs new file mode 100644 index 00000000..4dffb522 --- /dev/null +++ b/MangoPay.SDK/Entities/GET/PayInBancontactWebDTO.cs @@ -0,0 +1,28 @@ +using MangoPay.SDK.Core.Enumerations; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace MangoPay.SDK.Entities.GET +{ + public class PayInBancontactWebDTO : PayInDTO + { + /// An optional value to be specified on the user's bank statement. + public string StatementDescriptor { get; set; } + + /// The URL to redirect to after the payment, whether the transaction was successful or not + public string ReturnURL { get; set; } + + /// The URL to which the user is redirected to complete the payment + public string RedirectURL { get; set; } + + /// + public string DeepLinkURL { get; set; } + + /// Culture (language). + [JsonConverter(typeof(StringEnumConverter))] + public CultureCode? Culture { get; set; } + + /// Whether the Bancontact pay-ins are being made to be re-used in a recurring payment flow + public bool? Recurring { get; set; } + } +} diff --git a/MangoPay.SDK/Entities/GET/PayInGiropayWebDTO.cs b/MangoPay.SDK/Entities/GET/PayInGiropayWebDTO.cs index 05a607e0..cb1daedc 100644 --- a/MangoPay.SDK/Entities/GET/PayInGiropayWebDTO.cs +++ b/MangoPay.SDK/Entities/GET/PayInGiropayWebDTO.cs @@ -5,10 +5,10 @@ public class PayInGiropayWebDTO: PayInDTO /// An optional value to be specified on the user's bank statement. public string StatementDescriptor { get; set; } - /// The URL to redirect to after the payment, whether the transaction was successful or not + /// The URL to redirect to after the payment, whether the transaction was successful or not public string ReturnURL { get; set; } - /// The URL to which the user is redirected to complete the payment + /// The URL to which the user is redirected to complete the payment public string RedirectURL { get; set; } } } \ No newline at end of file diff --git a/MangoPay.SDK/Entities/POST/PayInBancontactWebPostDTO.cs b/MangoPay.SDK/Entities/POST/PayInBancontactWebPostDTO.cs new file mode 100644 index 00000000..362e4877 --- /dev/null +++ b/MangoPay.SDK/Entities/POST/PayInBancontactWebPostDTO.cs @@ -0,0 +1,48 @@ +using MangoPay.SDK.Core.Enumerations; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace MangoPay.SDK.Entities.POST +{ + public class PayInBancontactWebPostDTO : EntityPostBase + { + public PayInBancontactWebPostDTO(string authorId, Money debitedFunds, Money fees, string creditedWalletId, + string returnUrl, string tag = null, string statementDescriptor = null, bool? recurring = null, CultureCode? culture = null) + { + AuthorId = authorId; + DebitedFunds = debitedFunds; + Fees = fees; + CreditedWalletId = creditedWalletId; + ReturnURL = returnUrl; + StatementDescriptor = statementDescriptor; + Tag = tag; + Recurring = recurring; + Culture = culture; + } + + /// Author identifier. + public string AuthorId { get; set; } + + /// Debited funds. + public Money DebitedFunds { get; set; } + + /// Fees. + public Money Fees { get; set; } + + /// Credited wallet identifier. + public string CreditedWalletId { get; set; } + + /// The URL to redirect to after the payment, whether the transaction was successful or not + public string ReturnURL { get; set; } + + /// An optional value to be specified on the user's bank statement. + public string StatementDescriptor { get; set; } + + /// Culture (language). + [JsonConverter(typeof(StringEnumConverter))] + public CultureCode? Culture { get; set; } + + /// Whether the Bancontact pay-ins are being made to be re-used in a recurring payment flow + public bool? Recurring { get; set; } + } +} \ No newline at end of file diff --git a/MangoPay.SDK/Entities/PUT/CardPutDTO.cs b/MangoPay.SDK/Entities/PUT/CardPutDTO.cs index 8fdc55ab..a9684d31 100644 --- a/MangoPay.SDK/Entities/PUT/CardPutDTO.cs +++ b/MangoPay.SDK/Entities/PUT/CardPutDTO.cs @@ -7,5 +7,10 @@ public class CardPutDTO : EntityPutBase { /// You only can switch from TRUE to FALSE to disable the card. Note that this action is irreversible. public bool? Active { get; set; } + + /// + /// The cardholder’s name shown on the payment card. + /// + public string CardHolderName { get; set; } } }