// Copyright © 2022 Olo Inc. All rights reserved. // This software is made available under the Olo Pay SDK License (See LICENSE.md file) package com.olopaysdkreactnative.extensions import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap import com.olo.olopay.data.IPaymentMethod import com.olo.olopay.data.OloPayEnvironment import com.olopaysdkreactnative.data.DataKeys private const val InvalidExpiration = -1 fun IPaymentMethod.toMap(): WritableMap { return Arguments.createMap().also { it.putString(DataKeys.IDKey, this.id) it.putString(DataKeys.Last4Key, this.last4) it.putString(DataKeys.CardTypeKey, this.cardType.description) it.putInt(DataKeys.ExpirationMonthKey, this.expirationMonth ?: InvalidExpiration) it.putInt(DataKeys.ExpirationYearKey, this.expirationYear ?: InvalidExpiration) it.putString(DataKeys.PostalCodeKey, this.postalCode) it.putString(DataKeys.CountryCodeKey, this.countryCode) it.putString(DataKeys.EmailKey, this.email) it.putString(DataKeys.DigitalWalletCardDescriptionKey, this.googlePayCardDescription) it.putMap(DataKeys.BillingAddressKey, this.billingAddress.toMap()) it.putString(DataKeys.FullNameKey, this.fullName) it.putString(DataKeys.FullPhoneticNameKey, "") // iOS/Apple Pay only, empty on Android it.putString(DataKeys.PhoneNumberKey, this.phoneNumber) it.putBoolean(DataKeys.IsDigitalWalletKey, this.isGooglePay) it.putBoolean(DataKeys.ProductionEnvironmentKey, this.environment == OloPayEnvironment.Production) } }