Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ internal object GooglePayDisplayItemsFactory {
items += checkoutSession.lineItems.map { it.asDisplayItem() }

checkoutSession.totalSummary?.let { summary ->
items += summary.asSubtotalDisplayItem()
items += summary.discountAmounts.map { it.asDisplayItem() }
items += summary.taxAmounts.map { it.asDisplayItem() }
}

return items
}

private fun CheckoutSession.TotalSummary.asSubtotalDisplayItem(): GooglePayJsonFactory.DisplayItem {
return GooglePayJsonFactory.DisplayItem(
label = SUBTOTAL_LABEL,
type = GooglePayJsonFactory.DisplayItem.Type.SUBTOTAL,
price = subtotal,
)
}

private fun CheckoutSession.LineItem.asDisplayItem(): GooglePayJsonFactory.DisplayItem {
val label = if (quantity > 1) "$name x$quantity" else name
return GooglePayJsonFactory.DisplayItem(
Expand All @@ -54,4 +63,6 @@ internal object GooglePayDisplayItemsFactory {
price = amount,
)
}

private const val SUBTOTAL_LABEL = "Subtotal"
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ class GooglePayDisplayItemsFactoryTest {
type = GooglePayJsonFactory.DisplayItem.Type.LINE_ITEM,
price = 2000L,
),
displayItem(
label = "Subtotal",
type = GooglePayJsonFactory.DisplayItem.Type.SUBTOTAL,
price = 2000L,
),
displayItem(
label = "SAVE50",
type = GooglePayJsonFactory.DisplayItem.Type.DISCOUNT,
Expand Down Expand Up @@ -150,6 +155,11 @@ class GooglePayDisplayItemsFactoryTest {
type = GooglePayJsonFactory.DisplayItem.Type.LINE_ITEM,
price = 1000L,
),
displayItem(
label = "Subtotal",
type = GooglePayJsonFactory.DisplayItem.Type.SUBTOTAL,
price = 1000L,
),
displayItem(
label = "Sales Tax",
type = GooglePayJsonFactory.DisplayItem.Type.TAX,
Expand Down Expand Up @@ -182,6 +192,11 @@ class GooglePayDisplayItemsFactoryTest {
type = GooglePayJsonFactory.DisplayItem.Type.LINE_ITEM,
price = 2000L,
),
displayItem(
label = "Subtotal",
type = GooglePayJsonFactory.DisplayItem.Type.SUBTOTAL,
price = 2000L,
),
displayItem(
label = "SAVE50",
type = GooglePayJsonFactory.DisplayItem.Type.DISCOUNT,
Expand Down
Loading