Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

fun transactionComplete(

displayMetrics: DisplayMetrics,
transactionType: Boolean,
orderId: Long,
firstOrderOnApp: Boolean,
appVersion: String,
rejectedCoupons: List<String>,
errorsQuantityCoupon: Int,
): Boolean {
try {
val donationNotifications = donationsTracking.donationNotifications()
val cameFromOnlinePaymentError =
checkoutStateRepository.isCameFromOnlinePaymentError()
val deliveryAddressType = checkoutStateRepository.getDeliveryAddressType()
val voucher = checkoutStateRepository.getCartResult()?.voucher
val voucherDiscount = checkoutStateRepository.getVoucherDiscount()
val orderTotalAmount =
checkoutStateRepository.getCartResult()?.foodAmount
val orderTaxAmount =
checkoutStateRepository.getCartResult()?.taxes?.twoDecimals() ?: ZERO
val orderShippingAmountNoDiscount =
checkoutStateRepository.getCartResult()?.shippingTaxAmount?.let
{ taxAmount ->

checkoutStateRepository.getCartResult()?.shippingAmountNoDiscount?.plus(
taxAmount
)?.twoDecimals() ?: ZERO
} ?: ZERO
val isPickUp = checkoutStateRepository.getCartResult()?.pickUp ?: false
val orderDiscount = checkoutStateRepository.getVoucherDiscount().toString()
val isPreOrder = checkoutStateRepository.isPreOrder()

val shop = checkoutStateRepository.getSelectedShop()


val street: Street? = locationDataRepository.getEnteredStreet()
val enteredStreet = street?.toString() ?: NOT_SET
val mTransactionType = if (transactionType) ACQUISITION_KEY else
REORDER_KEY
val deviceId = appProperties.getDeviceId()
val coupon = voucher?.takeIf { it.isNotEmpty() } ?: NONE_KEY

val productList = getProducts()


val orderPaymentMethod = getOrderPaymentMethod()

val properties = getCommerce(


orderId,
orderTotalAmount,
orderTaxAmount,
orderShippingAmountNoDiscount,
productList,
coupon
)

properties[Global.SCREEN_TYPE.value] = CHECKOUT_SCREEN_KEY
properties[ORDER_ID] = orderId.toString()
properties[USER_ID] = shopAndSessionRepository.getUserId()
properties[TAG_BUSINESS_TYPE] =
CheckoutTrackingHandler.getBusinessTypeString(
shop?.isDarkstore,
shop?.businessTypeId
) ?: NOT_SET
properties[LOCATION_AREA_ADDRESS] = getAddressArea()
properties[ADDRESS_VALIDATED] = isAddressValidated().toString()
properties[LOCATION_ADDRESS] = enteredStreet
properties[SHOP_ID] = shop?.id.toNotNullable().toString()
properties[SHOP_NAME] = shop?.name.toString()
properties[SHOP_STATUS] = shopAndSessionRepository.getRestaurantStatus()
properties[SHOP_PAYMENT_METHODS] =
shopAndSessionRepository.getShopPaymentMethods()
properties[ORDER_PAYMENT_METHODS] = orderPaymentMethod
properties[ORDER_PICKUP] = isPickUp.toString()
properties[ORDER_PREORDER] = isPreOrder.toString()
properties[TRANSACTION_TYPE] = mTransactionType
properties[APP_VERSION] = appVersion
properties[IN_APP_ACQUISITION] = firstOrderOnApp.toString()
properties[DISPLAY_SIZE] = getDisplaySizeInches(displayMetrics).toString()
properties[DEVICE_MANUFACTURER] = Build.MANUFACTURER.toNotNullable()
properties[DEVICE_MODEL] = Build.MODEL.toNotNullable()
properties[DEVICE] = DEVICE_PHONE
properties[CART_VALUE] =

checkoutStateRepository.getCartResult()?.foodItemsAmount.toNotNullable().toString()
properties[DEAL] = orderDiscount
properties[ERRORS_QUANTITY_TOTAL] =
checkoutStateRepository.getErrorCount().toString()
properties[ERRORS_QUANTITY_ONLINE_PAYMENT] =
checkoutStateRepository.getErrorCategoryPaymentCount().toString()
properties[CAME_FROM_ONLINE_PAYMENT_ERROR] =
cameFromOnlinePaymentError.toString()
properties[AVG_VENDOR_RATING] = shop?.avgRating ?: NOT_SET
properties[VENDOR_REVIEWS] =
shop?.validReviewsCount.toNotNullable().toString()
properties[DEVICE_ID] = deviceId
properties[FEATURED_PRODUCT] = getFeaturedProduct()
properties[COUPON_VALUE] = voucherDiscount.toString()
properties[COUPON_REJECTED] = getRejectedCouponsString(rejectedCoupons)
properties[ERRORS_QUANTITY_COUPON] = errorsQuantityCoupon.toString()
properties[DELIVERY_ADDRESS_TYPE] = deliveryAddressType.toString()
properties[UPSELLING_ITEM] = contentUpsellingItem().toString()
properties[CART_GUID] = checkoutStateRepository.getCartGuid()
properties[FB_CONTENT_ORDER] = getFbContent()
properties[PAYMENT_METHOD_SELECTED] = createPaymentInfo(
paymentState.selectedPaymentMethod,
paymentState.selectedCreditCard,
paymentState.paymentWalletData.useWalletBalance
)
properties[PAYMENT_WALLET_STATUS_KEY] = getWalletPaymentStatus()
properties[PAYMENT_WALLET_BALANCE_KEY] =
paymentState.paymentWalletData.availableWalletBalance.toString()

properties[ORDER_SCHEDULED] =

checkoutStateRepository.getCartPreorderTimesResult().mapToTrackingString()
properties[DonationsTracking.DONATION_NOTIFICATIONS] =
if (paymentState.selectedPaymentMethod?.isOnline.toNotNullable()) {
donationNotifications
} else {
NOT_SET
}
properties[CheckoutTrackingEnum.ORDER_PREORDER_DETAIL.value] =
checkoutStateRepository.getSelectedDeliveryTime()?.scheduleToShow ?:
NOT_SET

TrackingManager.createEvent(ECOMMERCE_PURCHASE).addProperties(properties).send()

TrackingManager.createEvent(FirebaseAnalytics.Event.PURCHASE).addProperties(propert
ies)
.send()
return true
} catch (e: Exception) {
reportHandler.logException(
LogException.Builder().setScreen("splash").build(
project = "mobile",
owner = TraceOwnerEnum.CHECKOUT,
cause = e,
type = ErrorType.PARTIAL,
event = "transaction_event",
useCase = "send_order_transaction_event"
)
)
e.printStackTrace()
return false
}
}

You might also like