package com.margelo.nitro.fawrypay.rnfawrypaysdk import com.fawry.fawrypay.domain.models.BillItems as FBillItem import com.fawry.fawrypay.domain.models.FawryLaunchModel as FFawryLaunchModel import com.fawry.fawrypay.domain.models.LaunchCustomerModel as FLaunchCustomerModel import com.fawry.fawrypay.domain.models.LaunchMerchantModel as FLaunchMerchantModel import com.fawry.fawrypay.utils.fawrySdk.enums.PaymentMethods as FPayment_Method object FawryModelConverter { fun convert(model: FawryLaunchModel): FFawryLaunchModel { return FFawryLaunchModel( launchCustomerModel = convert(model.customerInfo), launchMerchantModel = convert(model.merchantInfo), chargeItems = convert(model.items), paymentSignature = model.paymentSignature?.takeIf { it.isNotBlank() }, tokenizationSignature = model.tokenizationSignature?.takeIf { it.isNotBlank() }, allowVoucher = model.allowVoucher, payWithCardToken = model.payWithCardToken, skipReceipt = model.skipReceipt, allow3DPayment = model.allow3DPayment, paymentMethods = convertPaymentMethod(model.paymentMethod), ) } private fun convert(customer: CustomerInfo): FLaunchCustomerModel { return FLaunchCustomerModel( customerName = customer.customerName, customerEmail = customer.customerEmail, customerMobile = customer.customerMobile, customerProfileId = customer.customerProfileId ) } private fun convert(merchant: MerchantInfo): FLaunchMerchantModel { return FLaunchMerchantModel( merchantCode = merchant.merchantCode, merchantRefNum = merchant.merchantRefNum, secretCode = merchant.merchantSecretCode ) } private fun convert(items: Array): ArrayList { return ArrayList(items.map { FBillItem( itemId = it.itemId, description = it.description, price = (it.price.toDoubleOrNull() ?: 0.0).toString(), quantity = (it.quantity.toIntOrNull() ?: 1).toString() ) }) } private fun convertPaymentMethod(method: String?): FPayment_Method { return when (method?.uppercase()) { "PAYATFAWRY" -> FPayment_Method.FAWRY_PAY "PAYUSINGCC" -> FPayment_Method.CREDIT_CARD "MWALLET" -> FPayment_Method.WALLET else -> FPayment_Method.ALL } } }