Skip to content

Commit

Permalink
Add BNP Installments option to payment (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
illunix authored Dec 16, 2023
2 parents 3b486f3 + 9d3b42c commit cd65cb5
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 25 deletions.
34 changes: 34 additions & 0 deletions src/Axepta.SDK/Entities/Request/Address.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Axepta.SDK.Entities.Request;

/// <summary>
/// Represents a postal address with street, postal code, and city details.
/// </summary>
public sealed record Address
{
/// <summary>
/// Gets the street name of the address.
/// </summary>
/// <value>
/// The street name as a string.
/// </value>
[JsonPropertyName("street")]
public required string Street { get; init; }

/// <summary>
/// Gets the postal code of the address.
/// </summary>
/// <value>
/// The postal code as a string.
/// </value>
[JsonPropertyName("postalCode")]
public required string PostalCode { get; init; }

/// <summary>
/// Gets the city name of the address.
/// </summary>
/// <value>
/// The city name as a string.
/// </value>
[JsonPropertyName("city")]
public required string City { get; init; }
}
34 changes: 34 additions & 0 deletions src/Axepta.SDK/Entities/Request/BnpInstalments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace Axepta.SDK.Entities.Request;

/// <summary>
/// Represents the installments information for BNP, including address, credit types, and products.
/// </summary>
public sealed record BnpInstalments
{
/// <summary>
/// Gets the address associated with the BNP installment.
/// </summary>
/// <value>
/// The address as a string.
/// </value>
[JsonPropertyName("address")]
public required string Address { get; init; }

/// <summary>
/// Gets the list of credit types associated with the BNP installment.
/// </summary>
/// <value>
/// A read-only list of integers representing credit types.
/// </value>
[JsonPropertyName("creditTypes")]
public required IReadOnlyList<int> CreditTypes { get; init; }

/// <summary>
/// Gets the list of products associated with the BNP installment.
/// </summary>
/// <value>
/// A read-only list of <see cref="Product"/> objects.
/// </value>
[JsonPropertyName("products")]
public required IReadOnlyList<Product> Products { get; init; }
}
55 changes: 30 additions & 25 deletions src/Axepta.SDK/Entities/Request/Payment.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
namespace Axepta.SDK.Entities.Request;

/// <summary>
/// Represents payment information, including details such as payment type, service ID, amount, and customer information.
/// Represents a payment transaction, encapsulating details such as payment type, service ID,
/// amount, currency, and customer information. This record is designed to handle various aspects
/// of a payment process including the transaction details, payment methods, and redirection URLs
/// for successful or failed payments.
/// </summary>
public sealed record Payment
{
private int _amount;

/// <summary>
/// Gets or initializes the type of payment.
/// Gets or sets the type of payment. This property specifies the category or method of the payment.
/// </summary>
[JsonPropertyName("type")]
public required PaymentType Type { get; init; }

/// <summary>
/// Gets or initializes the service ID associated with the payment.
/// Gets or sets the service ID associated with the payment. This is a unique identifier for the service involved in the payment.
/// </summary>
[JsonPropertyName("serviceId")]
public required string ServiceId { get; init; }

/// <summary>
/// Gets or initializes the amount of the payment.
/// Gets or sets the payment amount. The setter converts the input amount from a major currency unit (e.g., dollars) to a minor unit (e.g., cents).
/// </summary>
[JsonPropertyName("amount")]
public required int Amount
Expand All @@ -30,108 +33,110 @@ public required int Amount
}

/// <summary>
/// Gets or initializes the currency code for the payment amount.
/// Gets or sets the currency code for the payment, following the ISO 4217 standard.
/// </summary>
[StringLength(3)]
[JsonPropertyName("currency")]
public required string Currency { get; init; }

/// <summary>
/// Gets or initializes the unique identifier for the payment order.
/// Gets or sets the unique identifier for the payment order, which can be used for tracking and referencing the transaction.
/// </summary>
[StringLength(100)]
[RegularExpression(AllowedCharactersPatterns.ADDITIONAL_ALLOWED_CHARACTERS_PATTERN)]
[JsonPropertyName("orderId")]
public required string OrderId { get; init; }

/// <summary>
/// Gets or initializes the payment method used for the transaction.
/// Gets or sets the payment method used for the transaction. It defines how the payment is processed.
/// </summary>
[JsonPropertyName("paymentMethod")]
public required PaymentMethod PaymentMethod { get; init; }

/// <summary>
/// Gets or initializes the payment method channel for the transaction.
/// Gets or sets the channel through which the payment method is applied, providing additional context for the payment process.
/// </summary>
[JsonPropertyName("paymentMethodChannel")]
public required PaymentMethodChannel PaymentMethodChannel { get; init; }

/// <summary>
/// Gets or initializes the URL to redirect to after a successful payment.
/// Gets or sets the URL to which the user is redirected after a successful payment. This URL is used for post-transaction navigation.
/// </summary>
[StringLength(300)]
[Url]
[JsonPropertyName("successReturnUrl")]
public required string SuccessReturnUrl { get; init; }

/// <summary>
/// Gets or initializes the URL to redirect to after a failed payment.
/// Gets or sets the URL to which the user is redirected after a failed payment. This provides a means to handle unsuccessful transactions.
/// </summary>
[StringLength(300)]
[Url]
[JsonPropertyName("failureReturnUrl")]
public required string FailureReturnUrl { get; init; }

/// <summary>
/// Gets or initializes the general return URL for the payment.
/// Gets or sets a general return URL for the payment, used for redirecting the user after the transaction is processed, regardless of the outcome.
/// </summary>
[StringLength(300)]
[Url]
[JsonPropertyName("returnUrl")]
public required string ReturnUrl { get; init; }

/// <summary>
/// Gets or initializes information about the customer making the payment.
/// Gets or sets the customer's information, essential for processing the payment and for record-keeping purposes.
/// </summary>
[JsonPropertyName("customer")]
public required Customer Customer { get; init; }

/// <summary>
/// Gets or initializes client ip address associated with the user.
/// Gets or sets the IP address of the client initiating the payment. This can be used for security and auditing purposes.
/// </summary>
[JsonPropertyName("clientIp")]
public required string ClientIp { get; init; }

/// <summary>
/// Gets or initializes the title associated with the payment. Can be null.
/// Gets or sets the title associated with the payment. This can be a description or label for the payment, and can be null.
/// </summary>
[StringLength(255)]
[RegularExpression(AllowedCharactersPatterns.ADDITIONAL_ALLOWED_CHARACTERS_PATTERN)]
[JsonPropertyName("title")]
public string? Title { get; init; }

/// <summary>
/// Gets or initializes billing information associated with the payment. Can be null.
/// Gets or sets the billing information for the payment, including details like billing address. This property is optional.
/// </summary>
[JsonPropertyName("billing")]
public Billing? Billing { get; init; }

/// <summary>
/// Gets or initializes shipping information associated with the payment. Can be null.
/// Gets or sets the shipping information for the payment, applicable when the payment involves physical goods. This property is optional.
/// </summary>
[JsonPropertyName("shipping")]
public Shipping? Shipping { get; init; }

/// <summary>
/// Gets or initializes credit card information associated with the payment. Can be null.
/// Gets or sets the credit card information for the payment, required if the payment method is a card. This property is conditional based on the payment method.
/// </summary>
[RequiredIf(
nameof(PaymentMethod),
PaymentMethod.Card
)]
[RequiredIf(nameof(PaymentMethod), PaymentMethod.Card)]
[JsonPropertyName("card")]
public Card? Card { get; init; }

/// <summary>
/// Gets or initializes additional data associated with the payment. Can be null.
/// Gets or sets the BNP instalments information for the payment, providing details for installment-based payments. This property is optional.
/// </summary>
[JsonPropertyName("bnpInstalments")]
public BnpInstalments? BnpInstalments { get; init; }

/// <summary>
/// Gets or sets additional data associated with the payment, which can include any extra information relevant to the payment. This property is optional.
/// </summary>
[JsonPropertyName("additionalData")]
public AdditionalData? AdditionalData { get; init; }

/// <summary>
/// Gets or initializes the timestamp representing the expiration date and time of the transaction.
/// If not provided, the transaction is considered valid indefinitely. Failure to complete the payment
/// by the specified timestamp will result in the cancellation of the transaction.
/// Gets or sets the expiration date and time of the transaction. If not specified, the transaction remains valid indefinitely.
/// Transactions not completed by this timestamp will be automatically cancelled.
/// </summary>
[JsonPropertyName("activeTo")]
public DateTime? ActiveTo { get; init; }
Expand Down
50 changes: 50 additions & 0 deletions src/Axepta.SDK/Entities/Request/Product.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace Axepta.SDK.Entities.Request;

/// <summary>
/// Represents a product with details like name, price, quantity, and code.
/// </summary>
public sealed record Product
{
private int _amount;

/// <summary>
/// Gets the name of the product.
/// </summary>
/// <value>
/// The name of the product as a string.
/// </value>
[JsonPropertyName("name")]
public required string Name { get; init; }

/// <summary>
/// Gets or sets the price of the product.
/// The set method converts the input price from dollars to cents.
/// </summary>
/// <value>
/// The price of the product in cents as an integer.
/// </value>
[JsonPropertyName("price")]
public required int Price
{
get => _amount;
set => _amount = value * 100;
}

/// <summary>
/// Gets the quantity of the product.
/// </summary>
/// <value>
/// The quantity of the product as an integer.
/// </value>
[JsonPropertyName("quantity")]
public required int Quantity { get; init; }

/// <summary>
/// Gets the code of the product.
/// </summary>
/// <value>
/// The code of the product as an integer.
/// </value>
[JsonPropertyName("code")]
public required int Code { get; init; }
}

0 comments on commit cd65cb5

Please sign in to comment.