Class PaymentApplicationService

java.lang.Object
com.example.orderplatform.payments.application.PaymentApplicationService
All Implemented Interfaces:
PaymentManagement

@Service @Transactional public class PaymentApplicationService extends Object implements PaymentManagement
Application service that prepares payments from committed orders and authorizes matching payments.
  • Constructor Details

    • PaymentApplicationService

      public PaymentApplicationService(PaymentStore payments, org.springframework.context.ApplicationEventPublisher events)
  • Method Details

    • preparePayment

      @TransactionalEventListener(phase=AFTER_COMMIT) @Transactional(propagation=REQUIRES_NEW) public void preparePayment(OrderCreatedEvent event)
      Prepares one pending payment for a committed order.

      The listener runs after the order transaction commits and uses a new transaction so payment preparation is not part of the original order write.

      Parameters:
      event - committed order event
    • authorize

      public PaymentSummary authorize(UUID orderId, Money amount)
      Authorizes an existing pending payment when the submitted amount equals the order total.
      Specified by:
      authorize in interface PaymentManagement
      Parameters:
      orderId - order identifier
      amount - submitted payment amount
      Returns:
      authorized payment summary
    • getPayment

      @Transactional(readOnly=true) public PaymentSummary getPayment(UUID paymentId)
      Retrieves a payment by identifier.
      Specified by:
      getPayment in interface PaymentManagement
      Parameters:
      paymentId - payment identifier
      Returns:
      payment summary
      Throws:
      ResourceNotFoundException - when the payment does not exist