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 AbstractPaymentService

Inheritance

object ← AbstractPaymentService


Derived

MollieService

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


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 _db

Field 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> _logger

Field 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

NameTypeDescription
paymentIdstringThe unique identifier of the payment transaction.

Returns

TypeDescription
TaskA 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

NameTypeDescription
amountdecimalThe amount to be paid.
descriptionstringA description of the payment transaction.
redirectUrlstringAn optional URL to which the user will be redirected after the payment is completed.
webhookUrlstringAn optional URL to which payment status updates will be sent via webhooks.
metadatastringOptional metadata associated with the payment transaction.

Returns

TypeDescription
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

NameTypeDescription
paymentIdstringThe unique identifier of the payment transaction.

Returns

TypeDescription
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

NameTypeDescription
idstringThe unique identifier of the payment transaction.

Returns

Exceptions

TypeDescription
ExceptionThrown when the payment is not found.
TypeDescription
TaskA 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

NameTypeDescription
memberIdGuidThe member to send the activation email to.

Returns

TypeDescription
Task<bool>True if this call queued the email; false if one had already been sent.

On this page