Skip to content

Commit

Permalink
Merge pull request #222 from Mangopay/feature/bancontact-payin
Browse files Browse the repository at this point in the history
Bancontact payin
  • Loading branch information
iulian03 authored Jun 20, 2024
2 parents f8d341f + 8e51596 commit 748bc9d
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 2 deletions.
31 changes: 31 additions & 0 deletions MangoPay.SDK.Tests/ApiPayInsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
26 changes: 26 additions & 0 deletions MangoPay.SDK.Tests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,12 @@ protected async Task<PayInGiropayWebDTO> GetNewPayInGiropayWeb()
return await this.Api.PayIns.CreateGiropayWebAsync(payIn);
}

protected async Task<PayInBancontactWebDTO> GetNewPayInBancontactWeb()
{
PayInBancontactWebPostDTO payIn = await GetPayInBancontactWebPost();
return await this.Api.PayIns.CreateBancontactWebAsync(payIn);
}

protected async Task<PayInCardWebDTO> CreateLegacyIdealPayInCardWeb(string walletId)
{
var user = await this.GetJohn();
Expand Down Expand Up @@ -780,6 +786,26 @@ protected async Task<PayInGiropayWebPostDTO> GetPayInGiropayWebPost()

return payIn;
}

protected async Task<PayInBancontactWebPostDTO> 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<PayOutBankWireDTO> GetJohnsPayOutBankWire()
{
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 @@ -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)},
Expand Down
17 changes: 17 additions & 0 deletions MangoPay.SDK/Core/APIs/ApiPayIns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ public async Task<PayInGiropayWebDTO> CreateGiropayWebAsync(PayInGiropayWebPostD
return await this.CreateObjectAsync<PayInGiropayWebDTO, PayInGiropayWebPostDTO>(
MethodKey.PayinsGiropayWebCreate, payIn, idempotentKey);
}

/// <summary>Creates new payin bancontact web.</summary>
/// <param name="idempotentKey">Idempotent key for this request.</param>
/// <param name="payIn">Object instance to be created.</param>
/// <returns>Object instance returned from API.</returns>
public async Task<PayInBancontactWebDTO> CreateBancontactWebAsync(PayInBancontactWebPostDTO payIn, string idempotentKey = null)
{
return await this.CreateObjectAsync<PayInBancontactWebDTO, PayInBancontactWebPostDTO>(MethodKey.PayinsBancontactWebCreate, payIn, idempotentKey);
}

/// <summary>Gets PayIn entity by its identifier.</summary>
/// <param name="payInId">PayIn identifier.</param>
Expand Down Expand Up @@ -327,6 +336,14 @@ public async Task<PayInGiropayWebDTO> GetGiropayAsync(string payInId)
{
return await this.GetObjectAsync<PayInGiropayWebDTO>(MethodKey.PayinsGet, entitiesId: payInId);
}

/// <summary>Gets PayIn Bancontact entity by its identifier.</summary>
/// <param name="payInId">PayIn identifier.</param>
/// <returns>PayIn object returned from API.</returns>
public async Task<PayInBancontactWebDTO> GetBancontactAsync(string payInId)
{
return await this.GetObjectAsync<PayInBancontactWebDTO>(MethodKey.PayinsGet, entitiesId: payInId);
}

/// <summary>Creates refund for PayIn object.</summary>
/// <param name="idempotentKey">Idempotent key for this request.</param>
Expand Down
1 change: 1 addition & 0 deletions MangoPay.SDK/Core/Enumerations/MethodKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public enum MethodKey
PayinsKlarnaWebCreate,
PayinsIdealWebCreate,
PayinsGiropayWebCreate,
PayinsBancontactWebCreate,
GetPaymentMethodMetadata,
PayoutsBankwireCreate,
PayoutsBankwireGet,
Expand Down
2 changes: 2 additions & 0 deletions MangoPay.SDK/Core/Enumerations/PayInPaymentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ public enum PayInPaymentType
IDEAL,
/// <summary> Giropay payment type </summary>
GIROPAY,
/// <summary> Bancontact payment type </summary>
BCMC
}
}
28 changes: 28 additions & 0 deletions MangoPay.SDK/Entities/GET/PayInBancontactWebDTO.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>An optional value to be specified on the user's bank statement.</summary>
public string StatementDescriptor { get; set; }

/// <summary> The URL to redirect to after the payment, whether the transaction was successful or not </summary>
public string ReturnURL { get; set; }

/// <summary> The URL to which the user is redirected to complete the payment </summary>
public string RedirectURL { get; set; }

/// <summary> </summary>
public string DeepLinkURL { get; set; }

/// <summary>Culture (language).</summary>
[JsonConverter(typeof(StringEnumConverter))]
public CultureCode? Culture { get; set; }

/// <summary>Whether the Bancontact pay-ins are being made to be re-used in a recurring payment flow</summary>
public bool? Recurring { get; set; }
}
}
4 changes: 2 additions & 2 deletions MangoPay.SDK/Entities/GET/PayInGiropayWebDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ public class PayInGiropayWebDTO: PayInDTO
/// <summary>An optional value to be specified on the user's bank statement.</summary>
public string StatementDescriptor { get; set; }

/// <summary> The URL to redirect to after the payment, whether the transaction was successful or not
/// <summary> The URL to redirect to after the payment, whether the transaction was successful or not </summary>
public string ReturnURL { get; set; }

/// <summary> The URL to which the user is redirected to complete the payment
/// <summary> The URL to which the user is redirected to complete the payment </summary>
public string RedirectURL { get; set; }
}
}
48 changes: 48 additions & 0 deletions MangoPay.SDK/Entities/POST/PayInBancontactWebPostDTO.cs
Original file line number Diff line number Diff line change
@@ -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;
}

/// <summary>Author identifier.</summary>
public string AuthorId { get; set; }

/// <summary>Debited funds.</summary>
public Money DebitedFunds { get; set; }

/// <summary>Fees.</summary>
public Money Fees { get; set; }

/// <summary>Credited wallet identifier.</summary>
public string CreditedWalletId { get; set; }

/// <summary> The URL to redirect to after the payment, whether the transaction was successful or not
public string ReturnURL { get; set; }

/// <summary>An optional value to be specified on the user's bank statement.</summary>
public string StatementDescriptor { get; set; }

/// <summary>Culture (language).</summary>
[JsonConverter(typeof(StringEnumConverter))]
public CultureCode? Culture { get; set; }

/// <summary>Whether the Bancontact pay-ins are being made to be re-used in a recurring payment flow</summary>
public bool? Recurring { get; set; }
}
}
5 changes: 5 additions & 0 deletions MangoPay.SDK/Entities/PUT/CardPutDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ public class CardPutDTO : EntityPutBase
{
/// <summary>You only can switch from TRUE to FALSE to disable the card. Note that this action is irreversible.</summary>
public bool? Active { get; set; }

/// <summary>
/// The cardholder’s name shown on the payment card.
/// </summary>
public string CardHolderName { get; set; }
}
}

0 comments on commit 748bc9d

Please sign in to comment.