Skip to content

Commit

Permalink
Merge pull request #72 from buckaroo-it/feature/PS2-557_AddSepaDirect…
Browse files Browse the repository at this point in the history
…Debit_ForCreateCombinedInvoice

.NET SDK: Add SEPA DirectDebit for CreateCombinedInvoice
  • Loading branch information
xhanan authored Nov 16, 2023
2 parents b2a6c53 + a97abd7 commit 9c84e50
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 3 deletions.
1 change: 1 addition & 0 deletions BuckarooSdk.Tests/BuckarooSdk.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@
<Compile Include="Services\PayPal\PayPalTests.cs" />
<Compile Include="Services\PayPerEmail\PayPerEmailTests.cs" />
<Compile Include="Services\PaysafeCard\PaysafeCardTests.cs" />
<Compile Include="Services\SepaDirectDebit\SepaDirectDebitTests.cs" />
<Compile Include="Services\SimpleSepaDirectDebit\SimpleSepaDirectDebitTests.cs" />
<Compile Include="Services\Sofort\SofortTests.cs" />
<Compile Include="Services\Subscriptions\SubscriptionRequestTests.cs" />
Expand Down
72 changes: 72 additions & 0 deletions BuckarooSdk.Tests/Services/SepaDirectDebit/SepaDirectDebitTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using BuckarooSdk.DataTypes.RequestBases;
using BuckarooSdk.Services.SepaDirectDebit;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Globalization;

namespace BuckarooSdk.Tests.Services.SepaDirectDebit
{
[TestClass]
public class SepaDirectDebitTests
{
private SdkClient _sdkClient;

[TestInitialize]
public void Setup()
{
this._sdkClient = new SdkClient(Constants.TestSettings.Logger);
}

[TestMethod]
public void PayTest()
{
var payment = this._sdkClient.CreateRequest()
.Authenticate(Constants.TestSettings.WebsiteKey, Constants.TestSettings.SecretKey, false, new CultureInfo("nl-NL"))
.TransactionRequest()
.SetBasicFields(new TransactionBase
{
Currency = "EUR",
AmountDebit = 0.02m,
Invoice = $"SDK_TEST_{DateTime.Now.Ticks}",
Description = "SEPADIRECTDEBIT_PAY_SDK_UNITTEST",
StartRecurrent = true,

})
.SepaDirectDebit()
.Pay(new SepaDirectDebitPayRequest()
{
MandateReference = "0012652668455265",
MandateDate = "16-12-2023",
CustomerBic = "INGBNL2A",
CustomerAccountName = "Tester Test",
CollectDate = "26-12-2023",
});

var paymentResponse = payment.Execute();
}

[TestMethod]
public void RefundTest()
{
var request = this._sdkClient.CreateRequest()
.Authenticate(Constants.TestSettings.WebsiteKey, Constants.TestSettings.SecretKey, false, new CultureInfo("nl-NL"))
.TransactionRequest()
.SetBasicFields(new TransactionBase
{
AmountCredit = 0.02m,
Currency = "EUR",
Invoice = "",
OriginalTransactionKey = "",
Description = "SEPADIRECTDEBIT_REFUND_SDK_UNITTEST",

})
.SepaDirectDebit()
.Refund(new SepaDirectDebitRefundRequest()
{
});

var response = request.Execute();
}
}
}

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using BuckarooSdk.DataTypes.RequestBases;
using BuckarooSdk.Services.SimpleSepaDirectDebit;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Globalization;
using BuckarooSdk.DataTypes.RequestBases;

namespace BuckarooSdk.Tests.Services.SimpleSepaDirectDebit
{
Expand Down
1 change: 1 addition & 0 deletions BuckarooSdk/Constants/Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum ServiceNames
PayPal,
AmericanExpress,
Transfer,
SepaDirectDebit,
SimpleSepaDirectDebit,
Payconiq,
Sofort,
Expand Down
12 changes: 12 additions & 0 deletions BuckarooSdk/Services/SepaDirectDebit/SepaDirectDebitPayRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace BuckarooSdk.Services.SepaDirectDebit
{
public class SepaDirectDebitPayRequest
{
public string CollectDate { get; set; }
public string CustomerAccountName { get; set; }
public string CustomerIBAN { get; set; }
public string CustomerBic { get; set; }
public string MandateReference { get; set; }
public string MandateDate { get; set; }
}
}
33 changes: 33 additions & 0 deletions BuckarooSdk/Services/SepaDirectDebit/SepaDirectDebitPayResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;

namespace BuckarooSdk.Services.SepaDirectDebit
{
public class SepaDirectDebitPayResponse : ActionResponse
{
public override Constants.Services.ServiceNames ServiceNames => Constants.Services.ServiceNames.SepaDirectDebit;
/// <summary>
/// The date the mandate has been registered
/// </summary>
public DateTime MandateDate { get; set; }
/// <summary>
/// The type of direct debit that will be processed.
/// </summary>
public string DirectDebitType { get; set; }
/// <summary>
/// The date the mandate has been registered.
/// </summary>
public DateTime CollectDate { get; set; }
/// <summary>
/// The mandate reference number.
/// </summary>
public string MandateReference { get; set; }
/// <summary>
/// The IBAN of the customers account.
/// </summary>
public string CustomerIban { get; set; }
/// <summary>
/// The BIC of the customers account.
/// </summary>
public string CustomerBic { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace BuckarooSdk.Services.SepaDirectDebit
{
public class SepaDirectDebitRefundRequest
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace BuckarooSdk.Services.SepaDirectDebit
{
public class SepaDirectDebitRefundResponse
{
}
}
46 changes: 46 additions & 0 deletions BuckarooSdk/Services/SepaDirectDebit/SepaDirectDebitTransaction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using BuckarooSdk.Transaction;

namespace BuckarooSdk.Services.SepaDirectDebit
{
public class SepaDirectDebitTransaction
{
/// <summary>
/// The configured transaction
/// </summary>
private ConfiguredTransaction ConfiguredTransaction { get; set; }

internal SepaDirectDebitTransaction(ConfiguredTransaction configuredTransaction)
{
this.ConfiguredTransaction = configuredTransaction;
}

/// <summary>
/// The pay function creates a configured transaction with an SepaDirectDebitPayRequest,
/// that is ready to be executed.
/// </summary>
/// <param name="request">An SepaDirectDebitPayRequest</param>
/// <returns></returns>
public ConfiguredServiceTransaction Pay(SepaDirectDebitPayRequest request)
{
var parameters = ServiceHelper.CreateServiceParameters(request);
var configuredServiceTransaction = new ConfiguredServiceTransaction(this.ConfiguredTransaction.BaseTransaction);
configuredServiceTransaction.BaseTransaction.AddService("SepaDirectDebit", parameters, "pay");

return configuredServiceTransaction;
}
/// <summary>
/// The refund function creates a configured transaction with an SepaDirectDebitRefundRequest,
/// that is ready to be executed.
/// </summary>
/// <param name="request">An SepaDirectDebitRefundRequest</param>
/// <returns></returns>
public ConfiguredServiceTransaction Refund(SepaDirectDebitRefundRequest request)
{
var parameters = ServiceHelper.CreateServiceParameters(request);
var configuredServiceTransaction = new ConfiguredServiceTransaction(this.ConfiguredTransaction.BaseTransaction);
configuredServiceTransaction.BaseTransaction.AddService("SepaDirectDebit", parameters, "refund");

return configuredServiceTransaction;
}
}
}
11 changes: 10 additions & 1 deletion BuckarooSdk/Transaction/ConfiguredTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using BuckarooSdk.Services.PayPal;
using BuckarooSdk.Services.PayPerEmail;
using BuckarooSdk.Services.PaysafeCard;
using BuckarooSdk.Services.SepaDirectDebit;
using BuckarooSdk.Services.SimpleSepaDirectDebit;
using BuckarooSdk.Services.Sofort;
using BuckarooSdk.Services.Transfer.TransactionRequest;
Expand Down Expand Up @@ -305,7 +306,15 @@ public SimpleSepaDirectDebitTransaction SimpleSepaDirectDebit()
return new SimpleSepaDirectDebitTransaction(this);
}

public PayconiqTransaction Payconiq()
/// <summary>
/// The instanciation of the specific SEPA Direct debit Service transaction.
/// </summary>
public SepaDirectDebitTransaction SepaDirectDebit()
{
return new SepaDirectDebitTransaction(this);
}

public PayconiqTransaction Payconiq()
{
return new PayconiqTransaction(this);
}
Expand Down

0 comments on commit 9c84e50

Please sign in to comment.