diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentelement/confirmation/gpay/GooglePayDisplayItemsFactory.kt b/paymentsheet/src/main/java/com/stripe/android/paymentelement/confirmation/gpay/GooglePayDisplayItemsFactory.kt index 4cb351a0373..45a27f68606 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentelement/confirmation/gpay/GooglePayDisplayItemsFactory.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentelement/confirmation/gpay/GooglePayDisplayItemsFactory.kt @@ -23,6 +23,7 @@ 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() } } @@ -30,6 +31,14 @@ internal object GooglePayDisplayItemsFactory { 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( @@ -54,4 +63,6 @@ internal object GooglePayDisplayItemsFactory { price = amount, ) } + + private const val SUBTOTAL_LABEL = "Subtotal" } diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/gpay/GooglePayDisplayItemsFactoryTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/gpay/GooglePayDisplayItemsFactoryTest.kt index 8c5921f6895..c7b0fd9576f 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/gpay/GooglePayDisplayItemsFactoryTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/gpay/GooglePayDisplayItemsFactoryTest.kt @@ -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, @@ -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, @@ -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,