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 Summary
ConstructorsConstructorDescriptionPaymentApplicationService(PaymentStore payments, org.springframework.context.ApplicationEventPublisher events) -
Method Summary
Modifier and TypeMethodDescriptionAuthorizes an existing pending payment when the submitted amount equals the order total.getPayment(UUID paymentId) Retrieves a payment by identifier.voidpreparePayment(OrderCreatedEvent event) Prepares one pending payment for a committed order.
-
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
Authorizes an existing pending payment when the submitted amount equals the order total.- Specified by:
authorizein interfacePaymentManagement- Parameters:
orderId- order identifieramount- submitted payment amount- Returns:
- authorized payment summary
-
getPayment
Retrieves a payment by identifier.- Specified by:
getPaymentin interfacePaymentManagement- Parameters:
paymentId- payment identifier- Returns:
- payment summary
- Throws:
ResourceNotFoundException- when the payment does not exist
-