-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create payment specific mandate response types (#364)
* Add payment specific response methods in mandate api * Create Json converter to parse mandate payment specific responses * Generate a new PaypalBillingAgreementId every time the CanCreatePayPalMandate integration test runs * Remove PayPal integration test, it is not supported on our account
- Loading branch information
1 parent
d7800b6
commit 14dcc12
Showing
11 changed files
with
141 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/Mollie.Api/Framework/Factories/MandateResponseFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using Mollie.Api.Models.Mandate.Response; | ||
using Mollie.Api.Models.Mandate.Response.PaymentSpecificParameters; | ||
using Mollie.Api.Models.Payment; | ||
|
||
namespace Mollie.Api.Framework.Factories; | ||
|
||
internal class MandateResponseFactory { | ||
public MandateResponse Create(string? paymentMethod) { | ||
if (string.IsNullOrEmpty(paymentMethod)) { | ||
return Activator.CreateInstance<MandateResponse>(); | ||
} | ||
|
||
switch (paymentMethod) { | ||
case PaymentMethod.PayPal: | ||
return Activator.CreateInstance<PayPalMandateResponse>(); | ||
case PaymentMethod.DirectDebit: | ||
return Activator.CreateInstance<SepaDirectDebitMandateResponse>(); | ||
case PaymentMethod.CreditCard: | ||
return Activator.CreateInstance<CreditCardMandateResponse>(); | ||
default: | ||
return Activator.CreateInstance<MandateResponse>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using Mollie.Api.Framework.Factories; | ||
using Mollie.Api.Models.Mandate.Response; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Mollie.Api.JsonConverters; | ||
|
||
internal class MandateResponseConverter : JsonCreationConverter<MandateResponse> { | ||
private readonly MandateResponseFactory _mandateResponseFactory; | ||
|
||
public MandateResponseConverter(MandateResponseFactory mandateResponseFactory) { | ||
_mandateResponseFactory = mandateResponseFactory; | ||
} | ||
|
||
protected override MandateResponse Create(Type objectType, JObject jObject) { | ||
string? paymentMethod = GetPaymentMethod(jObject); | ||
|
||
return _mandateResponseFactory.Create(paymentMethod); | ||
} | ||
|
||
private string? GetPaymentMethod(JObject jObject) { | ||
if (FieldExists("method", jObject)) { | ||
string paymentMethodValue = (string) jObject["method"]!; | ||
if (!string.IsNullOrEmpty(paymentMethodValue)) { | ||
return paymentMethodValue; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...s/Mandate/Request/PayPalMandateRequest.cs → ...pecificParameters/PayPalMandateRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../Request/SepaDirectDebitMandateRequest.cs → ...rameters/SepaDirectDebitMandateRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...Mollie.Api/Models/Mandate/Response/PaymentSpecificParameters/CreditCardMandateResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace Mollie.Api.Models.Mandate.Response.PaymentSpecificParameters; | ||
|
||
public record CreditCardMandateResponse : MandateResponse { | ||
public required CreditCardMandateResponseDetails Details { get; set; } | ||
} | ||
|
||
public record CreditCardMandateResponseDetails { | ||
/// <summary> | ||
/// The credit card holder's name. | ||
/// </summary> | ||
public string? CardHolder { get; set; } | ||
|
||
/// <summary> | ||
/// The last four digits of the credit card number. | ||
/// </summary> | ||
public string? CardNumber { get; set; } | ||
|
||
/// <summary> | ||
/// The credit card's label. Note that not all labels can be acquired through Mollie. | ||
/// </summary> | ||
public string? CardLabel { get; set; } | ||
|
||
/// <summary> | ||
/// Unique alphanumeric representation of credit card, usable for identifying returning customers. | ||
/// </summary> | ||
public string? CardFingerprint { get; set; } | ||
|
||
/// <summary> | ||
/// Expiry date of the credit card card in YYYY-MM-DD format. | ||
/// </summary> | ||
public string? CardExpiryDate { get; set; } | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Mollie.Api/Models/Mandate/Response/PaymentSpecificParameters/PayPalMandateResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Mollie.Api.Models.Mandate.Response.PaymentSpecificParameters; | ||
|
||
public record PayPalMandateResponse : MandateResponse { | ||
public required PayPalMandateResponseDetails Details { get; set; } | ||
} | ||
|
||
public record PayPalMandateResponseDetails { | ||
/// <summary> | ||
/// Only available if the payment has been completed – The consumer's name. | ||
/// </summary> | ||
public string? ConsumerName { get; set; } | ||
|
||
/// <summary> | ||
/// Only available if the payment has been completed – The consumer's IBAN. | ||
/// </summary> | ||
public string? ConsumerAccount { get; set; } | ||
} |
22 changes: 22 additions & 0 deletions
22
...e.Api/Models/Mandate/Response/PaymentSpecificParameters/SepaDirectDebitMandateResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace Mollie.Api.Models.Mandate.Response.PaymentSpecificParameters; | ||
|
||
public record SepaDirectDebitMandateResponse : MandateResponse { | ||
public required SepaDirectDebitMandateResponseDetails Details { get; set; } | ||
} | ||
|
||
public record SepaDirectDebitMandateResponseDetails { | ||
/// <summary> | ||
/// Only available if the payment has been completed – The consumer's name. | ||
/// </summary> | ||
public string? ConsumerName { get; set; } | ||
|
||
/// <summary> | ||
/// Only available if the payment has been completed – The consumer's IBAN. | ||
/// </summary> | ||
public string? ConsumerAccount { get; set; } | ||
|
||
/// <summary> | ||
/// Only available if the payment has been completed – The consumer's bank's BIC. | ||
/// </summary> | ||
public string? ConsumerBic { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters