Skip to content

Commit

Permalink
Merge pull request #17 from FIAP-3SOAT-G15/adjust-to-orders
Browse files Browse the repository at this point in the history
Adjust orders
  • Loading branch information
wellyfrs authored May 20, 2024
2 parents 1c5ae1c + d47633e commit 1c6e27a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push docker image to Amazon ECR
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
#if: github.ref == 'refs/heads/main' && github.event_name == 'push'
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ vars.AWS_ECR_REPO_NAME }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class MercadoPagoPaymentProvider(
"by ${ paymentHTTPRequest.orderInfo.orderedBy }",
externalReference = paymentHTTPRequest.orderInfo.number.toString(),
notificationUrl = notificationUrl,
totalAmount = paymentHTTPRequest.orderInfo.totalAmount,
totalAmount = paymentHTTPRequest.orderInfo.total,
items = paymentHTTPRequest.orderInfo.lines.map { orderLine ->
MercadoPagoQRCodeOrderRequestItem(
title = orderLine.name,
unitPrice = orderLine.unitPrice,
quantity = orderLine.quantity,
unitMeasure = orderLine.unitOfMeasurement,
totalAmount = orderLine.totalAmount,
unitMeasure = DEFAULT_UNIT_OF_MEASUREMENT,
totalAmount = orderLine.total,
)
},
),
Expand Down Expand Up @@ -74,4 +74,8 @@ class MercadoPagoPaymentProvider(
PAYMENT_IN_PROCESS("payment_in_process"),
PAYMENT_REQUIRED("payment_required"),
}

companion object {
const val DEFAULT_UNIT_OF_MEASUREMENT = "UNIT"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,36 @@ data class PaymentHTTPRequest(
data class OrderInfo(
@Schema(title = "Número de pedido", example = "1", required = true)
val number: Long,

@JsonFormat(shape = JsonFormat.Shape.STRING)
@Schema(title = "Valor total", example = "10.00", required = true)
val totalAmount: BigDecimal,
val total: BigDecimal,

@ArraySchema(
schema = Schema(implementation = OrderLine::class, required = true),
minItems = 1
)
val lines: List<OrderLine>,

@Schema(title = "Data do pedido", example = "2024-05-19T11:00:00", required = true)
val orderedAt: LocalDateTime,

@Schema(title = "Solicitante", example = "John Doe", required = true)
val orderedBy: String,
)

data class OrderLine(
@Schema(title = "Nome do item de pedido", example = "Big Mac", required = true)
val name: String,

@JsonFormat(shape = JsonFormat.Shape.STRING)
@Schema(title = "Valor unitário", example = "10.00", required = true)
val unitPrice: BigDecimal,

@Schema(title = "Quantidade", example = "1", required = true)
val quantity: Long,
@Schema(title = "Unidade de medida", example = "UND", required = true)
val unitOfMeasurement: String,

@JsonFormat(shape = JsonFormat.Shape.STRING)
@Schema(title = "Valor total", example = "10.00", required = true)
val totalAmount: BigDecimal,
val total: BigDecimal,
)
5 changes: 2 additions & 3 deletions src/test/kotlin/com/fiap/payments/TestFixtures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ fun createOrderInfo(
number = number,
orderedAt = orderedAt,
orderedBy = orderedBy,
totalAmount = totalAmount,
total = totalAmount,
lines = listOf(
OrderLine(
name = "Item 1",
quantity = 1,
totalAmount = BigDecimal.valueOf(10),
unitOfMeasurement = "unit",
total = BigDecimal.valueOf(10),
unitPrice = BigDecimal.valueOf(10),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PaymentGatewayImplTest {

assertThat(result).containsExactlyInAnyOrderElementsOf(paymentEntities)
}

@Test
fun `should return existent payment`() {
val paymentId = UUID.randomUUID().toString()
Expand All @@ -67,7 +67,7 @@ class PaymentGatewayImplTest {
}

@Nested
inner class Upsert {
inner class UpsertPayment {

@Test
fun `should insert new payment`() {
Expand All @@ -85,7 +85,7 @@ class PaymentGatewayImplTest {

@Test
fun `should update payment`() {
val oldPayment = createPayment(status = PaymentStatus.PENDING)
val oldPayment = createPayment(id = UUID.randomUUID().toString(), status = PaymentStatus.PENDING)
val newPayment = oldPayment.copy(status = PaymentStatus.CONFIRMED)
val oldPaymentDocument = oldPayment.toDocument()
val newPaymentDocument = newPayment.toDocument()
Expand Down

0 comments on commit 1c6e27a

Please sign in to comment.