Skip to content

Commit

Permalink
Create a constructor overload for payment method specific payment req…
Browse files Browse the repository at this point in the history
…uests (#384)
  • Loading branch information
Viincenttt committed Jul 10, 2024
1 parent e4af109 commit bf99b47
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
namespace Mollie.Api.Models.Payment.Request.PaymentSpecificParameters {
using System.Diagnostics.CodeAnalysis;

namespace Mollie.Api.Models.Payment.Request.PaymentSpecificParameters {
public record ApplePayPaymentRequest : PaymentRequest {
public ApplePayPaymentRequest()
{
Method = PaymentMethod.ApplePay;
}

[SetsRequiredMembers]
public ApplePayPaymentRequest(PaymentRequest paymentRequest) : base(paymentRequest) {
Method = PaymentMethod.ApplePay;
}

/// <summary>
/// Optional - The Apple Pay Payment Token object (encoded as JSON) that is part of the result of authorizing a payment
/// request. The token contains the payment information needed to authorize the payment.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
using System.Diagnostics.CodeAnalysis;

namespace Mollie.Api.Models.Payment.Request.PaymentSpecificParameters {
public record BankTransferPaymentRequest : PaymentRequest {
public BankTransferPaymentRequest() {
Method = PaymentMethod.BankTransfer;
}

[SetsRequiredMembers]
public BankTransferPaymentRequest(PaymentRequest paymentRequest) : base(paymentRequest) {
Method = PaymentMethod.BankTransfer;
}

/// <summary>
/// Optional - Consumer's e-mail address, to automatically send the bank transfer details to. Please note: the payment
/// instructions will be sent immediately when creating the payment. if you don't specify the locale parameter, the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
using System.Diagnostics.CodeAnalysis;

namespace Mollie.Api.Models.Payment.Request.PaymentSpecificParameters {
public record CreditCardPaymentRequest : PaymentRequest {
public CreditCardPaymentRequest() {
Method = PaymentMethod.CreditCard;
}

[SetsRequiredMembers]
public CreditCardPaymentRequest(PaymentRequest paymentRequest) : base(paymentRequest) {
Method = PaymentMethod.CreditCard;
}

/// <summary>
/// The card token you get from Mollie Components. The token contains the card information
/// (such as card holder, card number and expiry date) needed to complete the payment.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
namespace Mollie.Api.Models.Payment.Request.PaymentSpecificParameters {
using System.Diagnostics.CodeAnalysis;

namespace Mollie.Api.Models.Payment.Request.PaymentSpecificParameters {
public record GiftcardPaymentRequest : PaymentRequest {
public GiftcardPaymentRequest() {
Method = PaymentMethod.GiftCard;
}

[SetsRequiredMembers]
public GiftcardPaymentRequest(PaymentRequest paymentRequest) : base(paymentRequest) {
Method = PaymentMethod.GiftCard;
}

/// <summary>
/// The gift card brand to use for the payment. These issuers are not dynamically available through the Issuers API,
/// but can be retrieved by using the issuers include in the Methods API. If you need a brand not in the list, contact
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
using System.Diagnostics.CodeAnalysis;

namespace Mollie.Api.Models.Payment.Request.PaymentSpecificParameters {
public record IdealPaymentRequest : PaymentRequest {
public IdealPaymentRequest() {
Method = PaymentMethod.Ideal;
}

[SetsRequiredMembers]
public IdealPaymentRequest(PaymentRequest paymentRequest) : base(paymentRequest) {
Method = PaymentMethod.Ideal;
}

/// <summary>
/// (Optional) iDEAL issuer id. The id could for example be ideal_INGBNL2A. The returned paymentUrl will then directly
/// point to the ING web site.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
namespace Mollie.Api.Models.Payment.Request.PaymentSpecificParameters {
using System.Diagnostics.CodeAnalysis;

namespace Mollie.Api.Models.Payment.Request.PaymentSpecificParameters {
public record KbcPaymentRequest : PaymentRequest {
public KbcPaymentRequest() {
Method = PaymentMethod.Kbc;
}

[SetsRequiredMembers]
public KbcPaymentRequest(PaymentRequest paymentRequest) : base(paymentRequest) {
Method = PaymentMethod.Kbc;
}

/// <summary>
/// The issuer to use for the KBC/CBC payment. These issuers are not dynamically available through the Issuers API,
/// but can be retrieved by using the issuers include in the Methods API. See the Mollie.Api.Models.Payment.Request.KbcIssuer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
using System.Diagnostics.CodeAnalysis;

namespace Mollie.Api.Models.Payment.Request.PaymentSpecificParameters {
public record PayPalPaymentRequest : PaymentRequest {
public PayPalPaymentRequest() {
Method = PaymentMethod.PayPal;
}

[SetsRequiredMembers]
public PayPalPaymentRequest(PaymentRequest paymentRequest) : base(paymentRequest) {
Method = PaymentMethod.PayPal;
}

/// <summary>
/// The unique ID you have used for the PayPal fraud library. You should include this if you use PayPal
/// for an on-demand payment. The maximum character length is 32.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
namespace Mollie.Api.Models.Payment.Request.PaymentSpecificParameters {
using System.Diagnostics.CodeAnalysis;

namespace Mollie.Api.Models.Payment.Request.PaymentSpecificParameters {
public record PaySafeCardPaymentRequest : PaymentRequest {
public PaySafeCardPaymentRequest() {
Method = PaymentMethod.PaySafeCard;
}

[SetsRequiredMembers]
public PaySafeCardPaymentRequest(PaymentRequest paymentRequest) : base(paymentRequest) {
Method = PaymentMethod.PaySafeCard;
}

/// <summary>
/// Used for consumer identification. For example, you could use the consumer’s IP address.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;

namespace Mollie.Api.Models.Payment.Request.PaymentSpecificParameters
{
public record Przelewy24PaymentRequest : PaymentRequest
Expand All @@ -7,6 +9,11 @@ public Przelewy24PaymentRequest()
Method = PaymentMethod.Przelewy24;
}

[SetsRequiredMembers]
public Przelewy24PaymentRequest(PaymentRequest paymentRequest) : base(paymentRequest) {
Method = PaymentMethod.Przelewy24;
}

/// <summary>
/// Consumer�s email address, this is required for Przelewy24 payments.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
using System.Diagnostics.CodeAnalysis;

namespace Mollie.Api.Models.Payment.Request.PaymentSpecificParameters {
public record SepaDirectDebitRequest : PaymentRequest {
public SepaDirectDebitRequest() {
Method = PaymentMethod.DirectDebit;
}

[SetsRequiredMembers]
public SepaDirectDebitRequest(PaymentRequest paymentRequest) : base(paymentRequest) {
Method = PaymentMethod.DirectDebit;
}

/// <summary>
/// Optional - Beneficiary name of the account holder.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using FluentAssertions;
using Mollie.Api.Models;
using Mollie.Api.Models.Payment;
using Mollie.Api.Models.Payment.Request;
using Mollie.Api.Models.Payment.Request.PaymentSpecificParameters;
using Xunit;

namespace Mollie.Tests.Unit.Models.Payment.Request;

public class PaymentRequestTests {
[Theory]
[InlineData(PaymentMethod.CreditCard, typeof(CreditCardPaymentRequest))]
[InlineData(PaymentMethod.Ideal, typeof(IdealPaymentRequest))]
public void CreatePaymentRequest(string paymentMethod, Type expectedType) {
var amount = new Amount(Currency.EUR, 50m);
var description = "my-description";
var paymentRequest = new PaymentRequest() {
Amount = amount,
Description = description
};
switch (paymentMethod) {
case PaymentMethod.CreditCard:
paymentRequest = new CreditCardPaymentRequest(paymentRequest) {
CardToken = "card-token"
};
break;
case PaymentMethod.Ideal:
paymentRequest = new IdealPaymentRequest(paymentRequest) {
Issuer = "ideal_issuer"
};
break;
}

paymentRequest.Should().BeOfType(expectedType);
paymentRequest.Amount.Should().Be(amount);
paymentRequest.Description.Should().Be(description);
}
}

0 comments on commit bf99b47

Please sign in to comment.