AbstractPaymentService
Namespace: Backend.Services.PaymentServices
Assembly: Backend.dll
Defines an interface for a payment client that can retrieve the status of a payment transaction based on its unique identifier.
public abstract class AbstractPaymentServiceInheritance
object ← AbstractPaymentService
Derived
MollieService
Show Inherited Members (7)
Constructors
AbstractPaymentService(PostgresDbContext, ILogger<AbstractPaymentService>)
Defines an interface for a payment client that can retrieve the status of a payment transaction based on its unique identifier.
protected AbstractPaymentService(PostgresDbContext _db, ILogger<AbstractPaymentService> _logger)Parameters
| Name | Type |
|---|---|
| _db | PostgresDbContext |
| _logger | ILogger<AbstractPaymentService> |
Fields
_db
The database context used for accessing and manipulating payment-related data in the underlying database. This context provides methods for querying and saving instances of payment entities, allowing the service to interact with the database in a structured manner.
protected readonly PostgresDbContext _dbField Value
PostgresDbContext
_logger
The logger instance used for logging informational messages, warnings, and errors related to payment service operations. This logger allows the service to record important events and issues that occur during the execution of payment-related tasks, facilitating debugging and monitoring of the service's behavior.
protected readonly ILogger<AbstractPaymentService> _loggerField Value
ILogger<AbstractPaymentService>
Properties
IsUsingAccountingTool
Gets a value indicating whether an accounting tool integration is configured in the database settings.
protected bool IsUsingAccountingTool { get; }Property Value
bool
Methods
CancelPaymentAsync(string)
Cancels a payment transaction using its unique identifier.
public abstract Task CancelPaymentAsync(string paymentId)Parameters
| Name | Type | Description |
|---|---|---|
| paymentId | string | The unique identifier of the payment transaction. |
Returns
| Type | Description |
|---|---|
Task | A task representing the asynchronous operation. |
CreatePaymentAsync(decimal, string, string?, string?, string?)
Creates a new payment transaction with the specified amount, description, and optional parameters for redirect URL, webhook URL, and metadata.
public abstract Task<CreatePaymentResponse> CreatePaymentAsync(decimal amount, string description, string? redirectUrl = null, string? webhookUrl = null, string? metadata = null)Parameters
| Name | Type | Description |
|---|---|---|
| amount | decimal | The amount to be paid. |
| description | string | A description of the payment transaction. |
| redirectUrl | string | An optional URL to which the user will be redirected after the payment is completed. |
| webhookUrl | string | An optional URL to which payment status updates will be sent via webhooks. |
| metadata | string | Optional metadata associated with the payment transaction. |
Returns
| Type | Description |
|---|---|
Task<CreatePaymentResponse> | A task that represents the asynchronous operation and contains the unique identifier of the created payment transaction. |
GetPaymentAsync(string)
Retrieves the status of a payment transaction using its unique identifier.
public abstract Task<GetPaymentResponse> GetPaymentAsync(string paymentId)Parameters
| Name | Type | Description |
|---|---|---|
| paymentId | string | The unique identifier of the payment transaction. |
Returns
| Type | Description |
|---|---|
Task<GetPaymentResponse> | The status of the payment transaction. |
HandleWebhookAsync(string)
Handles a webhook notification for a payment transaction with the specified unique identifier, processing the payment status update and performing necessary actions based on the updated status. This method is responsible for retrieving the current status of the payment transaction, updating local records accordingly, and triggering any necessary follow-up actions such as synchronizing with authentication systems or accounting tools, all within a transactional context to ensure data integrity.
public virtual Task HandleWebhookAsync(string id)Parameters
| Name | Type | Description |
|---|---|---|
| id | string | The unique identifier of the payment transaction. |
Returns
Exceptions
| Type | Description |
|---|---|
Exception | Thrown when the payment is not found. |
| Type | Description |
|---|---|
Task | A task representing the asynchronous operation. |
TryQueueActivationEmailAsync(Guid)
Marks a member as having been sent their one-time account-activation email and enqueues the outbox task for it, but only if one hasn't been sent already. The confirm-mail page, this webhook, and the periodic PaymentSyncService reconciliation can all end up wanting to send it for the same member around the same time (Mollie's redirect fires before a payment necessarily settles, so the page's attempt may have already declined, or may race with one of the others). The check-and-set is a single atomic conditional update at the database level rather than a tracked-entity read followed by a separate write, so concurrent callers - even across separate requests/DbContexts - can never both win: only one ever queues the email.
public virtual Task<bool> TryQueueActivationEmailAsync(Guid memberId)Parameters
| Name | Type | Description |
|---|---|---|
| memberId | Guid | The member to send the activation email to. |