-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
48 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 8 additions & 6 deletions
14
src/main/kotlin/com/fiap/order/usecases/services/PaymentService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
package com.fiap.order.usecases.services | ||
|
||
import com.fiap.order.adapter.gateway.PaymentGateway | ||
import com.fiap.order.adapter.gateway.PaymentProviderGateway | ||
import com.fiap.order.domain.entities.Order | ||
import com.fiap.order.domain.entities.Payment | ||
import com.fiap.order.domain.errors.ErrorType | ||
import com.fiap.order.domain.errors.SelfOrderManagementException | ||
import com.fiap.order.domain.valueobjects.PaymentStatus | ||
import com.fiap.order.driver.web.request.PaymentRequest | ||
import com.fiap.order.usecases.LoadPaymentUseCase | ||
import com.fiap.order.usecases.ProvidePaymentRequestUseCase | ||
import java.time.LocalDateTime | ||
import org.slf4j.LoggerFactory | ||
|
||
class PaymentService( | ||
private val paymentRepository: PaymentGateway, | ||
private val paymentGateway: PaymentGateway, | ||
) : | ||
LoadPaymentUseCase, | ||
ProvidePaymentRequestUseCase { | ||
private val log = LoggerFactory.getLogger(javaClass) | ||
|
||
override fun getByOrderNumber(orderNumber: Long): Payment { | ||
return paymentRepository.findByOrderNumber(orderNumber) | ||
log.info("Requesting payment for order [$orderNumber]") | ||
return paymentGateway.findByOrderNumber(orderNumber) | ||
?: throw SelfOrderManagementException( | ||
errorType = ErrorType.PAYMENT_NOT_FOUND, | ||
message = "Payment not found for order [$orderNumber]", | ||
) | ||
} | ||
|
||
override fun providePaymentRequest(order: Order): PaymentRequest { | ||
return paymentRepository.createFromOrder(order) | ||
log.info("Requesting payment request for order $order") | ||
return paymentGateway.createFromOrder(order) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters