From ae7e03235e8559898e9eb2c76e6bd5e487dc2caa Mon Sep 17 00:00:00 2001 From: Nathan Schott Date: Fri, 8 Sep 2023 19:14:34 -0400 Subject: [PATCH 01/37] refactor: prevent destroying modal on close (#3) --- .../java/com/paypal/messages/ModalFragment.kt | 35 +++++++++---------- .../com/paypal/messages/PayPalMessageView.kt | 25 ++++++++----- library/src/main/res/values/styles.xml | 10 ++++++ 3 files changed, 44 insertions(+), 26 deletions(-) create mode 100644 library/src/main/res/values/styles.xml diff --git a/library/src/main/java/com/paypal/messages/ModalFragment.kt b/library/src/main/java/com/paypal/messages/ModalFragment.kt index 4008c9d7..52f92bd2 100644 --- a/library/src/main/java/com/paypal/messages/ModalFragment.kt +++ b/library/src/main/java/com/paypal/messages/ModalFragment.kt @@ -2,7 +2,6 @@ package com.paypal.messages import android.annotation.SuppressLint import android.app.Dialog -import android.content.DialogInterface import android.content.Intent import android.graphics.Color import android.graphics.PorterDuff @@ -49,10 +48,8 @@ import com.paypal.messages.utils.LogCat import java.net.URI import java.util.UUID import kotlin.system.measureTimeMillis -import com.google.android.material.R as MaterialR import com.paypal.messages.config.PayPalMessageOfferType as OfferType - @RequiresApi(Build.VERSION_CODES.M) internal class ModalFragment constructor( private val clientId: String, @@ -76,6 +73,7 @@ internal class ModalFragment constructor( private var currentUrl: String? = null private var webView: WebView? = null private var rootView: View? = null + private var dialog: BottomSheetDialog? = null private var closeButtonData: ModalCloseButton? = null private var instanceId = UUID.randomUUID() @@ -136,12 +134,12 @@ internal class ModalFragment constructor( closeButton?.setOnClickListener { logEvent(TrackingEvent(eventType = EventType.MODAL_CLOSE)) - this.dismiss() + dialog?.hide() } // If we already have a WebView, don't reset it LogCat.debug(TAG, "Configuring WebView Settings and Handlers") - val webView = rootView.findViewById(R.id.ModalWebView) + val webView = rootView.findViewById(R.id.ModalWebView) // Programmatically set bottom margin instead of in XML since we also apply it to the // dialog behavior below to control it in a single location. The expanded offset below shifts @@ -250,23 +248,24 @@ internal class ModalFragment constructor( } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog - dialog.window?.setBackgroundDrawableResource(android.R.color.transparent) - dialog.behavior.isFitToContents = false - dialog.behavior.expandedOffset = offsetTop - dialog.behavior.isHideable = false - dialog.behavior.isDraggable = false - dialog.behavior.state = BottomSheetBehavior.STATE_EXPANDED - dialog.setOnShowListener { setupBottomSheet(it) } + setStyle(STYLE_NO_FRAME, R.style.BottomSheetDialog) + + val dialog = (super.onCreateDialog(savedInstanceState) as BottomSheetDialog).apply { + window?.setBackgroundDrawableResource(android.R.color.transparent) + behavior.isFitToContents = false + behavior.expandedOffset = offsetTop + behavior.isHideable = true + behavior.isDraggable = true + behavior.state = BottomSheetBehavior.STATE_EXPANDED + } + + this.dialog = dialog return dialog } - private fun setupBottomSheet(dialogInterface: DialogInterface) { - val bottomSheetDialog = dialogInterface as BottomSheetDialog - val bottomSheet = bottomSheetDialog.findViewById(MaterialR.id.design_bottom_sheet) - if (bottomSheet === null) return - bottomSheet.setBackgroundColor(Color.TRANSPARENT) + fun expand() { + this.dialog?.show() } fun init(config: ModalConfig) { diff --git a/library/src/main/java/com/paypal/messages/PayPalMessageView.kt b/library/src/main/java/com/paypal/messages/PayPalMessageView.kt index 17d31b7b..7bf2e970 100644 --- a/library/src/main/java/com/paypal/messages/PayPalMessageView.kt +++ b/library/src/main/java/com/paypal/messages/PayPalMessageView.kt @@ -324,15 +324,9 @@ class PayPalMessageView @JvmOverloads constructor( } private fun showWebView(response: ActionResponse) { - // Does an instance of the modal exist already? - if (modal != null) { - modal!!.show((context as AppCompatActivity).supportFragmentManager, modal!!.tag) - } - else { - // if it doesn't, instantiate the modal - val modal = ModalFragment(clientId) - val fragmentManager = (context as AppCompatActivity).supportFragmentManager + val modal = modal ?: run { + val modal = ModalFragment(clientId) // Build modal config val modalConfig = ModalConfig( amount = amount, @@ -352,8 +346,23 @@ class PayPalMessageView @JvmOverloads constructor( modal.init(modalConfig) modal.show((context as AppCompatActivity).supportFragmentManager, modal.tag) + this.modal = modal + + modal } + + // modal.show() above will display the modal on initial view, but if the user closes the modal + // it will become visually hidden and this method will re-display the modal without + // attempting to reattach it + modal.expand() + } + + override fun onDetachedFromWindow() { + super.onDetachedFromWindow() + // The modal will not dismiss (destroy) itself, it will only hide/show when opening and closing + // so we need to cleanup the modal instance if the message is removed + this.modal?.dismiss() } fun refresh() { diff --git a/library/src/main/res/values/styles.xml b/library/src/main/res/values/styles.xml new file mode 100644 index 00000000..7957b5a8 --- /dev/null +++ b/library/src/main/res/values/styles.xml @@ -0,0 +1,10 @@ + + + + + + From e6e59a442f9806007976190de9e1572555586c52 Mon Sep 17 00:00:00 2001 From: merlinpaypal <124289716+merlinpaypal@users.noreply.github.com> Date: Tue, 26 Sep 2023 01:00:40 -0400 Subject: [PATCH 02/37] chore: Update README and split out DEVELOPMENT (#2) --- .gitignore | 5 +- .idea/.gitignore | 17 ++ .idea/.name | 1 + .idea/codeStyles/Project.xml | 202 +++++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/compiler.xml | 6 + .idea/gradle.xml | 20 ++ .idea/inspectionProfiles/Project_Default.xml | 39 ++++ .idea/kotlinc.xml | 6 + .idea/misc.xml | 14 ++ .idea/vcs.xml | 6 + DEVELOPMENT.md | 119 +++++++++++ README.md | 110 +++------- 13 files changed, 467 insertions(+), 83 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/.name create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/kotlinc.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 DEVELOPMENT.md diff --git a/.gitignore b/.gitignore index 878c2cd5..39a4b769 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,13 @@ *.iml .gradle /local.properties -.idea .DS_Store /build /captures .externalNativeBuild .cxx local.properties + +# Recommended Ignores by JetBrains +# https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 +# .idea/ files are handled in .idea/.gitignore diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..847291c3 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,17 @@ +# Recommended Ignores by JetBrains +# https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 +# Default ignored files +/dictionaries/ +/libraries/ +/modules/ +/shelf/ +/assetWizardSettings.xml +/dataSources.ids +/dataSources.xml +/dynamic.xml +/modules.xml +/sqlDataSources.xml +/tasks.xml +/workspace.xml +/usage.statistics.xml +*.iml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..fa692ec6 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +PayPalMessages diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 00000000..540bc2e0 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 00000000..1a0176ac --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..d208d08e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 00000000..ed4c5b1e --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..f72e9dab --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,39 @@ + + + + diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 00000000..fbd3b0a1 --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..188f6e32 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..5ace414d --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 00000000..143762ad --- /dev/null +++ b/DEVELOPMENT.md @@ -0,0 +1,119 @@ +# PayPalMessages Android Development Notes + +- [Setup](#setup) +- [Running the Demo](#running-the-demo) +- [Troubleshooting](#troubleshooting) +- [Sample Modal URL](#sample-modal-url) + +## Setup + +### Set Demo Client ID + +Set the demo's client ID inside of [demo locals](demo/src/main/res/values/locals.xml) + +If you plan to make commits, be sure to ignore the file after you pull so you don't accidentally commit a client ID. + +### Ignored Files + +To prevent commits of sensitive data, tell git to ignore future changes to some files, including: + +- [demo locals](demo/src/main/res/values/locals.xml) + +Run `./scripts/ignore-files.sh -y`, which will tell git to ignore the files above. + +To see how to stop ignoring files or to list ignored files, see [ignore-files.sh](scripts/ignore-files.sh) + +### Environment Variables + +Add environment variables to your shell config file (`~/.zshrc`, `~/.bashrc`, so on) + +``` +export UPSTREAM_ANDROID_STAGE_URL="" +export UPSTREAM_ANDROID_STAGE_VPN_URL="" +export UPSTREAM_ANDROID_LOCAL_URL="" +``` + +## Running the Demo + + + +There is one activity that can be run for PayPalMessages: + +- [XmlActivity](demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt) + - Uses traditional [XML Layouts](https://developer.android.com/develop/ui/views/layout/declaring-layout) + +To run the activity: + +1. Open your run configurations +2. If you don't have any run configurations, create one + +3. Under the **General** tab of the configuration, modify Launch Options + - Set **Launch** to **Specified Activity** + - Set **Activity** to the above activity + - com.paypal.messages demo.XmlActivity + +![Run General Settings Screenshot](readme-images/run-settings_general.png) + +## Troubleshooting + +### Logcat Debugging + +For ease of debugging, it is suggested to set Logcat to clear and show automatically. + +To set that up: + +1. Open your run configurations +2. Select the run configuration to modify +3. Under the **Miscellaneous** tab of the configuration, modify Logcat + - Check **Show logcat automatically** + - Check **Clear log before launch** + +![Run Miscellaneous Settings Screenshot](readme-images/run-settings_miscellaneous.png) + +### `JAVA_HOME` ISSUES + +If you get the below error during your build attempt, please follow these instructions to fix it. + +``` +ERROR: JAVA_HOME is set to an invalid directory: +``` + +1. Click **File** and then **Project Structure** +2. Click **Gradle Settings** + +![Java Home Project Structure Settings Screenshot](readme-images/java_home-settings_project_structure.png) + +3. In Gradle Settings, note the file path to the Gradle JDK + +![Java Home Gradle Settings Screenshot](readme-images/java_home-settings_gradle.png) + +4. Open your shell's Run Commands file (`.zshrc`, `.bashrc`, etc) +5. Add a line to export `JAVA_HOME` and set its value to the path from step 3 + +``` +export JAVA_HOME='/Applications/Android Studio.app/Contents/jbr/Contents/Home' +``` + +Or if it matches this path, you can run this command to add it your `.zshrc` + +``` +echo 'export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home"' >> ~/.zshrc +``` + +## Sample Modal URL + +This what a modal URL should look like. + +``` +https://www.paypal.com/credit-presentment/lander/modal?client_id=CLIENT_ID&integration_type=NATIVE_ANDROID&features=native-modal +``` diff --git a/README.md b/README.md index 3fe402fa..d0f600f3 100644 --- a/README.md +++ b/README.md @@ -1,66 +1,42 @@ -# PayPalMessages +# PayPalMessages Android -## Run +A messaging component library allowing easy integration of PayPal Credit Messages onto your app. -There are two activities that can be run for PayPalMessages: +- [Availability](#availability) +- [Contribution](#contribution) +- [Support](#support) +- [Client ID](#client-id) +- [Release Process](#release-process) +- [Testing](#testing) +- [Static Analysis Tools](#static-analysis-tools) +- [Build](#build) +- [Local Development and Troubleshooting](#local-development-and-troubleshooting) -- [JetpackActivity](demo/src/main/java/com/paypal/messagesdemo/JetpackActivity.kt) - - Uses [Jetpack Compose](https://developer.android.com/jetpack/compose) to render PayPalMessages - - Jetpack Compose is the new way to render Android UI, [since 2021](https://android-developers.googleblog.com/2021/07/jetpack-compose-announcement.html) - - **Note**: The Jetpack view does not currently work to show PayPalMessages -- [XmlActivity](demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt) - - Uses traditional [XML Layouts](https://developer.android.com/develop/ui/views/layout/declaring-layout) +## Availability +The library is currently in the development process. This product is being developed fully open source - throughout the development process, we welcome any and all feedback. Aspects of the library _will likely_ change as we develop the SDK. We recommend using the library in the sandbox environment until an official release is available. This README will be updated with an official release date once it is generally available. -To run either activity: +## Contribution +As the library is moved to general availability, we will be adding a contribution guide for developers that would like to contribute to the library. If you have suggestions for features that you would like to see in future iterations of the library, please feel free to open an issue, PR, or discussion with suggestions. If you want to open a PR but are unsure about our testing strategy, we are more than happy to work with you to add tests to any PRs before work is merged. -1. Open your run configurations -2. If you don't have any run configurations, create one - - It is suggested to create two configurations, one for running JetpackActivity and one for running XmlActivity -3. Under the **General** tab of the configuration, modify Launch Options - - Set **Launch** to **Specified Activity** - - Set **Activity** to one of the above activities - - com.paypal.messages demo.JetpackActivity - - com.paypal.messages demo.XmlActivity +## Support +The PayPalMessages Library is available for Android SDK 23+. -![Run General Settings Screenshot](readme-images/run-settings_general.png) +## Client ID -### Environment Variables +The PayPalMessages Library uses a client ID for authentication. This can be found in your [PayPal Developer Dashboard](https://developer.paypal.com/api/rest/#link-getstarted). -Add environment variables to your shell config file (`~/.zshrc`, `~/.bashrc`, so on) +## Release Process +This library follows [Semantic Versioning](https://semver.org/). This library is published to Maven Central. The release process is automated via GitHub Actions. -``` -export UPSTREAM_ANDROID_STAGE_URL="" -export UPSTREAM_ANDROID_STAGE_VPN_URL="" -export UPSTREAM_ANDROID_LOCAL_URL="" -``` +## Testing -### Set Demo Client ID +This repository includes unit tests, integration tests, and end-to-end tests. -Set the demo's client ID inside of [demo locals](demo/src/main/res/values/locals.xml) +// TODO: Add sections with commands for running each type of tests -### Ignored Files +## Static Analysis Tools -To prevent commits of sensitive data, tell git to ignore future changes to some files, including: - -- [demo locals](demo/src/main/res/values/locals.xml) - -Run `./scripts/ignore-files.sh -y`, which will tell git to ignore the files above. - -To see how to stop ignoring files or to list ignored files, see [ignore-files.sh](scripts/ignore-files.sh) - -### Logcat Debugging - -For ease of debugging, it is suggested to set Logcat to clear and show automatically. - -To set that up: - -1. Open your run configurations -2. Select the run configuration to modify -3. Under the **Miscellaneous** tab of the configuration, modify Logcat - - Check **Show logcat automatically** - - Check **Clear log before launch** - -![Run Miscellaneous Settings Screenshot](readme-images/run-settings_miscellaneous.png) +// TODO: Add sections with commands for static analysis ## Build @@ -73,36 +49,6 @@ To set that up: ![Switch Folder View Screenshot](readme-images/build-switch_view.png) -### `JAVA_HOME` ISSUES - -If you get the below error during your build attempt, please follow these instructions to fix it. - -``` -ERROR: JAVA_HOME is set to an invalid directory: -``` - -1. Click **File** and then **Project Structure** -2. Click **Gradle Settings** - -![Java Home Project Structure Settings Screenshot](readme-images/java_home-settings_project_structure.png) - -3. In Gradle Settings, note the file path to the Gradle JDK - -![Java Home Gradle Settings Screenshot](readme-images/java_home-settings_gradle.png) - -4. Open your shell's Run Commands file (`.zshrc`, `.bashrc`, etc) -5. Add a line to export `JAVA_HOME` and set its value to the path from step 3 - -``` -export JAVA_HOME='/Applications/Android Studio.app/Contents/jbr/Contents/Home' -``` - -Or if it matches this path, you can run this command to add it your `.zshrc` - -``` -echo 'export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home"' >> ~/.zshrc -``` - -# Sample Modal URL +## Local Development and Troubleshooting -[https://www.paypal.com/credit-presentment/lander/modal?client_id=CLIENT_ID&integration_type=NATIVE_ANDROID&features=native-modal](https://www.paypal.com/credit-presentment/lander/modal?client_id=CLIENT_ID&integration_type=NATIVE_ANDROID&features=native-modal) +See [our development guidelines](DEVELOPMENT.md) From d72cceef42158444167abca1b8f3d4cb58023c63 Mon Sep 17 00:00:00 2001 From: Grant Black <85238976+grablack@users.noreply.github.com> Date: Wed, 27 Sep 2023 08:32:32 -0400 Subject: [PATCH 03/37] feat: add instance_id (#4) --- .../main/java/com/paypal/messages/PayPalMessageView.kt | 9 +++++++-- .../com/paypal/messages/io/ActionResponseMetadata.kt | 3 +++ library/src/main/java/com/paypal/messages/io/Api.kt | 9 ++++++++- .../java/com/paypal/messages/logger/TrackingComponent.kt | 4 ++++ .../java/com/paypal/messages/logger/TrackingPayload.kt | 3 +++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/paypal/messages/PayPalMessageView.kt b/library/src/main/java/com/paypal/messages/PayPalMessageView.kt index 7bf2e970..fd5f7989 100644 --- a/library/src/main/java/com/paypal/messages/PayPalMessageView.kt +++ b/library/src/main/java/com/paypal/messages/PayPalMessageView.kt @@ -31,6 +31,7 @@ import com.paypal.messages.config.modal.ModalEvents import com.paypal.messages.errors.BaseException import com.paypal.messages.io.Action import com.paypal.messages.io.ActionResponse +import com.paypal.messages.io.Api import com.paypal.messages.io.ApiResult import com.paypal.messages.io.OnActionCompleted import com.paypal.messages.logger.ComponentType @@ -80,7 +81,6 @@ class PayPalMessageView @JvmOverloads constructor( private var logoType: LogoType = LogoType.PRIMARY private var alignment: Align = Align.LEFT - private var instanceId = UUID.randomUUID() // Full Message Data private var data: ActionResponse? = null @@ -141,6 +141,7 @@ class PayPalMessageView @JvmOverloads constructor( updateFromAttributes(typedArray) } config?.let { updateFromConfig(it) } + Api.sessionId = UUID.randomUUID(); updateMessageContent() } @@ -509,6 +510,8 @@ class PayPalMessageView @JvmOverloads constructor( */ private fun updateMessageContent() { if (!updateInProgress) { + Api.instanceId = UUID.randomUUID(); + // Call OnLoading callback and prepare view for the process onLoading.invoke() messageTextView.visibility = View.GONE @@ -703,7 +706,9 @@ class PayPalMessageView @JvmOverloads constructor( offerCountryCode = this.data?.meta?.offerCountryCode, merchantCountryCode = this.data?.meta?.merchantCountryCode, type = ComponentType.MESSAGE.toString(), - instanceId = this.instanceId.toString(), + instanceId = Api.instanceId.toString(), + originatingInstanceId = Api.originatingInstanceId.toString(), + sessionId = Api.sessionId.toString(), events = mutableListOf(event), ) diff --git a/library/src/main/java/com/paypal/messages/io/ActionResponseMetadata.kt b/library/src/main/java/com/paypal/messages/io/ActionResponseMetadata.kt index 67012aec..3be069b0 100644 --- a/library/src/main/java/com/paypal/messages/io/ActionResponseMetadata.kt +++ b/library/src/main/java/com/paypal/messages/io/ActionResponseMetadata.kt @@ -4,6 +4,7 @@ import com.google.gson.annotations.SerializedName import com.paypal.messages.config.PayPalMessageOfferType import com.paypal.messages.config.ProductGroup import com.paypal.messages.config.modal.ModalCloseButton +import java.util.* data class ActionResponseMetadata( @SerializedName("credit_product_group") @@ -28,4 +29,6 @@ data class ActionResponseMetadata( val fdata: String, @SerializedName("tracking_keys") val trackingKeys: List, + @SerializedName("originating_instance_id") + val originatingInstanceId: UUID ) diff --git a/library/src/main/java/com/paypal/messages/io/Api.kt b/library/src/main/java/com/paypal/messages/io/Api.kt index b845dbc8..69d434ac 100644 --- a/library/src/main/java/com/paypal/messages/io/Api.kt +++ b/library/src/main/java/com/paypal/messages/io/Api.kt @@ -16,12 +16,16 @@ import okhttp3.RequestBody.Companion.toRequestBody import okio.IOException import com.paypal.messages.config.PayPalMessageOfferType as OfferType import com.paypal.messages.config.message.PayPalMessageConfig as MessageConfig +import java.util.UUID object Api { private const val TAG = "Api" private val client = OkHttpClient() private val gson = Gson() var environment = Environment.SANDBOX + var instanceId: UUID? = null; + var originatingInstanceId: UUID? = null; + var sessionId: UUID? = null; object Endpoints { private val ROOT_URLS = mapOf( @@ -47,6 +51,8 @@ object Api { addQueryParameter("devTouchpoint", "false") addQueryParameter("env", environment.name.lowercase()) addQueryParameter("logo_type", config.style.logoType.name.lowercase()) + addQueryParameter("instance_id", instanceId.toString()) + addQueryParameter("session_id", sessionId.toString()) config.data?.amount?.let { addQueryParameter("amount", it.toString()) } config.data?.buyerCountry?.let { addQueryParameter("buyer_country", it) } @@ -86,7 +92,8 @@ object Api { val isValidResponse = body?.content != null && body.meta != null return if (isValidResponse) { - ApiResult.Success(body) + Api.originatingInstanceId = body.meta?.originatingInstanceId; + ApiResult.Success(body); } else { ApiResult.getFailureWithDebugId(response.headers) diff --git a/library/src/main/java/com/paypal/messages/logger/TrackingComponent.kt b/library/src/main/java/com/paypal/messages/logger/TrackingComponent.kt index dccec291..f773f1e0 100644 --- a/library/src/main/java/com/paypal/messages/logger/TrackingComponent.kt +++ b/library/src/main/java/com/paypal/messages/logger/TrackingComponent.kt @@ -56,6 +56,10 @@ data class TrackingComponent( val type: String? = null, @SerializedName("instance_id") val instanceId: String? = null, + @SerializedName("originating_instance_id") + val originatingInstanceId: String? = null, + @SerializedName("session_id") + val sessionId: String? = null, @SerializedName("events") val events: MutableList, diff --git a/library/src/main/java/com/paypal/messages/logger/TrackingPayload.kt b/library/src/main/java/com/paypal/messages/logger/TrackingPayload.kt index 41ea7d71..e5c07f8e 100644 --- a/library/src/main/java/com/paypal/messages/logger/TrackingPayload.kt +++ b/library/src/main/java/com/paypal/messages/logger/TrackingPayload.kt @@ -2,6 +2,7 @@ package com.paypal.messages.logger import com.google.gson.annotations.SerializedName import com.paypal.messages.BuildConfig +import java.util.UUID data class TrackingPayload( // Integration Details @@ -19,6 +20,8 @@ data class TrackingPayload( val deviceId: String, @SerializedName("session_id") val sessionId: String, + @SerializedName("instance_id") + val instanceId: String = UUID.randomUUID().toString(), @SerializedName("integration_name") val integrationName: String, @SerializedName("integration_type") From c32defe0f9b32700dc9cea836dc3cc0def835a1b Mon Sep 17 00:00:00 2001 From: merlinpaypal <124289716+merlinpaypal@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:19:24 -0400 Subject: [PATCH 04/37] feat: base of GitHub workflows (#5) --- .editorconfig | 5 ++ .github/workflows/build.yml | 22 ++++++ .github/workflows/lint.yml | 22 ++++++ .github/workflows/lintAndUnit.yml | 19 ----- .github/workflows/release.yml | 53 +++++++++++++ .github/workflows/test.yml | 28 +++++++ .idea/codeStyles/Project.xml | 4 + .idea/compiler.xml | 2 +- .idea/gradle.xml | 3 +- .idea/inspectionProfiles/Project_Default.xml | 11 +-- .idea/misc.xml | 3 +- demo/build.gradle | 25 +++--- .../messagesdemo/ExampleInstrumentedTest.kt | 6 +- .../java/com/paypal/messagesdemo/Dropdown.kt | 6 +- .../paypal/messagesdemo/JetpackActivity.kt | 6 +- .../com/paypal/messagesdemo/XmlActivity.kt | 18 ++--- .../java/com/paypal/messagesdemo/ui/Theme.kt | 8 +- .../java/com/paypal/messagesdemo/ui/Type.kt | 4 +- demo/src/main/res/values/colors.xml | 9 +-- .../paypal/messagesdemo/ExampleUnitTest.kt | 3 +- library/build.gradle | 5 +- .../messages/ExampleInstrumentedTest.kt | 6 +- .../src/main/java/com/paypal/messages/Logo.kt | 10 +-- .../java/com/paypal/messages/LogoAsset.kt | 8 +- .../java/com/paypal/messages/ModalFragment.kt | 42 +++++----- .../com/paypal/messages/PayPalMessageView.kt | 58 ++++++-------- .../com/paypal/messages/RoundedWebView.kt | 12 ++- .../com/paypal/messages/config/Channel.kt | 2 +- .../paypal/messages/config/CurrencyCode.kt | 2 +- .../messages/config/PayPalEnvironment.kt | 2 +- .../messages/config/PayPalMessageOfferType.kt | 7 +- .../paypal/messages/config/ProductGroup.kt | 2 +- .../config/message/PayPalMessageConfig.kt | 2 +- .../config/message/PayPalMessageData.kt | 2 +- .../config/message/PayPalMessageStyle.kt | 2 +- .../message/style/PayPalMessageAlign.kt | 7 +- .../message/style/PayPalMessageColor.kt | 7 +- .../message/style/PayPalMessageLogoType.kt | 7 +- .../paypal/messages/errors/BaseException.kt | 2 +- .../errors/FailedToFetchDataException.kt | 2 +- .../paypal/messages/errors/IllegalEnumArg.kt | 8 ++ .../errors/InvalidCheckoutConfigException.kt | 2 +- .../errors/InvalidClientIdException.kt | 2 +- .../errors/InvalidResponseException.kt | 3 +- .../messages/errors/ModalFailedToLoad.kt | 2 +- .../java/com/paypal/messages/io/Action.kt | 4 +- .../com/paypal/messages/io/ActionResponse.kt | 2 +- .../messages/io/ActionResponseMetadata.kt | 4 +- .../main/java/com/paypal/messages/io/Api.kt | 46 +++++------ .../java/com/paypal/messages/io/ApiResult.kt | 4 +- .../paypal/messages/io/HashActionResponse.kt | 2 +- .../com/paypal/messages/io/LocalStorage.kt | 10 ++- .../paypal/messages/logger/ComponentType.kt | 2 +- .../com/paypal/messages/logger/EventType.kt | 2 +- .../java/com/paypal/messages/logger/Logger.kt | 4 +- .../messages/logger/TrackingComponent.kt | 4 +- .../messages/utils/AccessibilityUtils.kt | 2 +- .../utils/IgnoreGeneratedTestReport.kt | 2 +- .../java/com/paypal/messages/utils/LogCat.kt | 4 +- ...createFormattedIllegalArgumentException.kt | 10 --- .../drawable/logo_alternative_monochrome.xml | 4 +- .../logo_credit_alternative_grayscale.xml | 24 ++++-- .../logo_credit_alternative_monochrome.xml | 36 +++++---- .../logo_credit_alternative_standard.xml | 20 ++--- .../logo_credit_alternative_white.xml | 4 +- .../drawable/logo_credit_inline_grayscale.xml | 52 ++++++------ .../logo_credit_inline_monochrome.xml | 54 ++++++++----- .../drawable/logo_credit_inline_standard.xml | 52 +++++++----- .../res/drawable/logo_credit_inline_white.xml | 47 ++++++++--- .../logo_credit_primary_grayscale.xml | 62 +++++++++++---- .../logo_credit_primary_monochrome.xml | 64 ++++++++++++--- .../drawable/logo_credit_primary_standard.xml | 77 +++++++++++------- .../drawable/logo_credit_primary_white.xml | 79 +++++++++++++------ .../res/drawable/logo_primary_grayscale.xml | 4 +- .../res/drawable/logo_primary_monochrome.xml | 8 +- .../res/drawable/logo_primary_standard.xml | 4 +- .../main/res/drawable/logo_primary_white.xml | 4 +- .../com/paypal/messages/ExampleUnitTest.kt | 3 +- 78 files changed, 735 insertions(+), 426 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/lintAndUnit.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml create mode 100644 library/src/main/java/com/paypal/messages/errors/IllegalEnumArg.kt delete mode 100644 library/src/main/java/com/paypal/messages/utils/createFormattedIllegalArgumentException.kt diff --git a/.editorconfig b/.editorconfig index 32090c01..15f3b768 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,3 +11,8 @@ indent_style = tab indent_size = 2 trim_trailing_whitespace = true insert_final_newline = true + +[*.{kt,kts}] +ktlint_code_style = ktlint_official +ktlint_standard_keyword-spacing = disabled +ktlint_standard_annotation = disabled diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..0a710c81 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,22 @@ +name: Build +on: [pull_request, workflow_dispatch] + +concurrency: + group: build-${{ github.event.number }} + cancel-in-progress: true + +jobs: + build: + name: Build + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: gradle diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..87fe9ef2 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,22 @@ +name: Lint +on: [pull_request, workflow_dispatch] + +concurrency: + group: lint-${{ github.event.number }} + cancel-in-progress: true + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: gradle diff --git a/.github/workflows/lintAndUnit.yml b/.github/workflows/lintAndUnit.yml deleted file mode 100644 index bdaa5770..00000000 --- a/.github/workflows/lintAndUnit.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Lint, Unit, Non-snapshot tests -on: - # allow for manual triggers - workflow_dispatch: {} - workflow_call: {} - push: - branches: - - develop - pull_request: {} - -jobs: - lintAndUnit: - name: Lint and Unit Tests - runs-on: ubuntu-latest - steps: - - name: Checkout repo - uses: actions/checkout@v3 - with: - persist-credentials: false diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..2e670c95 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,53 @@ +name: Release +on: + workflow_dispatch: {} + push: + branches: + - main + +jobs: + lint: + uses: paypal/paypal-messages-android/.github/workflows/lint.yml@release + + test: + uses: paypal/paypal-messages-android/.github/workflows/test.yml@release + + build: + uses: paypal/paypal-messages-android/.github/workflows/build.yml@release + + release: + name: Release + needs: [linting, tests, build] + runs-on: ubuntu-latest + + permissions: + contents: write + issues: write + pull-requests: write + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + with: + # pulls all commits (needed for semantic release to correctly version) + fetch-depth: '0' + persist-credentials: false + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: gradle + + - name: Install Dependencies + run: | + npm i -g @semantic-release/exec @semantic-release/changelog @semantic-release/git conventional-changelog-conventionalcommits@6.1.0 + + - name: GitHub Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: npx semantic-release@21 + + - name: Publish to Maven + run: echo "Publish to Maven" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..96385be3 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +name: Test +on: [pull_request, workflow_dispatch] + +concurrency: + group: test-${{ github.event.number }} + cancel-in-progress: true + +jobs: + test: + name: Test + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: gradle + + - name: Install Dependencies + run: echo "Install Dependencies" + + - name: Run Tests + run: echo "Run Tests" diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 540bc2e0..e781ca8b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -199,4 +199,8 @@ +<<<<<<< HEAD +======= + +>>>>>>> e6e59a442f9806007976190de9e1572555586c52 diff --git a/.idea/compiler.xml b/.idea/compiler.xml index d208d08e..b589d56e 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -3,4 +3,4 @@ - + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index ed4c5b1e..9714607e 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,6 +1,5 @@ - - + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index f72e9dab..23ff7fd0 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -1,9 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 188f6e32..6a28afd0 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,3 +1,4 @@ + @@ -11,4 +12,4 @@ - + \ No newline at end of file diff --git a/demo/build.gradle b/demo/build.gradle index 6fda4fa7..1471b913 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -1,6 +1,7 @@ plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' + id 'org.jmailen.kotlinter' } android { @@ -10,7 +11,7 @@ android { defaultConfig { applicationId "com.paypal.messagesdemo" minSdk 23 - targetSdk 33 + targetSdk 34 versionCode 1 versionName "1.0" @@ -59,15 +60,15 @@ android { } dependencies { - implementation 'androidx.core:core-ktx:1.10.1' + implementation 'androidx.core:core-ktx:1.12.0' implementation platform('org.jetbrains.kotlin:kotlin-bom:1.9.0') - implementation platform('androidx.compose:compose-bom:2023.06.01') - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1' + implementation platform('androidx.compose:compose-bom:2023.09.00') + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2' implementation 'androidx.activity:activity-compose:1.7.2' - implementation 'androidx.compose.ui:ui:1.5.0' - implementation 'androidx.compose.ui:ui-graphics:1.5.0' - implementation 'androidx.compose.ui:ui-tooling-preview:1.5.0' - implementation 'androidx.compose.material3:material3:1.1.1' + implementation 'androidx.compose.ui:ui:1.5.1' + implementation 'androidx.compose.ui:ui-graphics:1.5.1' + implementation 'androidx.compose.ui:ui-tooling-preview:1.5.1' + implementation 'androidx.compose.material3:material3:1.1.2' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.appcompat:appcompat:1.6.1' implementation project(':library') @@ -75,8 +76,8 @@ dependencies { testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' - androidTestImplementation platform('androidx.compose:compose-bom:2023.06.01') - androidTestImplementation 'androidx.compose.ui:ui-test-junit4:1.5.0' - debugImplementation 'androidx.compose.ui:ui-tooling:1.5.0' - debugImplementation 'androidx.compose.ui:ui-test-manifest:1.5.0' + androidTestImplementation platform('androidx.compose:compose-bom:2023.09.00') + androidTestImplementation 'androidx.compose.ui:ui-test-junit4:1.5.1' + debugImplementation 'androidx.compose.ui:ui-tooling:1.5.1' + debugImplementation 'androidx.compose.ui:ui-test-manifest:1.5.1' } diff --git a/demo/src/androidTest/java/com/paypal/messagesdemo/ExampleInstrumentedTest.kt b/demo/src/androidTest/java/com/paypal/messagesdemo/ExampleInstrumentedTest.kt index 1c9151e4..778da867 100644 --- a/demo/src/androidTest/java/com/paypal/messagesdemo/ExampleInstrumentedTest.kt +++ b/demo/src/androidTest/java/com/paypal/messagesdemo/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package com.paypal.messagesdemo -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * diff --git a/demo/src/main/java/com/paypal/messagesdemo/Dropdown.kt b/demo/src/main/java/com/paypal/messagesdemo/Dropdown.kt index a91a0961..599bfb7d 100644 --- a/demo/src/main/java/com/paypal/messagesdemo/Dropdown.kt +++ b/demo/src/main/java/com/paypal/messagesdemo/Dropdown.kt @@ -23,14 +23,14 @@ fun Dropdown(label: String, value: T, options: Array, onValueChange: (T) Button( onClick = { expanded = !expanded }, shape = RectangleShape, - modifier = Modifier.width(200.dp) + modifier = Modifier.width(200.dp), ) { Text("$label: $value") } DropdownMenu( expanded = expanded, onDismissRequest = { expanded = false }, - modifier = Modifier.width(200.dp) + modifier = Modifier.width(200.dp), ) { options.forEach { option -> DropdownMenuItem( @@ -38,7 +38,7 @@ fun Dropdown(label: String, value: T, options: Array, onValueChange: (T) onClick = { onValueChange(option) expanded = false - } + }, ) } } diff --git a/demo/src/main/java/com/paypal/messagesdemo/JetpackActivity.kt b/demo/src/main/java/com/paypal/messagesdemo/JetpackActivity.kt index 6e891213..53cfe343 100644 --- a/demo/src/main/java/com/paypal/messagesdemo/JetpackActivity.kt +++ b/demo/src/main/java/com/paypal/messagesdemo/JetpackActivity.kt @@ -18,13 +18,13 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp -import com.paypal.messagesdemo.ui.BasicTheme import com.paypal.messages.Logo import com.paypal.messages.LogoAsset +import com.paypal.messages.PayPalMessageView +import com.paypal.messages.config.ProductGroup import com.paypal.messages.config.message.style.PayPalMessageColor import com.paypal.messages.config.message.style.PayPalMessageLogoType -import com.paypal.messages.config.ProductGroup -import com.paypal.messages.PayPalMessageView +import com.paypal.messagesdemo.ui.BasicTheme class JetpackActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { diff --git a/demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt b/demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt index 2cdab207..7b4362bd 100644 --- a/demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt +++ b/demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt @@ -6,19 +6,19 @@ import android.view.View import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import com.paypal.messages.PayPalMessageView -import com.paypal.messages.config.PayPalEnvironment as Environment -import com.paypal.messages.config.message.style.PayPalMessageAlign -import com.paypal.messages.config.message.style.PayPalMessageColor -import com.paypal.messages.config.message.style.PayPalMessageLogoType import com.paypal.messages.config.PayPalMessageOfferType import com.paypal.messages.config.message.PayPalMessageConfig import com.paypal.messages.config.message.PayPalMessageData import com.paypal.messages.config.message.PayPalMessageEvents import com.paypal.messages.config.message.PayPalMessageStyle import com.paypal.messages.config.message.PayPalMessageViewState +import com.paypal.messages.config.message.style.PayPalMessageAlign +import com.paypal.messages.config.message.style.PayPalMessageColor +import com.paypal.messages.config.message.style.PayPalMessageLogoType import com.paypal.messagesdemo.databinding.ActivityMessageBinding +import com.paypal.messages.config.PayPalEnvironment as Environment -class XmlActivity: AppCompatActivity() { +class XmlActivity : AppCompatActivity() { private lateinit var binding: ActivityMessageBinding private val TAG = "XmlActivity" @@ -39,14 +39,14 @@ class XmlActivity: AppCompatActivity() { Log.d(TAG, "onLoading") progressBar.visibility = View.VISIBLE reloadButton.isEnabled = false - Toast.makeText(this, "Loading Content...",Toast.LENGTH_SHORT).show() + Toast.makeText(this, "Loading Content...", Toast.LENGTH_SHORT).show() }, onError = { Log.d(TAG, "onError") progressBar.visibility = View.INVISIBLE runOnUiThread { reloadButton.isEnabled = true - Toast.makeText(this, it.javaClass.toString() + ":" + it.message + ":" + it.paypalDebugId,Toast.LENGTH_LONG).show() + Toast.makeText(this, it.javaClass.toString() + ":" + it.message + ":" + it.paypalDebugId, Toast.LENGTH_LONG).show() } it.message?.let { it1 -> Log.d("XmlActivity Error", it1) } it.paypalDebugId?.let { it1 -> Log.d("XmlActivity Error", it1) } @@ -58,8 +58,8 @@ class XmlActivity: AppCompatActivity() { reloadButton.isEnabled = true Toast.makeText(this, "Success Getting Content", Toast.LENGTH_SHORT).show() } - } - ) + }, + ), ) } diff --git a/demo/src/main/java/com/paypal/messagesdemo/ui/Theme.kt b/demo/src/main/java/com/paypal/messagesdemo/ui/Theme.kt index ec76f2aa..fc4bb252 100644 --- a/demo/src/main/java/com/paypal/messagesdemo/ui/Theme.kt +++ b/demo/src/main/java/com/paypal/messagesdemo/ui/Theme.kt @@ -18,13 +18,13 @@ import androidx.core.view.WindowCompat private val DarkColorScheme = darkColorScheme( primary = Purple80, secondary = PurpleGrey80, - tertiary = Pink80 + tertiary = Pink80, ) private val LightColorScheme = lightColorScheme( primary = Purple40, secondary = PurpleGrey40, - tertiary = Pink40 + tertiary = Pink40, /* Other default colors to override background = Color(0xFFFFFBFE), @@ -34,7 +34,7 @@ private val LightColorScheme = lightColorScheme( onTertiary = Color.White, onBackground = Color(0xFF1C1B1F), onSurface = Color(0xFF1C1B1F), - */ + */ ) @Composable @@ -65,6 +65,6 @@ fun BasicTheme( MaterialTheme( colorScheme = colorScheme, typography = Typography, - content = content + content = content, ) } diff --git a/demo/src/main/java/com/paypal/messagesdemo/ui/Type.kt b/demo/src/main/java/com/paypal/messagesdemo/ui/Type.kt index 86753b28..2b123f11 100644 --- a/demo/src/main/java/com/paypal/messagesdemo/ui/Type.kt +++ b/demo/src/main/java/com/paypal/messagesdemo/ui/Type.kt @@ -29,6 +29,6 @@ val Typography = Typography( fontWeight = FontWeight.Normal, fontSize = 16.sp, lineHeight = 24.sp, - letterSpacing = 0.5.sp - ) + letterSpacing = 0.5.sp, + ), ) diff --git a/demo/src/main/res/values/colors.xml b/demo/src/main/res/values/colors.xml index d95bf93e..045e125f 100644 --- a/demo/src/main/res/values/colors.xml +++ b/demo/src/main/res/values/colors.xml @@ -1,10 +1,3 @@ - #FFBB86FC - #FF6200EE - #FF3700B3 - #FF03DAC5 - #FF018786 - #FF000000 - #FFFFFFFF - \ No newline at end of file + diff --git a/demo/src/test/java/com/paypal/messagesdemo/ExampleUnitTest.kt b/demo/src/test/java/com/paypal/messagesdemo/ExampleUnitTest.kt index 8030bc08..befc85a0 100644 --- a/demo/src/test/java/com/paypal/messagesdemo/ExampleUnitTest.kt +++ b/demo/src/test/java/com/paypal/messagesdemo/ExampleUnitTest.kt @@ -1,9 +1,8 @@ package com.paypal.messagesdemo +import org.junit.Assert.assertEquals import org.junit.Test -import org.junit.Assert.* - /** * Example local unit test, which will execute on the development machine (host). * diff --git a/library/build.gradle b/library/build.gradle index 01c90ecb..5ec13d91 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,6 +1,7 @@ plugins { id 'com.android.library' id 'org.jetbrains.kotlin.android' + id 'org.jmailen.kotlinter' } android { @@ -9,7 +10,7 @@ android { defaultConfig { minSdk 23 - targetSdk 33 + targetSdk 34 versionCode 10000 versionName "1.0.0" @@ -42,7 +43,7 @@ android { } dependencies { - implementation 'androidx.core:core-ktx:1.10.1' + implementation 'androidx.core:core-ktx:1.12.0' implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'com.google.android.material:material:1.9.0' implementation 'com.google.code.gson:gson:2.8.9' diff --git a/library/src/androidTest/java/com/paypal/messages/ExampleInstrumentedTest.kt b/library/src/androidTest/java/com/paypal/messages/ExampleInstrumentedTest.kt index 5f7185ef..9c2697fd 100644 --- a/library/src/androidTest/java/com/paypal/messages/ExampleInstrumentedTest.kt +++ b/library/src/androidTest/java/com/paypal/messages/ExampleInstrumentedTest.kt @@ -1,13 +1,11 @@ package com.paypal.messages -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 - +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * diff --git a/library/src/main/java/com/paypal/messages/Logo.kt b/library/src/main/java/com/paypal/messages/Logo.kt index f2922631..e0fffb0d 100644 --- a/library/src/main/java/com/paypal/messages/Logo.kt +++ b/library/src/main/java/com/paypal/messages/Logo.kt @@ -1,8 +1,8 @@ package com.paypal.messages +import com.paypal.messages.config.ProductGroup import com.paypal.messages.config.message.style.PayPalMessageColor import com.paypal.messages.config.message.style.PayPalMessageLogoType -import com.paypal.messages.config.ProductGroup class Logo( private val logoType: PayPalMessageLogoType = PayPalMessageLogoType.PRIMARY, @@ -26,7 +26,7 @@ class Logo( PayPalMessageColor.MONOCHROME -> R.drawable.logo_primary_monochrome PayPalMessageColor.GRAYSCALE -> R.drawable.logo_primary_grayscale } - } + }, ) } @@ -46,7 +46,7 @@ class Logo( PayPalMessageColor.MONOCHROME -> R.drawable.logo_alternative_monochrome PayPalMessageColor.GRAYSCALE -> R.drawable.logo_alternative_grayscale } - } + }, ) } @@ -66,7 +66,7 @@ class Logo( PayPalMessageColor.MONOCHROME -> R.drawable.logo_inline_monochrome PayPalMessageColor.GRAYSCALE -> R.drawable.logo_inline_grayscale } - } + }, ) } @@ -75,7 +75,7 @@ class Logo( when (productGroup) { ProductGroup.PAYPAL_CREDIT -> R.string.logo_none_label_credit else -> R.string.logo_none_label_default - } + }, ) } } diff --git a/library/src/main/java/com/paypal/messages/LogoAsset.kt b/library/src/main/java/com/paypal/messages/LogoAsset.kt index a7cab26b..f8454f58 100644 --- a/library/src/main/java/com/paypal/messages/LogoAsset.kt +++ b/library/src/main/java/com/paypal/messages/LogoAsset.kt @@ -7,10 +7,14 @@ sealed class LogoAsset { /** * [StringAsset] is a representation of a [LogoAsset] that holds a StringRes resourceId */ - data class StringAsset(@StringRes val resId: Int) : LogoAsset() + data class StringAsset( + @StringRes val resId: Int, + ) : LogoAsset() /** * [ImageAsset] is a representation of a [LogoAsset] that holds a DrawableRes resourceId */ - data class ImageAsset(@DrawableRes val resId: Int) : LogoAsset() + data class ImageAsset( + @DrawableRes val resId: Int, + ) : LogoAsset() } diff --git a/library/src/main/java/com/paypal/messages/ModalFragment.kt b/library/src/main/java/com/paypal/messages/ModalFragment.kt index 52f92bd2..dc10af63 100644 --- a/library/src/main/java/com/paypal/messages/ModalFragment.kt +++ b/library/src/main/java/com/paypal/messages/ModalFragment.kt @@ -8,7 +8,6 @@ import android.graphics.PorterDuff import android.graphics.PorterDuffColorFilter import android.net.Uri import android.net.http.SslError -import android.os.Build import android.os.Bundle import android.util.TypedValue import android.view.LayoutInflater @@ -26,19 +25,18 @@ import android.webkit.WebViewClient import android.widget.ImageButton import android.widget.ProgressBar import android.widget.RelativeLayout -import androidx.annotation.RequiresApi import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.google.gson.JsonElement import com.google.gson.JsonParser import com.paypal.messages.config.Channel +import com.paypal.messages.config.modal.ModalCloseButton import com.paypal.messages.config.modal.ModalConfig import com.paypal.messages.errors.BaseException import com.paypal.messages.errors.ModalFailedToLoad import com.paypal.messages.extensions.dp import com.paypal.messages.io.Api -import com.paypal.messages.config.modal.ModalCloseButton import com.paypal.messages.logger.ComponentType import com.paypal.messages.logger.EventType import com.paypal.messages.logger.Logger @@ -50,10 +48,9 @@ import java.util.UUID import kotlin.system.measureTimeMillis import com.paypal.messages.config.PayPalMessageOfferType as OfferType -@RequiresApi(Build.VERSION_CODES.M) internal class ModalFragment constructor( private val clientId: String, -): BottomSheetDialogFragment() { +) : BottomSheetDialogFragment() { private val TAG = "PayPalMessageModal" private val offsetTop = 50.dp @@ -122,11 +119,11 @@ internal class ModalFragment constructor( closeButton.layoutParams.height = TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, - this.closeButtonData?.height!!.toFloat(), resources.displayMetrics + this.closeButtonData?.height!!.toFloat(), resources.displayMetrics, ).toInt() closeButton.layoutParams.width = TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, - this.closeButtonData?.width!!.toFloat(), resources.displayMetrics + this.closeButtonData?.width!!.toFloat(), resources.displayMetrics, ).toInt() val colorInt = Color.parseColor(this.closeButtonData?.color) @@ -310,7 +307,7 @@ internal class ModalFragment constructor( eventType = EventType.MODAL_ERROR, errorName = errorName, errorDescription = errorDescription, - ) + ), ) } @@ -330,7 +327,7 @@ internal class ModalFragment constructor( eventType = EventType.MODAL_ERROR, errorName = errorName, errorDescription = errorDescription, - ) + ), ) } @@ -352,7 +349,7 @@ internal class ModalFragment constructor( this.onLoading() val url = Api.createModalUrl(clientId, amount, buyerCountry, offer) - LogCat.debug(TAG, "Start show process for modal with webView: ${webView.toString()}") + LogCat.debug(TAG, "Start show process for modal with webView: $webView") val requestDuration = measureTimeMillis { if (inErrorState) { LogCat.debug(TAG, "Modal had error, resetting state and reloading WebView with URL: $url") @@ -379,8 +376,8 @@ internal class ModalFragment constructor( TrackingEvent( eventType = EventType.MODAL_RENDER, renderDuration, - requestDuration - ) + requestDuration, + ), ) } @@ -410,8 +407,9 @@ internal class ModalFragment constructor( TrackingEvent( eventType = EventType.MODAL_CLICK, linkSrc = linkSrc, - linkName = linkName - ), shared + linkName = linkName, + ), + shared, ) } @@ -421,8 +419,9 @@ internal class ModalFragment constructor( logEvent( TrackingEvent( eventType = EventType.MODAL_CLICK, - data = "$calculatorAmount" - ), shared + data = "$calculatorAmount", + ), + shared, ) } @@ -450,12 +449,15 @@ internal class ModalFragment constructor( return when { jsonElement.isJsonPrimitive -> { val jsonPrimitive = jsonElement.asJsonPrimitive - if (jsonPrimitive.isBoolean) + if (jsonPrimitive.isBoolean) { jsonPrimitive.asBoolean - else if (jsonPrimitive.isNumber) + } + else if (jsonPrimitive.isNumber) { jsonPrimitive.asNumber - else + } + else { jsonPrimitive.asString + } } jsonElement.isJsonObject -> jsonElementToMutableMap(jsonElement) @@ -482,7 +484,7 @@ internal class ModalFragment constructor( type = ComponentType.MODAL.toString(), instanceId = this.instanceId.toString(), events = mutableListOf(event), - __shared__ = dynamicKeys + __shared__ = dynamicKeys, ) context?.let { Logger.getInstance(clientId = clientId).log(it, component) } diff --git a/library/src/main/java/com/paypal/messages/PayPalMessageView.kt b/library/src/main/java/com/paypal/messages/PayPalMessageView.kt index fd5f7989..76f4926e 100644 --- a/library/src/main/java/com/paypal/messages/PayPalMessageView.kt +++ b/library/src/main/java/com/paypal/messages/PayPalMessageView.kt @@ -2,10 +2,8 @@ package com.paypal.messages import android.content.Context import android.content.res.TypedArray -import android.os.Build import android.text.Spannable import android.text.SpannableStringBuilder -import android.text.style.DynamicDrawableSpan import android.text.style.ForegroundColorSpan import android.text.style.ImageSpan import android.text.style.StyleSpan @@ -16,7 +14,6 @@ import android.view.LayoutInflater import android.view.View import android.widget.LinearLayout import android.widget.TextView -import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import androidx.core.content.res.getFloatOrThrow @@ -42,15 +39,15 @@ import com.paypal.messages.logger.TrackingEvent import com.paypal.messages.utils.LogCat import java.util.UUID import kotlin.system.measureTimeMillis -import com.paypal.messages.config.message.style.PayPalMessageAlign as Align -import com.paypal.messages.config.message.style.PayPalMessageColor as Color -import com.paypal.messages.config.message.style.PayPalMessageLogoType as LogoType import com.paypal.messages.config.PayPalMessageOfferType as OfferType import com.paypal.messages.config.message.PayPalMessageConfig as MessageConfig import com.paypal.messages.config.message.PayPalMessageData as MessageData import com.paypal.messages.config.message.PayPalMessageEvents as MessageEvents import com.paypal.messages.config.message.PayPalMessageStyle as MessageStyle import com.paypal.messages.config.message.PayPalMessageViewState as MessageViewState +import com.paypal.messages.config.message.style.PayPalMessageAlign as Align +import com.paypal.messages.config.message.style.PayPalMessageColor as Color +import com.paypal.messages.config.message.style.PayPalMessageLogoType as LogoType /** * PayPalMessage is a component that provides the merchant with a message about different pay later @@ -58,7 +55,6 @@ import com.paypal.messages.config.message.PayPalMessageViewState as MessageViewS * be displayed in different styles. Interacting with this component will show more information about the * product itself and the option to apply */ -@RequiresApi(Build.VERSION_CODES.M) class PayPalMessageView @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, @@ -81,7 +77,6 @@ class PayPalMessageView @JvmOverloads constructor( private var logoType: LogoType = LogoType.PRIMARY private var alignment: Align = Align.LEFT - // Full Message Data private var data: ActionResponse? = null @@ -95,7 +90,7 @@ class PayPalMessageView @JvmOverloads constructor( private var modal: ModalFragment? = null // Stats - private var requestDuration : Int? = null + private var requestDuration: Int? = null /** * Updates the onLoading callback used in [MessageConfig] for the current [PayPalMessageView]. @@ -141,7 +136,7 @@ class PayPalMessageView @JvmOverloads constructor( updateFromAttributes(typedArray) } config?.let { updateFromConfig(it) } - Api.sessionId = UUID.randomUUID(); + Api.sessionId = UUID.randomUUID() updateMessageContent() } @@ -325,7 +320,6 @@ class PayPalMessageView @JvmOverloads constructor( } private fun showWebView(response: ActionResponse) { - val modal = modal ?: run { val modal = ModalFragment(clientId) // Build modal config @@ -342,7 +336,7 @@ class PayPalMessageView @JvmOverloads constructor( onClick = onClick, onError = onError, ), - modalCloseButton = this.data?.meta?.modalCloseButton!! + modalCloseButton = this.data?.meta?.modalCloseButton!!, ) modal.init(modalConfig) @@ -399,7 +393,6 @@ class PayPalMessageView @JvmOverloads constructor( text = builder } } - } /** @@ -448,8 +441,8 @@ class PayPalMessageView @JvmOverloads constructor( color = PayPalMessageColor( typedArray.getInt( R.styleable.PayPalMessageView_paypal_text_color, - Color.BLACK.value - ) + Color.BLACK.value, + ), ) } @@ -457,8 +450,8 @@ class PayPalMessageView @JvmOverloads constructor( logoType = PayPalMessageLogoType( typedArray.getInt( R.styleable.PayPalMessageView_paypal_logo_type, - LogoType.PRIMARY.value - ) + LogoType.PRIMARY.value, + ), ) } @@ -466,8 +459,8 @@ class PayPalMessageView @JvmOverloads constructor( alignment = PayPalMessageAlign( typedArray.getInt( R.styleable.PayPalMessageView_paypal_text_align, - Align.LEFT.value - ) + Align.LEFT.value, + ), ) } } @@ -510,7 +503,7 @@ class PayPalMessageView @JvmOverloads constructor( */ private fun updateMessageContent() { if (!updateInProgress) { - Api.instanceId = UUID.randomUUID(); + Api.instanceId = UUID.randomUUID() // Call OnLoading callback and prepare view for the process onLoading.invoke() @@ -524,9 +517,9 @@ class PayPalMessageView @JvmOverloads constructor( action.execute( MessageConfig( MessageData(clientId, amount, placement, offerType, buyerCountry, currencyCode), - MessageStyle(logoType, color, alignment) + MessageStyle(logoType, color, alignment), ), - this + this, ) }.toInt() } @@ -548,10 +541,9 @@ class PayPalMessageView @JvmOverloads constructor( TrackingEvent( eventType = EventType.MESSAGE_RENDER, renderDuration, - requestDuration - ) + requestDuration, + ), ) - } is ApiResult.Failure<*> -> { @@ -580,7 +572,7 @@ class PayPalMessageView @JvmOverloads constructor( eventType = EventType.MESSAGE_CLICK, linkName = "banner_wrapper", linkSrc = "message", - ) + ), ) showWebView(response) } @@ -605,7 +597,7 @@ class PayPalMessageView @JvmOverloads constructor( logoTag?.let { tag -> if (logoType in listOf( LogoType.PRIMARY, - LogoType.ALTERNATIVE + LogoType.ALTERNATIVE, ) && !content.contains(tag) ) { builder.append("$tag ") @@ -641,7 +633,7 @@ class PayPalMessageView @JvmOverloads constructor( StyleSpan(android.graphics.Typeface.BOLD), logoIndex, logoIndex + logoString.length, - Spannable.SPAN_INCLUSIVE_INCLUSIVE + Spannable.SPAN_INCLUSIVE_INCLUSIVE, ) } @@ -650,11 +642,12 @@ class PayPalMessageView @JvmOverloads constructor( val width = lineHeight * logoDrawable.intrinsicWidth / logoDrawable.intrinsicHeight logoDrawable.setBounds(0, 0, width, lineHeight) + val alignCenter = 2 setSpan( - ImageSpan(logoDrawable, DynamicDrawableSpan.ALIGN_CENTER), + ImageSpan(logoDrawable, alignCenter), logoIndex, logoIndex + logoTag.length, - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE, ) } } @@ -677,18 +670,17 @@ class PayPalMessageView @JvmOverloads constructor( ForegroundColorSpan(ContextCompat.getColor(context, R.color.blue_600)), disclaimerIndex, disclaimerIndex + disclaimer.length, - Spannable.SPAN_INCLUSIVE_INCLUSIVE + Spannable.SPAN_INCLUSIVE_INCLUSIVE, ) } setSpan( UnderlineSpan(), disclaimerIndex, disclaimerIndex + disclaimer.length, - Spannable.SPAN_INCLUSIVE_INCLUSIVE + Spannable.SPAN_INCLUSIVE_INCLUSIVE, ) } - private fun logEvent(event: TrackingEvent) { // Build component Information val component = TrackingComponent( diff --git a/library/src/main/java/com/paypal/messages/RoundedWebView.kt b/library/src/main/java/com/paypal/messages/RoundedWebView.kt index 0cd7eea8..f6fdd5f0 100644 --- a/library/src/main/java/com/paypal/messages/RoundedWebView.kt +++ b/library/src/main/java/com/paypal/messages/RoundedWebView.kt @@ -6,13 +6,17 @@ import android.graphics.Path import android.util.AttributeSet import android.webkit.WebView -internal class RoundedWebView: WebView { +internal class RoundedWebView : WebView { private var radius: Int = 50 private var path: Path = Path() - constructor(context: Context): super(context) - constructor(context: Context, attrs: AttributeSet): super(context, attrs) - constructor(context: Context, attrs: AttributeSet, defStyle: Int): super(context, attrs, defStyle) + constructor(context: Context) : super(context) + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) + constructor( + context: Context, + attrs: AttributeSet, + defStyle: Int, + ) : super(context, attrs, defStyle) override fun onSizeChanged(width: Int, height: Int, oldWidth: Int, oldHeight: Int) { super.onSizeChanged(width, height, oldWidth, oldHeight) diff --git a/library/src/main/java/com/paypal/messages/config/Channel.kt b/library/src/main/java/com/paypal/messages/config/Channel.kt index e35452cf..ce3ea87a 100644 --- a/library/src/main/java/com/paypal/messages/config/Channel.kt +++ b/library/src/main/java/com/paypal/messages/config/Channel.kt @@ -1,5 +1,5 @@ package com.paypal.messages.config enum class Channel { - NATIVE + NATIVE, } diff --git a/library/src/main/java/com/paypal/messages/config/CurrencyCode.kt b/library/src/main/java/com/paypal/messages/config/CurrencyCode.kt index 81c5389d..88f6260e 100644 --- a/library/src/main/java/com/paypal/messages/config/CurrencyCode.kt +++ b/library/src/main/java/com/paypal/messages/config/CurrencyCode.kt @@ -32,5 +32,5 @@ enum class CurrencyCode { * Countries using this: US (United States) * Symbol: $ */ - USD + USD, } diff --git a/library/src/main/java/com/paypal/messages/config/PayPalEnvironment.kt b/library/src/main/java/com/paypal/messages/config/PayPalEnvironment.kt index f15b8484..7e01a2de 100644 --- a/library/src/main/java/com/paypal/messages/config/PayPalEnvironment.kt +++ b/library/src/main/java/com/paypal/messages/config/PayPalEnvironment.kt @@ -5,5 +5,5 @@ enum class PayPalEnvironment { SANDBOX, STAGE, STAGE_VPN, - LOCAL; + LOCAL, } diff --git a/library/src/main/java/com/paypal/messages/config/PayPalMessageOfferType.kt b/library/src/main/java/com/paypal/messages/config/PayPalMessageOfferType.kt index 881e2e34..a23e2504 100644 --- a/library/src/main/java/com/paypal/messages/config/PayPalMessageOfferType.kt +++ b/library/src/main/java/com/paypal/messages/config/PayPalMessageOfferType.kt @@ -1,6 +1,6 @@ package com.paypal.messages.config -import com.paypal.messages.utils.createFormattedIllegalArgumentException +import com.paypal.messages.errors.IllegalEnumArg /** * [PayPalMessageOfferType] provides different variations of OfferTypes supported by the PayPalMessage component @@ -11,7 +11,8 @@ enum class PayPalMessageOfferType(val value: Int) { PAY_LATER_SHORT_TERM(0), PAY_LATER_LONG_TERM(1), PAY_LATER_PAY_IN_1(2), - PAYPAL_CREDIT_NO_INTEREST(3); + PAYPAL_CREDIT_NO_INTEREST(3), + ; companion object { /** @@ -26,7 +27,7 @@ enum class PayPalMessageOfferType(val value: Int) { PAY_LATER_LONG_TERM.value -> PAY_LATER_LONG_TERM PAY_LATER_PAY_IN_1.value -> PAY_LATER_PAY_IN_1 PAYPAL_CREDIT_NO_INTEREST.value -> PAYPAL_CREDIT_NO_INTEREST - else -> throw createFormattedIllegalArgumentException("OfferType", 3) + else -> throw IllegalEnumArg("OfferType", 3) } } } diff --git a/library/src/main/java/com/paypal/messages/config/ProductGroup.kt b/library/src/main/java/com/paypal/messages/config/ProductGroup.kt index 9f2c1ff9..9810bc80 100644 --- a/library/src/main/java/com/paypal/messages/config/ProductGroup.kt +++ b/library/src/main/java/com/paypal/messages/config/ProductGroup.kt @@ -2,5 +2,5 @@ package com.paypal.messages.config enum class ProductGroup { PAY_LATER, - PAYPAL_CREDIT + PAYPAL_CREDIT, } diff --git a/library/src/main/java/com/paypal/messages/config/message/PayPalMessageConfig.kt b/library/src/main/java/com/paypal/messages/config/message/PayPalMessageConfig.kt index 836f32d0..8c789bbe 100644 --- a/library/src/main/java/com/paypal/messages/config/message/PayPalMessageConfig.kt +++ b/library/src/main/java/com/paypal/messages/config/message/PayPalMessageConfig.kt @@ -15,7 +15,7 @@ data class PayPalMessageConfig( var viewState: PayPalMessageViewState? = null, var events: PayPalMessageEvents? = null, ) { - fun setGlobalAnalytics ( + fun setGlobalAnalytics( integrationName: String, integrationVersion: String, ) { diff --git a/library/src/main/java/com/paypal/messages/config/message/PayPalMessageData.kt b/library/src/main/java/com/paypal/messages/config/message/PayPalMessageData.kt index fa493c8b..6d1c344a 100644 --- a/library/src/main/java/com/paypal/messages/config/message/PayPalMessageData.kt +++ b/library/src/main/java/com/paypal/messages/config/message/PayPalMessageData.kt @@ -1,9 +1,9 @@ package com.paypal.messages.config.message import com.paypal.messages.config.CurrencyCode -import com.paypal.messages.config.PayPalEnvironment as Environment import com.paypal.messages.config.PayPalMessageOfferType import com.paypal.messages.io.Api +import com.paypal.messages.config.PayPalEnvironment as Environment /** * [PayPalMessageData] holds data used to determine the content of a PayPalMessage component diff --git a/library/src/main/java/com/paypal/messages/config/message/PayPalMessageStyle.kt b/library/src/main/java/com/paypal/messages/config/message/PayPalMessageStyle.kt index 6ef5d725..52bdc275 100644 --- a/library/src/main/java/com/paypal/messages/config/message/PayPalMessageStyle.kt +++ b/library/src/main/java/com/paypal/messages/config/message/PayPalMessageStyle.kt @@ -1,7 +1,7 @@ package com.paypal.messages.config.message -import com.paypal.messages.config.message.style.PayPalMessageColor import com.paypal.messages.config.message.style.PayPalMessageAlign +import com.paypal.messages.config.message.style.PayPalMessageColor import com.paypal.messages.config.message.style.PayPalMessageLogoType /** diff --git a/library/src/main/java/com/paypal/messages/config/message/style/PayPalMessageAlign.kt b/library/src/main/java/com/paypal/messages/config/message/style/PayPalMessageAlign.kt index f8a6377f..f7119822 100644 --- a/library/src/main/java/com/paypal/messages/config/message/style/PayPalMessageAlign.kt +++ b/library/src/main/java/com/paypal/messages/config/message/style/PayPalMessageAlign.kt @@ -1,6 +1,6 @@ package com.paypal.messages.config.message.style -import com.paypal.messages.utils.createFormattedIllegalArgumentException +import com.paypal.messages.errors.IllegalEnumArg /** * [PayPalMessageAlign] provides different variations of text alignments supported by the PayPalMessage component @@ -10,7 +10,8 @@ import com.paypal.messages.utils.createFormattedIllegalArgumentException enum class PayPalMessageAlign(val value: Int) { LEFT(0), CENTER(1), - RIGHT(2); + RIGHT(2), + ; companion object { /** @@ -24,7 +25,7 @@ enum class PayPalMessageAlign(val value: Int) { LEFT.value -> LEFT CENTER.value -> CENTER RIGHT.value -> RIGHT - else -> throw createFormattedIllegalArgumentException("LogoAlignment", 3) + else -> throw IllegalEnumArg("LogoAlignment", 3) } } } diff --git a/library/src/main/java/com/paypal/messages/config/message/style/PayPalMessageColor.kt b/library/src/main/java/com/paypal/messages/config/message/style/PayPalMessageColor.kt index a426fc46..64ba9cae 100644 --- a/library/src/main/java/com/paypal/messages/config/message/style/PayPalMessageColor.kt +++ b/library/src/main/java/com/paypal/messages/config/message/style/PayPalMessageColor.kt @@ -1,7 +1,7 @@ package com.paypal.messages.config.message.style import com.paypal.messages.R -import com.paypal.messages.utils.createFormattedIllegalArgumentException +import com.paypal.messages.errors.IllegalEnumArg /** * [PayPalMessageColor] provides different variations of colors supported by the PayPalMessage component @@ -15,7 +15,8 @@ enum class PayPalMessageColor( BLACK(value = 0, colorResId = R.color.gray_700), WHITE(value = 1, colorResId = R.color.white), MONOCHROME(value = 2, colorResId = R.color.black), - GRAYSCALE(value = 3, colorResId = R.color.gray_700); + GRAYSCALE(value = 3, colorResId = R.color.gray_700), + ; companion object { /** @@ -30,7 +31,7 @@ enum class PayPalMessageColor( WHITE.value -> WHITE MONOCHROME.value -> MONOCHROME GRAYSCALE.value -> GRAYSCALE - else -> throw createFormattedIllegalArgumentException("Color", 4) + else -> throw IllegalEnumArg("Color", 4) } } } diff --git a/library/src/main/java/com/paypal/messages/config/message/style/PayPalMessageLogoType.kt b/library/src/main/java/com/paypal/messages/config/message/style/PayPalMessageLogoType.kt index 666acd73..4dc92268 100644 --- a/library/src/main/java/com/paypal/messages/config/message/style/PayPalMessageLogoType.kt +++ b/library/src/main/java/com/paypal/messages/config/message/style/PayPalMessageLogoType.kt @@ -1,6 +1,6 @@ package com.paypal.messages.config.message.style -import com.paypal.messages.utils.createFormattedIllegalArgumentException +import com.paypal.messages.errors.IllegalEnumArg /** * [PayPalMessageLogoType] provides different variations of LogoTypes supported by the PayPalMessage component @@ -11,7 +11,8 @@ enum class PayPalMessageLogoType(val value: Int) { PRIMARY(0), ALTERNATIVE(1), INLINE(2), - NONE(3); + NONE(3), + ; companion object { /** @@ -26,7 +27,7 @@ enum class PayPalMessageLogoType(val value: Int) { ALTERNATIVE.value -> ALTERNATIVE INLINE.value -> INLINE NONE.value -> NONE - else -> throw createFormattedIllegalArgumentException("LogoType", 4) + else -> throw IllegalEnumArg("LogoType", 4) } } } diff --git a/library/src/main/java/com/paypal/messages/errors/BaseException.kt b/library/src/main/java/com/paypal/messages/errors/BaseException.kt index 0b920458..4db437d5 100644 --- a/library/src/main/java/com/paypal/messages/errors/BaseException.kt +++ b/library/src/main/java/com/paypal/messages/errors/BaseException.kt @@ -1,4 +1,4 @@ package com.paypal.messages.errors -open class BaseException(message: String, var paypalDebugId: String?): +open class BaseException(message: String, var paypalDebugId: String?) : Exception("PayPalMessageException: $message") diff --git a/library/src/main/java/com/paypal/messages/errors/FailedToFetchDataException.kt b/library/src/main/java/com/paypal/messages/errors/FailedToFetchDataException.kt index 3a262806..ad13885b 100644 --- a/library/src/main/java/com/paypal/messages/errors/FailedToFetchDataException.kt +++ b/library/src/main/java/com/paypal/messages/errors/FailedToFetchDataException.kt @@ -1,3 +1,3 @@ package com.paypal.messages.errors -class FailedToFetchDataException: BaseException("Failed to get Message Data", null) +class FailedToFetchDataException : BaseException("Failed to get Message Data", null) diff --git a/library/src/main/java/com/paypal/messages/errors/IllegalEnumArg.kt b/library/src/main/java/com/paypal/messages/errors/IllegalEnumArg.kt new file mode 100644 index 00000000..df0ffa53 --- /dev/null +++ b/library/src/main/java/com/paypal/messages/errors/IllegalEnumArg.kt @@ -0,0 +1,8 @@ +package com.paypal.messages.errors + +class IllegalEnumArg(enumName: String, enumValues: Int) : + BaseException( + "PayPalMessage Attempted to create a $enumName with an invalid index. " + + "Please use an index that is between 0 and ${enumValues - 1} and try again.", + null, + ) diff --git a/library/src/main/java/com/paypal/messages/errors/InvalidCheckoutConfigException.kt b/library/src/main/java/com/paypal/messages/errors/InvalidCheckoutConfigException.kt index 33632da5..2af30c3e 100644 --- a/library/src/main/java/com/paypal/messages/errors/InvalidCheckoutConfigException.kt +++ b/library/src/main/java/com/paypal/messages/errors/InvalidCheckoutConfigException.kt @@ -1,3 +1,3 @@ package com.paypal.messages.errors -class InvalidCheckoutConfigException: BaseException("Invalid Checkout Config", null) +class InvalidCheckoutConfigException : BaseException("Invalid Checkout Config", null) diff --git a/library/src/main/java/com/paypal/messages/errors/InvalidClientIdException.kt b/library/src/main/java/com/paypal/messages/errors/InvalidClientIdException.kt index 5e9c4d0d..a6d97de6 100644 --- a/library/src/main/java/com/paypal/messages/errors/InvalidClientIdException.kt +++ b/library/src/main/java/com/paypal/messages/errors/InvalidClientIdException.kt @@ -1,3 +1,3 @@ package com.paypal.messages.errors -class InvalidClientIdException: BaseException("Invalid Client-ID", null) +class InvalidClientIdException : BaseException("Invalid Client-ID", null) diff --git a/library/src/main/java/com/paypal/messages/errors/InvalidResponseException.kt b/library/src/main/java/com/paypal/messages/errors/InvalidResponseException.kt index d733d772..4b0235c7 100644 --- a/library/src/main/java/com/paypal/messages/errors/InvalidResponseException.kt +++ b/library/src/main/java/com/paypal/messages/errors/InvalidResponseException.kt @@ -1,3 +1,4 @@ package com.paypal.messages.errors -class InvalidResponseException(paypalDebugId: String): BaseException("Invalid Response", paypalDebugId) +class InvalidResponseException(paypalDebugId: String) : + BaseException("Invalid Response", paypalDebugId) diff --git a/library/src/main/java/com/paypal/messages/errors/ModalFailedToLoad.kt b/library/src/main/java/com/paypal/messages/errors/ModalFailedToLoad.kt index 70c1f703..48f510ec 100644 --- a/library/src/main/java/com/paypal/messages/errors/ModalFailedToLoad.kt +++ b/library/src/main/java/com/paypal/messages/errors/ModalFailedToLoad.kt @@ -1,3 +1,3 @@ package com.paypal.messages.errors -class ModalFailedToLoad(message: String): BaseException("Modal failed to open: $message", null) +class ModalFailedToLoad(message: String) : BaseException("Modal failed to open: $message", null) diff --git a/library/src/main/java/com/paypal/messages/io/Action.kt b/library/src/main/java/com/paypal/messages/io/Action.kt index 41e0ca81..aed5ce5b 100644 --- a/library/src/main/java/com/paypal/messages/io/Action.kt +++ b/library/src/main/java/com/paypal/messages/io/Action.kt @@ -35,7 +35,7 @@ class Action(private val context: Context) { // If the stored hash is older than hard_ttl if (ageOfStoredHash < hardTtl) { // the stale value should be ignored and a new hash should be fetched - LogCat.debug(TAG, "TTL expired. Fetching new hash.\n${merchantHash}") + LogCat.debug(TAG, "TTL expired. Fetching new hash.\n$merchantHash") newHash = fetchNewHash(messageConfig) val messageData = Api.callMessageDataEndpoint(messageConfig, newHash) @@ -51,7 +51,7 @@ class Action(private val context: Context) { } } else { - LogCat.debug(TAG, "Retrieving hash from local storage\n${merchantHash}") + LogCat.debug(TAG, "Retrieving hash from local storage\n$merchantHash") val messageData = Api.callMessageDataEndpoint(messageConfig, merchantHash) withContext(Dispatchers.Main) { onCompleted.onActionCompleted(messageData) diff --git a/library/src/main/java/com/paypal/messages/io/ActionResponse.kt b/library/src/main/java/com/paypal/messages/io/ActionResponse.kt index a103f751..e50ba33a 100644 --- a/library/src/main/java/com/paypal/messages/io/ActionResponse.kt +++ b/library/src/main/java/com/paypal/messages/io/ActionResponse.kt @@ -7,4 +7,4 @@ data class ActionResponse( val meta: ActionResponseMetadata?, @SerializedName("content") val content: ActionResponseContent?, -): ApiResult.ApiResponse() +) : ApiResult.ApiResponse() diff --git a/library/src/main/java/com/paypal/messages/io/ActionResponseMetadata.kt b/library/src/main/java/com/paypal/messages/io/ActionResponseMetadata.kt index 3be069b0..e85d5597 100644 --- a/library/src/main/java/com/paypal/messages/io/ActionResponseMetadata.kt +++ b/library/src/main/java/com/paypal/messages/io/ActionResponseMetadata.kt @@ -4,7 +4,7 @@ import com.google.gson.annotations.SerializedName import com.paypal.messages.config.PayPalMessageOfferType import com.paypal.messages.config.ProductGroup import com.paypal.messages.config.modal.ModalCloseButton -import java.util.* +import java.util.UUID data class ActionResponseMetadata( @SerializedName("credit_product_group") @@ -30,5 +30,5 @@ data class ActionResponseMetadata( @SerializedName("tracking_keys") val trackingKeys: List, @SerializedName("originating_instance_id") - val originatingInstanceId: UUID + val originatingInstanceId: UUID, ) diff --git a/library/src/main/java/com/paypal/messages/io/Api.kt b/library/src/main/java/com/paypal/messages/io/Api.kt index 69d434ac..d40c020b 100644 --- a/library/src/main/java/com/paypal/messages/io/Api.kt +++ b/library/src/main/java/com/paypal/messages/io/Api.kt @@ -2,7 +2,6 @@ package com.paypal.messages.io import com.google.gson.Gson import com.paypal.messages.BuildConfig -import com.paypal.messages.config.PayPalEnvironment as Environment import com.paypal.messages.errors.FailedToFetchDataException import com.paypal.messages.logger.TrackingPayload import com.paypal.messages.utils.LogCat @@ -14,31 +13,32 @@ import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.RequestBody.Companion.toRequestBody import okio.IOException +import java.util.UUID +import com.paypal.messages.config.PayPalEnvironment as Env import com.paypal.messages.config.PayPalMessageOfferType as OfferType import com.paypal.messages.config.message.PayPalMessageConfig as MessageConfig -import java.util.UUID object Api { private const val TAG = "Api" private val client = OkHttpClient() private val gson = Gson() - var environment = Environment.SANDBOX - var instanceId: UUID? = null; - var originatingInstanceId: UUID? = null; - var sessionId: UUID? = null; + var environment = Env.SANDBOX + var instanceId: UUID? = null + var originatingInstanceId: UUID? = null + var sessionId: UUID? = null object Endpoints { private val ROOT_URLS = mapOf( - Environment.LIVE to "https://www.paypal.com", - Environment.SANDBOX to "https://www.sandbox.paypal.com", - Environment.STAGE to BuildConfig.STAGE_URL, - Environment.STAGE_VPN to BuildConfig.STAGE_VPN_URL, - Environment.LOCAL to BuildConfig.LOCAL_URL, + Env.LIVE to "https://www.paypal.com", + Env.SANDBOX to "https://www.sandbox.paypal.com", + Env.STAGE to BuildConfig.STAGE_URL, + Env.STAGE_VPN to BuildConfig.STAGE_VPN_URL, + Env.LOCAL to BuildConfig.LOCAL_URL, ) private val rootUrl = ROOT_URLS[environment] - private val presentmentUrl = if (environment === Environment.LOCAL) "$rootUrl:8000" else "$rootUrl" - private val loggerUrl = if (environment === Environment.LOCAL) "$rootUrl:9090" else "$rootUrl" + private val presentmentUrl = if (environment === Env.LOCAL) "$rootUrl:8000" else "$rootUrl" + private val loggerUrl = if (environment === Env.LOCAL) "$rootUrl:9090" else "$rootUrl" val messageData = "$presentmentUrl/credit-presentment/native/message".toHttpUrl() val messageHash = "$presentmentUrl/credit-presentment/merchant-profile".toHttpUrl() @@ -85,21 +85,21 @@ object Api { val bodyJson = response.body?.string() response.close() - if (code != 200) { return ApiResult.Failure(FailedToFetchDataException()) } + if (code != 200) return ApiResult.Failure(FailedToFetchDataException()) - LogCat.debug(TAG,"callMessageDataEndpoint response: $bodyJson") + LogCat.debug(TAG, "callMessageDataEndpoint response: $bodyJson") val body = gson.fromJson(bodyJson, ActionResponse::class.java) val isValidResponse = body?.content != null && body.meta != null return if (isValidResponse) { - Api.originatingInstanceId = body.meta?.originatingInstanceId; - ApiResult.Success(body); + originatingInstanceId = body.meta?.originatingInstanceId + ApiResult.Success(body) } else { ApiResult.getFailureWithDebugId(response.headers) } } - catch(exception: IOException) { + catch (exception: IOException) { // Failed to fetch the data and there is no debugId return ApiResult.Failure(FailedToFetchDataException()) } @@ -125,16 +125,16 @@ object Api { try { val response = client.newCall(request).execute() val bodyJson = response.body?.string() - val isFailedResponse = ! response.isSuccessful + val isFailedResponse = !response.isSuccessful val message = response.message response.close() if (isFailedResponse) { - LogCat.error(TAG, "callMessageHashEndpoint error: ${message}\n${bodyJson}") + LogCat.error(TAG, "callMessageHashEndpoint error: ${message}\n$bodyJson") return ApiResult.getFailureWithDebugId(response.headers) } - LogCat.debug(TAG,"callMessageHashEndpoint response: $bodyJson") + LogCat.debug(TAG, "callMessageHashEndpoint response: $bodyJson") val hashResponse = gson.fromJson(bodyJson, HashActionResponse::class.java) return ApiResult.Success(hashResponse) @@ -148,7 +148,7 @@ object Api { clientId: String, amount: Double?, buyerCountry: String?, - offer: OfferType? + offer: OfferType?, ): String { val url = Endpoints.modalData.newBuilder().apply { addQueryParameter("client_id", clientId) @@ -178,6 +178,6 @@ object Api { val json = gson.toJson(payload) val request = createLoggerRequest(json) val response = client.newCall(request).execute() - response.body?.string()?.let { LogCat.debug(TAG,"callLoggerEndpoint response: $it") } + response.body?.string()?.let { LogCat.debug(TAG, "callLoggerEndpoint response: $it") } } } diff --git a/library/src/main/java/com/paypal/messages/io/ApiResult.kt b/library/src/main/java/com/paypal/messages/io/ApiResult.kt index 893d51dc..5951f085 100644 --- a/library/src/main/java/com/paypal/messages/io/ApiResult.kt +++ b/library/src/main/java/com/paypal/messages/io/ApiResult.kt @@ -15,8 +15,8 @@ sealed class ApiResult { val isSuccess: Boolean get() = this is Success<*> - data class Success(val response: T): ApiResult() - data class Failure(val error: T): ApiResult() + data class Success(val response: T) : ApiResult() + data class Failure(val error: T) : ApiResult() companion object { fun getFailureWithDebugId(headers: Headers): ApiResult { diff --git a/library/src/main/java/com/paypal/messages/io/HashActionResponse.kt b/library/src/main/java/com/paypal/messages/io/HashActionResponse.kt index 6b67f4d9..18b336c2 100644 --- a/library/src/main/java/com/paypal/messages/io/HashActionResponse.kt +++ b/library/src/main/java/com/paypal/messages/io/HashActionResponse.kt @@ -11,4 +11,4 @@ data class HashActionResponse( val ttlHard: Long?, @SerializedName("merchant_profile") val merchantProfile: HashDataActionResponse?, -): ApiResult.ApiResponse() +) : ApiResult.ApiResponse() diff --git a/library/src/main/java/com/paypal/messages/io/LocalStorage.kt b/library/src/main/java/com/paypal/messages/io/LocalStorage.kt index 7e4338ed..0490f740 100644 --- a/library/src/main/java/com/paypal/messages/io/LocalStorage.kt +++ b/library/src/main/java/com/paypal/messages/io/LocalStorage.kt @@ -13,8 +13,12 @@ class LocalStorage constructor(context: Context) { enum class StorageKeys(private val keyName: String) { MERCHANT_HASH_DATA("merchantProfileHashData"), - TIMESTAMP("timestamp"); - override fun toString(): String { return keyName } + TIMESTAMP("timestamp"), + ; + + override fun toString(): String { + return keyName + } } var merchantHashData: HashActionResponse? @@ -23,7 +27,7 @@ class LocalStorage constructor(context: Context) { LogCat.debug(TAG, "Retrieving hash from local storage:\n$storage") if (storage !== null) { val storageFromString = gson.fromJson(storage, HashActionResponse::class.java) - LogCat.debug(TAG, "Converted local storage string to json:\n${storageFromString}") + LogCat.debug(TAG, "Converted local storage string to json:\n$storageFromString") return storageFromString } return null diff --git a/library/src/main/java/com/paypal/messages/logger/ComponentType.kt b/library/src/main/java/com/paypal/messages/logger/ComponentType.kt index ac6c27e3..7c503fb2 100644 --- a/library/src/main/java/com/paypal/messages/logger/ComponentType.kt +++ b/library/src/main/java/com/paypal/messages/logger/ComponentType.kt @@ -2,5 +2,5 @@ package com.paypal.messages.logger enum class ComponentType { MODAL, - MESSAGE + MESSAGE, } diff --git a/library/src/main/java/com/paypal/messages/logger/EventType.kt b/library/src/main/java/com/paypal/messages/logger/EventType.kt index b3e6078c..e343f6f4 100644 --- a/library/src/main/java/com/paypal/messages/logger/EventType.kt +++ b/library/src/main/java/com/paypal/messages/logger/EventType.kt @@ -7,5 +7,5 @@ enum class EventType { MODAL_CLICK, MODAL_OPEN, MODAL_CLOSE, - MODAL_ERROR + MODAL_ERROR, } diff --git a/library/src/main/java/com/paypal/messages/logger/Logger.kt b/library/src/main/java/com/paypal/messages/logger/Logger.kt index 13bd3567..eee30363 100644 --- a/library/src/main/java/com/paypal/messages/logger/Logger.kt +++ b/library/src/main/java/com/paypal/messages/logger/Logger.kt @@ -2,9 +2,9 @@ package com.paypal.messages.logger import android.content.Context import android.provider.Settings -import com.paypal.messages.io.LocalStorage import com.paypal.messages.errors.InvalidCheckoutConfigException import com.paypal.messages.io.Api +import com.paypal.messages.io.LocalStorage import com.paypal.messages.utils.LogCat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -65,7 +65,7 @@ class Logger private constructor() { } } - fun setGlobalAnalytics ( + fun setGlobalAnalytics( integrationName: String, integrationVersion: String, ) { diff --git a/library/src/main/java/com/paypal/messages/logger/TrackingComponent.kt b/library/src/main/java/com/paypal/messages/logger/TrackingComponent.kt index f773f1e0..2daf5930 100644 --- a/library/src/main/java/com/paypal/messages/logger/TrackingComponent.kt +++ b/library/src/main/java/com/paypal/messages/logger/TrackingComponent.kt @@ -1,10 +1,10 @@ package com.paypal.messages.logger import com.google.gson.annotations.SerializedName -import com.paypal.messages.config.message.style.PayPalMessageColor +import com.paypal.messages.config.PayPalMessageOfferType import com.paypal.messages.config.message.style.PayPalMessageAlign +import com.paypal.messages.config.message.style.PayPalMessageColor import com.paypal.messages.config.message.style.PayPalMessageLogoType -import com.paypal.messages.config.PayPalMessageOfferType data class TrackingComponent( // Integration Details diff --git a/library/src/main/java/com/paypal/messages/utils/AccessibilityUtils.kt b/library/src/main/java/com/paypal/messages/utils/AccessibilityUtils.kt index efbf1a07..33e17370 100644 --- a/library/src/main/java/com/paypal/messages/utils/AccessibilityUtils.kt +++ b/library/src/main/java/com/paypal/messages/utils/AccessibilityUtils.kt @@ -16,7 +16,7 @@ fun View.requestAccessibilityFocus() { { sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED) }, - ACCESSIBILITY_DELAY + ACCESSIBILITY_DELAY, ) } diff --git a/library/src/main/java/com/paypal/messages/utils/IgnoreGeneratedTestReport.kt b/library/src/main/java/com/paypal/messages/utils/IgnoreGeneratedTestReport.kt index de63b429..eba0e97d 100644 --- a/library/src/main/java/com/paypal/messages/utils/IgnoreGeneratedTestReport.kt +++ b/library/src/main/java/com/paypal/messages/utils/IgnoreGeneratedTestReport.kt @@ -11,6 +11,6 @@ package com.paypal.messages.utils AnnotationTarget.FUNCTION, AnnotationTarget.CLASS, AnnotationTarget.FIELD, - AnnotationTarget.FILE + AnnotationTarget.FILE, ) annotation class IgnoreGeneratedTestReport diff --git a/library/src/main/java/com/paypal/messages/utils/LogCat.kt b/library/src/main/java/com/paypal/messages/utils/LogCat.kt index 727e1ecb..54c9538e 100644 --- a/library/src/main/java/com/paypal/messages/utils/LogCat.kt +++ b/library/src/main/java/com/paypal/messages/utils/LogCat.kt @@ -5,9 +5,9 @@ import android.util.Log object LogCat { private const val prefix = "PPMessages" private const val SHOW_FULL_MESSAGES = false - + private fun reduceLongMessage(message: String): String { - if (SHOW_FULL_MESSAGES) { return message } + if (SHOW_FULL_MESSAGES) return message return message.split("\n").take(10).joinToString("\n") } diff --git a/library/src/main/java/com/paypal/messages/utils/createFormattedIllegalArgumentException.kt b/library/src/main/java/com/paypal/messages/utils/createFormattedIllegalArgumentException.kt deleted file mode 100644 index 1be7843a..00000000 --- a/library/src/main/java/com/paypal/messages/utils/createFormattedIllegalArgumentException.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.paypal.messages.utils - -internal fun createFormattedIllegalArgumentException( - enumName: String, - enumValues: Int, -): IllegalArgumentException { - val exceptionMessage = "PayPalMessage Attempted to create a $enumName with an invalid index. " + - "Please use an index that is between 0 and ${enumValues - 1} and try again." - return IllegalArgumentException(exceptionMessage) -} diff --git a/library/src/main/res/drawable/logo_alternative_monochrome.xml b/library/src/main/res/drawable/logo_alternative_monochrome.xml index d88bfe11..5a2d3247 100644 --- a/library/src/main/res/drawable/logo_alternative_monochrome.xml +++ b/library/src/main/res/drawable/logo_alternative_monochrome.xml @@ -1,6 +1,6 @@ + @@ -12,22 +13,29 @@ + diff --git a/library/src/main/res/drawable/logo_credit_alternative_monochrome.xml b/library/src/main/res/drawable/logo_credit_alternative_monochrome.xml index adfeaa53..af3083c9 100644 --- a/library/src/main/res/drawable/logo_credit_alternative_monochrome.xml +++ b/library/src/main/res/drawable/logo_credit_alternative_monochrome.xml @@ -1,8 +1,9 @@ + @@ -12,22 +13,29 @@ + + android:name="C" + android:pathData="M169.752,41.64c-0.19,1.17 -1.63,1.6 -2.46,0.75c-2.82,-2.89 -6.96,-4.42 -11.42,-4.42c-10.07,0 -18.05,7.72 -19.64,17.54c-1.51,9.99 4.2,17.21 14.43,17.21c4.22,0 8.7,-1.61 12.42,-4.29c1.03,-0.74 2.44,0.15 2.23,1.4l-2.34,14.49c-0.14,0.86 -0.76,1.57 -1.6,1.81c-5.02,1.47 -8.87,2.53 -13.57,2.53c-27.3,0 -31.67,-23.33 -30.26,-33.24c3.94,-27.8 26.51,-34.17 40.34,-33.41c4.46,0.25 8.45,0.84 12.36,2.31c1.26,0.48 2.02,1.78 1.8,3.11L169.752,41.64z" + android:fillColor="#FF000000" /> + android:name="R" + android:pathData="M190.672,52.04h1.6c5.38,0 11.56,-1.01 12.68,-7.9c1.12,-6.89 -2.46,-7.88 -8.21,-7.9h-2.33c-0.7,0 -1.3,0.51 -1.41,1.21L190.672,52.04zM218.932,86.99h-16.92c-0.72,0 -1.38,-0.41 -1.69,-1.06l-11.17,-23.3h-0.17l-3.61,22.79c-0.14,0.91 -0.93,1.58 -1.85,1.58h-13.29c-0.83,0 -1.46,-0.74 -1.33,-1.56l9.5,-60.21c0.14,-0.91 0.93,-1.58 1.85,-1.58h23.02c12.52,0 21.08,5.97 18.98,19.49c-1.43,8.74 -7.48,16.3 -16.72,17.9l14.55,23.91C220.632,85.84 219.992,86.99 218.932,86.99z" + android:fillColor="#FF000000" /> + android:name="E" + android:pathData="M247.162,39.54l-1.37,8.64h16.99c0.83,0 1.46,0.74 1.33,1.56l-1.63,10.44c-0.18,1.12 -1.14,1.95 -2.28,1.95h-14.62c-1.13,0 -2.1,0.82 -2.28,1.94l-1.45,8.98h18c0.83,0 1.46,0.74 1.33,1.56l-1.63,10.44c-0.18,1.13 -1.14,1.95 -2.28,1.95h-32.48c-0.83,0 -1.46,-0.74 -1.33,-1.56l9.44,-59.84c0.18,-1.12 1.15,-1.95 2.28,-1.95h32.49c0.83,0 1.46,0.74 1.33,1.56l-1.63,10.44c-0.18,1.12 -1.15,1.95 -2.28,1.95h-15.62C248.302,37.59 247.342,38.42 247.162,39.54" + android:fillColor="#FF000000" /> + android:name="D" + android:pathData="M283.812,73.04h3.69c9.83,0 19.07,-5.38 21.09,-17.73c1.76,-11.34 -4.7,-17.73 -15.29,-17.73h-2.71c-0.66,0 -1.23,0.48 -1.33,1.14L283.812,73.04zM274.842,25.59c0.18,-1.12 1.15,-1.95 2.28,-1.95h21.38c17.64,0 29.99,13.86 27.22,31.67c-2.86,17.81 -19.66,31.67 -37.22,31.67h-21.78c-0.83,0 -1.46,-0.74 -1.33,-1.56L274.842,25.59z" + android:fillColor="#FF000000" /> + android:name="I" + android:pathData="M340.102,86.99h-12.91c-0.83,0 -1.46,-0.74 -1.33,-1.56l9.44,-59.84c0.18,-1.12 1.15,-1.95 2.28,-1.95h12.91c0.83,0 1.46,0.74 1.33,1.56l-9.44,59.83C342.212,86.16 341.242,86.99 340.102,86.99" + android:fillColor="#FF000000" /> + android:name="T" + android:pathData="M375.032,86.99h-12.91c-0.83,0 -1.46,-0.74 -1.33,-1.56l7.57,-47.84h-12.03c-0.83,0 -1.46,-0.74 -1.33,-1.56l1.63,-10.44c0.18,-1.12 1.14,-1.95 2.28,-1.95h40.13c0.83,0 1.46,0.74 1.33,1.56l-1.63,10.44c-0.18,1.12 -1.15,1.95 -2.28,1.95h-11.63l-7.5,47.45C377.132,86.16 376.162,86.99 375.032,86.99" + android:fillColor="#FF000000" /> diff --git a/library/src/main/res/drawable/logo_credit_alternative_standard.xml b/library/src/main/res/drawable/logo_credit_alternative_standard.xml index 9ba5c045..461ac417 100644 --- a/library/src/main/res/drawable/logo_credit_alternative_standard.xml +++ b/library/src/main/res/drawable/logo_credit_alternative_standard.xml @@ -1,50 +1,51 @@ - - + diff --git a/library/src/main/res/drawable/logo_credit_inline_grayscale.xml b/library/src/main/res/drawable/logo_credit_inline_grayscale.xml index d43c132d..64ee285a 100644 --- a/library/src/main/res/drawable/logo_credit_inline_grayscale.xml +++ b/library/src/main/res/drawable/logo_credit_inline_grayscale.xml @@ -1,42 +1,50 @@ - + android:fillType="nonZero" /> + android:name="a" + android:pathData="M70.645 35.551 C 69.483 40.505 65.551 43.831 60.534 43.831 C 58.02 43.831 56.006 43.022 54.712 41.49 C 53.43 39.972 52.946 37.809 53.354 35.401 C 54.134 30.49 58.13 27.057 63.07 27.057 C 65.533 27.057 67.532 27.874 68.85 29.42 C 70.178 30.977 70.701 33.154 70.321 35.551 M 82.404 18.675 L 73.734 18.675 C 72.991 18.675 72.359 19.215 72.244 19.949 L 71.861 22.373 L 71.256 21.495 C 69.378 18.769 65.193 17.859 61.014 17.859 C 51.436 17.859 43.253 25.117 41.659 35.299 C 40.831 40.378 42.008 45.232 44.886 48.62 C 47.533 51.733 51.309 53.029 55.807 53.029 C 63.529 53.029 67.812 48.068 67.812 48.068 L 67.425 50.478 C 67.28 51.394 67.988 52.223 68.915 52.224 L 76.724 52.224 C 77.962 52.223 79.015 51.323 79.208 50.101 L 83.896 20.419 C 84.041 19.502 83.332 18.673 82.404 18.675" + android:fillColor="#1a1a1a" + android:fillType="nonZero" /> - - - - - + + + + + diff --git a/library/src/main/res/drawable/logo_credit_inline_monochrome.xml b/library/src/main/res/drawable/logo_credit_inline_monochrome.xml index f1a2093d..2af56230 100644 --- a/library/src/main/res/drawable/logo_credit_inline_monochrome.xml +++ b/library/src/main/res/drawable/logo_credit_inline_monochrome.xml @@ -1,36 +1,54 @@ + + + + + + - - - - - - diff --git a/library/src/main/res/drawable/logo_credit_inline_standard.xml b/library/src/main/res/drawable/logo_credit_inline_standard.xml index 559b3278..782cf943 100644 --- a/library/src/main/res/drawable/logo_credit_inline_standard.xml +++ b/library/src/main/res/drawable/logo_credit_inline_standard.xml @@ -1,45 +1,57 @@ - - - - - - + + + + + diff --git a/library/src/main/res/drawable/logo_credit_inline_white.xml b/library/src/main/res/drawable/logo_credit_inline_white.xml index d91a4d8f..9c4ca371 100644 --- a/library/src/main/res/drawable/logo_credit_inline_white.xml +++ b/library/src/main/res/drawable/logo_credit_inline_white.xml @@ -1,30 +1,57 @@ + android:width="200dp" + android:height="26.83dp" + android:viewportWidth="477" + android:viewportHeight="64"> + + + + + diff --git a/library/src/main/res/drawable/logo_credit_primary_grayscale.xml b/library/src/main/res/drawable/logo_credit_primary_grayscale.xml index f3c40cba..7e8a52d3 100644 --- a/library/src/main/res/drawable/logo_credit_primary_grayscale.xml +++ b/library/src/main/res/drawable/logo_credit_primary_grayscale.xml @@ -1,36 +1,66 @@ + android:width="200dp" + android:height="27.92dp" + android:viewportWidth="573" + android:viewportHeight="80"> + + + + android:name="a" + android:pathData="M 178.73 34.62 L 170.06 34.62 C 169.32 34.62 168.68 35.16 168.57 35.89 L 168.19 38.31 L 167.58 37.43 C 165.7 34.7 161.52 33.79 157.34 33.79 C 147.76 33.79 139.58 41.05 137.99 51.23 C 137.16 56.31 138.34 61.16 141.22 64.55 C 143.87 67.66 147.64 68.96 152.14 68.96 C 159.86 68.96 164.14 64 164.14 64 L 163.75 66.41 C 163.6 67.33 164.31 68.16 165.24 68.16 L 173.05 68.16 C 174.29 68.16 175.34 67.26 175.53 66.04 L 180.22 36.36 C 180.36 35.45 179.66 34.62 178.73 34.62 Z M 166.65 51.49 C 165.81 56.44 161.88 59.77 156.86 59.77 C 154.34 59.77 152.33 58.96 151.04 57.43 C 149.76 55.91 149.27 53.75 149.68 51.34 C 150.46 46.43 154.46 43 159.4 43 C 161.86 43 163.86 43.82 165.18 45.36 C 166.5 46.92 167.03 49.1 166.65 51.49 Z" + android:fillColor="#1a1a1a" /> + + + + android:name="C" + android:pathData="M 389.5 32.2 C 389.35 33.13 388.21 33.47 387.54 32.79 C 385.3 30.49 382 29.28 378.46 29.28 C 370.45 29.28 364.11 35.42 362.84 43.23 C 361.64 51.17 366.18 56.91 374.32 56.91 C 377.68 56.91 381.24 55.63 384.2 53.5 C 385.02 52.91 386.14 53.62 385.98 54.61 L 384.12 66.14 C 384.01 66.83 383.51 67.39 382.85 67.58 C 378.86 68.75 375.8 69.59 372.06 69.59 C 350.35 69.59 346.88 51.04 347.99 43.16 C 351.13 21.05 369.07 15.99 380.06 16.6 C 383.6 16.8 386.78 17.27 389.89 18.44 C 390.89 18.82 391.49 19.85 391.32 20.91 L 389.5 32.2 Z" + android:fillColor="#1a1a1a" /> + android:name="E" + android:pathData="M 451.06 30.53 L 449.97 37.4 L 463.48 37.4 C 464.14 37.4 464.64 37.99 464.54 38.64 L 463.24 46.94 C 463.097 47.834 462.325 48.491 461.42 48.49 L 449.8 48.49 C 448.9 48.49 448.13 49.14 447.99 50.03 L 446.84 57.17 L 461.15 57.17 C 461.81 57.17 462.31 57.76 462.21 58.41 L 460.91 66.71 C 460.767 67.604 459.995 68.261 459.09 68.26 L 433.26 68.26 C 432.6 68.26 432.1 67.67 432.2 67.02 L 439.71 19.44 C 439.85 18.55 440.62 17.89 441.53 17.89 L 467.36 17.89 C 468.02 17.89 468.52 18.48 468.42 19.13 L 467.12 27.43 C 466.977 28.324 466.205 28.981 465.3 28.98 L 452.88 28.98 C 451.97 28.98 451.2 29.63 451.06 30.53 Z" + android:fillColor="#1a1a1a" /> + android:name="D" + android:pathData="M 473.08 19.44 C 473.22 18.55 473.99 17.89 474.9 17.89 L 491.9 17.89 C 505.93 17.89 515.75 28.91 513.54 43.08 C 511.27 57.24 497.91 68.27 483.95 68.27 L 466.63 68.27 C 465.97 68.27 465.47 67.68 465.57 67.03 L 473.08 19.44 Z M 480.2 57.17 L 483.14 57.17 C 490.96 57.17 498.3 52.89 499.91 43.07 C 501.31 34.05 496.17 28.97 487.75 28.97 L 485.59 28.97 C 485.06 28.97 484.61 29.35 484.53 29.87 L 480.2 57.17 Z" + android:fillColor="#1a1a1a" /> + + diff --git a/library/src/main/res/drawable/logo_credit_primary_monochrome.xml b/library/src/main/res/drawable/logo_credit_primary_monochrome.xml index bbd714be..6426e9b4 100644 --- a/library/src/main/res/drawable/logo_credit_primary_monochrome.xml +++ b/library/src/main/res/drawable/logo_credit_primary_monochrome.xml @@ -1,14 +1,8 @@ - - + android:width="200dp" + android:height="27.92dp" + android:viewportWidth="573" + android:viewportHeight="80"> @@ -18,4 +12,54 @@ + + + + + + + + + + + + + + diff --git a/library/src/main/res/drawable/logo_credit_primary_standard.xml b/library/src/main/res/drawable/logo_credit_primary_standard.xml index 66bd6197..288ddf23 100644 --- a/library/src/main/res/drawable/logo_credit_primary_standard.xml +++ b/library/src/main/res/drawable/logo_credit_primary_standard.xml @@ -1,52 +1,73 @@ + + + + + + - - - - + + android:name="C" + android:pathData="M 389.5 32.2 C 389.35 33.13 388.21 33.47 387.54 32.79 C 385.3 30.49 382 29.28 378.46 29.28 C 370.45 29.28 364.11 35.42 362.84 43.23 C 361.64 51.17 366.18 56.91 374.32 56.91 C 377.68 56.91 381.24 55.63 384.2 53.5 C 385.02 52.91 386.14 53.62 385.98 54.61 L 384.12 66.14 C 384.01 66.83 383.51 67.39 382.85 67.58 C 378.86 68.75 375.8 69.59 372.06 69.59 C 350.35 69.59 346.88 51.04 347.99 43.16 C 351.13 21.05 369.07 15.99 380.06 16.6 C 383.6 16.8 386.78 17.27 389.89 18.44 C 390.89 18.82 391.49 19.85 391.32 20.91 L 389.5 32.2 Z" + android:fillColor="#003087" /> - - - - + android:name="R" + android:pathData="M 428.62 68.26 L 415.16 68.26 C 414.59 68.26 414.07 67.93 413.82 67.42 L 404.94 48.89 L 404.81 48.89 L 401.93 67 C 401.82 67.72 401.19 68.25 400.46 68.25 L 389.89 68.25 C 389.23 68.25 388.73 67.66 388.83 67.01 L 396.39 19.13 C 396.5 18.41 397.13 17.87 397.86 17.87 L 416.16 17.87 C 426.11 17.87 432.93 22.61 431.26 33.37 C 430.12 40.32 425.31 46.33 417.97 47.6 L 429.54 66.61 C 429.97 67.34 429.45 68.26 428.62 68.26 Z M 406.14 40.47 L 407.41 40.47 C 411.69 40.47 416.6 39.66 417.5 34.19 C 418.39 28.71 415.54 27.93 410.97 27.91 L 409.12 27.91 C 408.56 27.91 408.08 28.32 408 28.87 L 406.14 40.47 Z" + android:fillColor="#003087" /> + android:name="E" + android:pathData="M 451.06 30.53 L 449.97 37.4 L 463.48 37.4 C 464.14 37.4 464.64 37.99 464.54 38.64 L 463.24 46.94 C 463.097 47.834 462.325 48.491 461.42 48.49 L 449.8 48.49 C 448.9 48.49 448.13 49.14 447.99 50.03 L 446.84 57.17 L 461.15 57.17 C 461.81 57.17 462.31 57.76 462.21 58.41 L 460.91 66.71 C 460.767 67.604 459.995 68.261 459.09 68.26 L 433.26 68.26 C 432.6 68.26 432.1 67.67 432.2 67.02 L 439.71 19.44 C 439.85 18.55 440.62 17.89 441.53 17.89 L 467.36 17.89 C 468.02 17.89 468.52 18.48 468.42 19.13 L 467.12 27.43 C 466.977 28.324 466.205 28.981 465.3 28.98 L 452.88 28.98 C 451.97 28.98 451.2 29.63 451.06 30.53 Z" + android:fillColor="#003087" /> + + + diff --git a/library/src/main/res/drawable/logo_credit_primary_white.xml b/library/src/main/res/drawable/logo_credit_primary_white.xml index 69a90af4..c7cccf48 100644 --- a/library/src/main/res/drawable/logo_credit_primary_white.xml +++ b/library/src/main/res/drawable/logo_credit_primary_white.xml @@ -1,14 +1,12 @@ + android:fillType="evenOdd" /> + + android:name="P" + android:pathData="M 124.61 17.919 L 106.5 17.773 C 105.26 17.763 104.21 18.655 104.02 19.873 L 96.7 66.245 C 96.56 67.163 97.26 67.989 98.19 67.997 L 107.48 68.071 C 108.35 68.078 109.08 67.454 109.22 66.595 L 111.3 53.452 C 111.495 52.231 112.551 51.339 113.79 51.352 L 119.52 51.398 C 131.45 51.493 138.33 45.778 140.13 34.354 C 140.94 29.36 140.16 25.423 137.82 22.644 C 135.23 19.604 130.67 17.967 124.61 17.919 Z M 126.7 34.895 C 125.71 41.387 120.75 41.347 115.95 41.309 L 113.22 41.287 L 115.14 29.162 C 115.26 28.434 115.89 27.899 116.63 27.905 L 117.88 27.914 C 121.15 27.941 124.24 27.965 125.83 29.838 C 126.77 30.956 127.06 32.608 126.7 34.895 Z" + android:fillColor="#FFF" /> + android:name="a" + android:pathData="M 178.73 34.62 L 170.06 34.62 C 169.32 34.62 168.68 35.16 168.57 35.89 L 168.19 38.31 L 167.58 37.43 C 165.7 34.7 161.52 33.79 157.34 33.79 C 147.76 33.79 139.58 41.05 137.99 51.23 C 137.16 56.31 138.34 61.16 141.22 64.55 C 143.87 67.66 147.64 68.96 152.14 68.96 C 159.86 68.96 164.14 64 164.14 64 L 163.75 66.41 C 163.6 67.33 164.31 68.16 165.24 68.16 L 173.05 68.16 C 174.29 68.16 175.34 67.26 175.53 66.04 L 180.22 36.36 C 180.36 35.45 179.66 34.62 178.73 34.62 Z M 166.65 51.49 C 165.81 56.44 161.88 59.77 156.86 59.77 C 154.34 59.77 152.33 58.96 151.04 57.43 C 149.76 55.91 149.27 53.75 149.68 51.34 C 150.46 46.43 154.46 43 159.4 43 C 161.86 43 163.86 43.82 165.18 45.36 C 166.5 46.92 167.03 49.1 166.65 51.49 Z" + android:fillColor="#FFF" /> + android:name="y" + android:pathData="M224.76,34.62h-8.72c-0.83,0 -1.61,0.41 -2.08,1.1l-12.02,17.71 -5.09,-17.01a2.52,2.52 0,0 0,-2.41 -1.79h-8.57c-1.03,0 -1.76,1.02 -1.43,2l9.6,28.17 -9.03,12.74c-0.71,1 0.01,2.38 1.23,2.38h8.71c0.83,0 1.6,-0.4 2.07,-1.08L226,36.99c0.69,-1 -0.02,-2.37 -1.24,-2.37z" + android:fillColor="#FFF" /> + android:name="P-2" + android:pathData="M253.61,17.87L235.5,17.87c-1.24,0 -2.29,0.9 -2.48,2.12l-7.32,46.43c-0.14,0.92 0.56,1.74 1.49,1.74h9.29c0.87,0 1.6,-0.63 1.74,-1.49l2.08,-13.16a2.517,2.517 0,0 1,2.49 -2.12h5.73c11.93,0 18.81,-5.77 20.61,-17.21 0.81,-5 0.03,-8.93 -2.31,-11.69 -2.59,-3.02 -7.15,-4.62 -13.21,-4.62zM255.7,34.83c-0.99,6.5 -5.95,6.5 -10.75,6.5h-2.73l1.92,-12.14c0.12,-0.73 0.75,-1.27 1.49,-1.27h1.25c3.27,0 6.36,0 7.95,1.86 0.94,1.11 1.23,2.76 0.87,5.05z" + android:fillColor="#FFF" /> + android:name="a-2" + android:pathData="M307.73,34.62h-8.67c-0.74,0 -1.38,0.54 -1.49,1.27l-0.38,2.42 -0.61,-0.88c-1.88,-2.73 -6.06,-3.64 -10.24,-3.64 -9.58,0 -17.76,7.26 -19.35,17.44 -0.83,5.08 0.35,9.93 3.23,13.32 2.65,3.11 6.42,4.41 10.92,4.41 7.72,0 12,-4.96 12,-4.96l-0.39,2.41c-0.15,0.92 0.56,1.75 1.49,1.75h7.81c1.24,0 2.29,-0.9 2.48,-2.12l4.69,-29.68c0.14,-0.91 -0.56,-1.74 -1.49,-1.74zM295.65,51.49c-0.84,4.95 -4.77,8.28 -9.79,8.28 -2.52,0 -4.53,-0.81 -5.82,-2.34 -1.28,-1.52 -1.77,-3.68 -1.36,-6.09 0.78,-4.91 4.78,-8.34 9.72,-8.34 2.46,0 4.46,0.82 5.78,2.36 1.32,1.56 1.85,3.74 1.47,6.13z" + android:fillColor="#FFF" /> + android:name="l" + android:pathData="M317.95,19.14l-7.43,47.28c-0.14,0.92 0.56,1.74 1.49,1.74h7.47c1.24,0 2.29,-0.9 2.48,-2.12l7.33,-46.43c0.14,-0.92 -0.56,-1.74 -1.49,-1.74h-8.36c-0.74,0 -1.38,0.54 -1.49,1.27z" + android:fillColor="#FFF" /> + + + + + + + + diff --git a/library/src/main/res/drawable/logo_primary_grayscale.xml b/library/src/main/res/drawable/logo_primary_grayscale.xml index 24bb5cb9..e096ed19 100644 --- a/library/src/main/res/drawable/logo_primary_grayscale.xml +++ b/library/src/main/res/drawable/logo_primary_grayscale.xml @@ -1,6 +1,6 @@ + android:viewportHeight="98.18"> diff --git a/library/src/main/res/drawable/logo_primary_standard.xml b/library/src/main/res/drawable/logo_primary_standard.xml index 6f10d9d7..168f8d66 100644 --- a/library/src/main/res/drawable/logo_primary_standard.xml +++ b/library/src/main/res/drawable/logo_primary_standard.xml @@ -1,6 +1,6 @@ Date: Wed, 27 Sep 2023 09:32:22 -0400 Subject: [PATCH 05/37] fix: update shared data (#7) --- .../java/com/paypal/messages/ModalFragment.kt | 35 +++++++------- .../java/com/paypal/messages/logger/Logger.kt | 47 ++++++++++--------- .../paypal/messages/logger/TrackingPayload.kt | 2 +- 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/library/src/main/java/com/paypal/messages/ModalFragment.kt b/library/src/main/java/com/paypal/messages/ModalFragment.kt index dc10af63..52fd1397 100644 --- a/library/src/main/java/com/paypal/messages/ModalFragment.kt +++ b/library/src/main/java/com/paypal/messages/ModalFragment.kt @@ -386,17 +386,20 @@ internal class ModalFragment constructor( * See paypal-messaging-components/src/components/modal/v2/lib/zoid-polyfill.js for how it works. */ @JavascriptInterface - fun paypalMessageModalCallbackHandler(args: String) { - val json = JsonParser.parseString(args).asJsonObject - LogCat.debug(TAG, "CallbackHandler:\n name = ${json.get("name")}\n args = ${json.get("args")}") + fun paypalMessageModalCallbackHandler(passedParams: String) { + val params = if (passedParams != "") passedParams else "{\"name\": \"\", \"args\": [{}]" + val nameAndArgs = JsonParser.parseString(params).asJsonObject + val name = nameAndArgs.get("name").asString + val args = nameAndArgs.get("args").asJsonArray[0].asJsonObject + LogCat.debug(TAG, "CallbackHandler:\n name = $name\n args = $args") // If __shared__ does not exist, use an empty object - val sharedJson = json.get("__shared__") ?: JsonParser.parseString("{}") + val sharedJson = args.get("__shared__") ?: JsonParser.parseString("{}") val shared = jsonElementToMutableMap(sharedJson) - when (json.get("name").asString) { + when (name) { "onClick" -> { - val linkName = json.get("link_name")?.asString - val linkSrc = json.get("link_src")?.asString + val linkName = args.get("link_name")?.asString + val linkSrc = args.get("link_src")?.asString if (linkName == "Apply Now") { this.onApply() } @@ -414,7 +417,7 @@ internal class ModalFragment constructor( } "onCalculate" -> { - val calculatorAmount = json.get("amount")?.asString + val calculatorAmount = args.get("amount")?.asString this.onCalculate() logEvent( TrackingEvent( @@ -448,18 +451,14 @@ internal class ModalFragment constructor( private fun jsonValueToAny(jsonElement: JsonElement): Any { return when { jsonElement.isJsonPrimitive -> { - val jsonPrimitive = jsonElement.asJsonPrimitive - if (jsonPrimitive.isBoolean) { - jsonPrimitive.asBoolean - } - else if (jsonPrimitive.isNumber) { - jsonPrimitive.asNumber - } - else { - jsonPrimitive.asString + val primitive = jsonElement.asJsonPrimitive + when { + primitive.isBoolean -> primitive.asBoolean + primitive.isNumber -> primitive.asNumber + else -> primitive.asString } } - + jsonElement.isJsonArray -> jsonElement.asJsonArray jsonElement.isJsonObject -> jsonElementToMutableMap(jsonElement) else -> throw IllegalArgumentException("Unsupported JSON element type: ${jsonElement::class.java.simpleName}") } diff --git a/library/src/main/java/com/paypal/messages/logger/Logger.kt b/library/src/main/java/com/paypal/messages/logger/Logger.kt index eee30363..c43ccd03 100644 --- a/library/src/main/java/com/paypal/messages/logger/Logger.kt +++ b/library/src/main/java/com/paypal/messages/logger/Logger.kt @@ -43,21 +43,26 @@ class Logger private constructor() { initBasePayload() } + private fun resetBasePayload(isInit: Boolean = false) { + LogCat.debug(TAG, if (isInit) "initBasePayload" else "resetBasePayload") + this.payload = TrackingPayload( + clientId = clientId, + merchantId = null, + partnerAttributionId = null, + // merchantProfileHash will be later defined by pulling from LocalStorage + merchantProfileHash = null, + deviceId = Settings.Secure.ANDROID_ID, + // TODO Determine SessionId for Logger + sessionId = "random for now, TBD at later point to what this is specifically", + integrationName = integrationName, + integrationVersion = integrationVersion, + components = mutableListOf(), + ) + } + private fun initBasePayload() { if (clientId !== "") { - this.payload = TrackingPayload( - clientId = clientId, - merchantId = null, - partnerAttributionId = null, - // merchantProfileHash can be later defined after a message request by pulling from paypalmessagelocalstorage - merchantProfileHash = null, - deviceId = Settings.Secure.ANDROID_ID, - // TODO Determine SessionId for Logger - sessionId = "random for now, TBD at later point to what this is specifically", - integrationName = integrationName, - integrationVersion = integrationVersion, - components = mutableListOf(), - ) + resetBasePayload(true) } else { val exception = InvalidCheckoutConfigException() @@ -113,18 +118,16 @@ class Logger private constructor() { delay(5000) // Wait 5 seconds before sending our payload val localStorage = LocalStorage(context) - LogCat.debug(TAG, localStorage.merchantHash.toString()) - finalPayload.components.forEach { component -> - component.instanceId?.let { LogCat.debug(TAG, it) } - component.events.forEach { event -> - LogCat.debug(TAG, event.eventType.toString()) - } + val hash = localStorage.merchantHash + val payloadSummary = finalPayload.components.joinToString("\n") { + val eventsString = it.events.joinToString { event -> event.eventType.toString() } + " type: ${it.type}\n instanceId: ${it.instanceId}\n events: $eventsString\n" } + LogCat.debug(TAG, "merchantHash: ${hash}\npayloadSummary:\n$payloadSummary") + finalPayload.merchantProfileHash = hash Api.callLoggerEndpoint(finalPayload) - - // After our response has completed, we can reset our base payload. - initBasePayload() + resetBasePayload() } } } diff --git a/library/src/main/java/com/paypal/messages/logger/TrackingPayload.kt b/library/src/main/java/com/paypal/messages/logger/TrackingPayload.kt index e5c07f8e..ec83b2ef 100644 --- a/library/src/main/java/com/paypal/messages/logger/TrackingPayload.kt +++ b/library/src/main/java/com/paypal/messages/logger/TrackingPayload.kt @@ -13,7 +13,7 @@ data class TrackingPayload( @SerializedName("partner_attribution_id") val partnerAttributionId: String? = null, @SerializedName("merchant_profile_hash") - val merchantProfileHash: String? = null, + var merchantProfileHash: String? = null, // Global Details @SerializedName("device_id") From 1550f44f72d9ba6fed95cb0c2fb8bf6b5794463e Mon Sep 17 00:00:00 2001 From: "Merlin (they/them)" <124289716+merlinpaypal@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:40:43 -0400 Subject: [PATCH 06/37] fix: remove kotlinter --- demo/build.gradle | 1 - library/build.gradle | 1 - 2 files changed, 2 deletions(-) diff --git a/demo/build.gradle b/demo/build.gradle index 1471b913..eb282d35 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -1,7 +1,6 @@ plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' - id 'org.jmailen.kotlinter' } android { diff --git a/library/build.gradle b/library/build.gradle index 5ec13d91..5fdfff59 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,7 +1,6 @@ plugins { id 'com.android.library' id 'org.jetbrains.kotlin.android' - id 'org.jmailen.kotlinter' } android { From 4b3350431678922af6cab9952f9f155b92275c78 Mon Sep 17 00:00:00 2001 From: Grant Black <85238976+grablack@users.noreply.github.com> Date: Wed, 18 Oct 2023 11:50:18 -0400 Subject: [PATCH 07/37] feat: xml demo (#6) --- demo/build.gradle | 3 +- .../com/paypal/messagesdemo/XmlActivity.kt | 202 ++++++++--- demo/src/main/res/layout/activity_message.xml | 321 ++++++++++++++---- demo/src/main/res/values/strings.xml | 5 +- .../com/paypal/messages/PayPalMessageView.kt | 8 +- .../main/java/com/paypal/messages/io/Api.kt | 7 +- 6 files changed, 433 insertions(+), 113 deletions(-) diff --git a/demo/build.gradle b/demo/build.gradle index eb282d35..ba320754 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -71,8 +71,9 @@ dependencies { implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.appcompat:appcompat:1.6.1' implementation project(':library') + implementation 'com.google.android.material:material:1.10.0' - testImplementation 'junit:junit:4.13.2' + testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation platform('androidx.compose:compose-bom:2023.09.00') diff --git a/demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt b/demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt index 7b4362bd..95875bab 100644 --- a/demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt +++ b/demo/src/main/java/com/paypal/messagesdemo/XmlActivity.kt @@ -3,24 +3,30 @@ package com.paypal.messagesdemo import android.os.Bundle import android.util.Log import android.view.View +import android.widget.Button +import android.widget.EditText +import android.widget.RadioGroup import android.widget.Toast +import android.widget.ToggleButton import androidx.appcompat.app.AppCompatActivity -import com.paypal.messages.PayPalMessageView +import androidx.compose.ui.graphics.Color +import com.google.android.material.switchmaterial.SwitchMaterial import com.paypal.messages.config.PayPalMessageOfferType -import com.paypal.messages.config.message.PayPalMessageConfig -import com.paypal.messages.config.message.PayPalMessageData -import com.paypal.messages.config.message.PayPalMessageEvents import com.paypal.messages.config.message.PayPalMessageStyle import com.paypal.messages.config.message.PayPalMessageViewState import com.paypal.messages.config.message.style.PayPalMessageAlign import com.paypal.messages.config.message.style.PayPalMessageColor import com.paypal.messages.config.message.style.PayPalMessageLogoType +import com.paypal.messages.io.Api import com.paypal.messagesdemo.databinding.ActivityMessageBinding -import com.paypal.messages.config.PayPalEnvironment as Environment class XmlActivity : AppCompatActivity() { private lateinit var binding: ActivityMessageBinding private val TAG = "XmlActivity" + private var logoType: PayPalMessageLogoType = PayPalMessageLogoType.PRIMARY + private var color: PayPalMessageColor = PayPalMessageColor.BLACK + private var alignment: PayPalMessageAlign = PayPalMessageAlign.LEFT + private var offerType: PayPalMessageOfferType? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -29,23 +35,169 @@ class XmlActivity : AppCompatActivity() { val payPalMessage = binding.payPalMessage val progressBar = binding.progressBar - val reloadButton = binding.reloadButton - // TODO add example of adding MessageView here instead of in XML + val editedClientId: EditText? = findViewById(R.id.clientId) + + val logoTypeRadioGroup = findViewById(R.id.logoTypeRadioGroup) + logoTypeRadioGroup.setOnCheckedChangeListener { _, checkedId -> + logoType = when (checkedId) { + R.id.stylePrimary -> PayPalMessageLogoType.PRIMARY + R.id.styleInline -> PayPalMessageLogoType.INLINE + R.id.styleAlternative -> PayPalMessageLogoType.ALTERNATIVE + R.id.styleNone -> PayPalMessageLogoType.NONE + else -> PayPalMessageLogoType.PRIMARY + } + } + + val colorRadioGroup = findViewById(R.id.colorRadioGroup) + colorRadioGroup.setOnCheckedChangeListener { _, checkedId -> + color = when (checkedId) { + R.id.styleBlack -> PayPalMessageColor.BLACK + R.id.styleWhite -> PayPalMessageColor.WHITE + R.id.styleMonochrome -> PayPalMessageColor.MONOCHROME + R.id.styleGrayscale -> PayPalMessageColor.GRAYSCALE + else -> PayPalMessageColor.BLACK + } + } + + val alignmentRadioGroup = findViewById(R.id.alignmentRadioGroup) + alignmentRadioGroup.setOnCheckedChangeListener { _, checkedId -> + alignment = when (checkedId) { + R.id.styleLeft -> PayPalMessageAlign.LEFT + R.id.styleCenter -> PayPalMessageAlign.CENTER + R.id.styleRight -> PayPalMessageAlign.RIGHT + else -> PayPalMessageAlign.LEFT + } + } + + val shortTerm = findViewById(R.id.shortTerm) + val longTerm = findViewById(R.id.longTerm) + val payIn1 = findViewById(R.id.payIn1) + val credit = findViewById(R.id.credit) + + fun updateOfferUi (offerName: PayPalMessageOfferType?, isChecked: Boolean) { + shortTerm.isChecked = false + longTerm.isChecked = false + payIn1.isChecked = false + credit.isChecked = false + offerType = null + + if ( offerName == PayPalMessageOfferType.PAY_LATER_SHORT_TERM && isChecked) { + shortTerm.isChecked = true + offerType = PayPalMessageOfferType.PAY_LATER_SHORT_TERM + } else if ( offerName == PayPalMessageOfferType.PAY_LATER_LONG_TERM && isChecked) { + longTerm.isChecked = true + offerType = PayPalMessageOfferType.PAY_LATER_LONG_TERM + } else if ( offerName == PayPalMessageOfferType.PAY_LATER_PAY_IN_1 && isChecked) { + payIn1.isChecked = true + offerType = PayPalMessageOfferType.PAY_LATER_PAY_IN_1 + } else if ( offerName == PayPalMessageOfferType.PAYPAL_CREDIT_NO_INTEREST && isChecked) { + credit.isChecked = true + offerType = PayPalMessageOfferType.PAYPAL_CREDIT_NO_INTEREST + } + + payPalMessage.setOfferType(offerType = offerType) + + } + + shortTerm.setOnCheckedChangeListener { _, isChecked -> + updateOfferUi(PayPalMessageOfferType.PAY_LATER_SHORT_TERM, isChecked) + } + longTerm.setOnCheckedChangeListener { _, isChecked -> + updateOfferUi(PayPalMessageOfferType.PAY_LATER_LONG_TERM, isChecked) + } + payIn1.setOnCheckedChangeListener { _, isChecked -> + updateOfferUi(PayPalMessageOfferType.PAY_LATER_PAY_IN_1, isChecked) + } + credit.setOnCheckedChangeListener { _, isChecked -> + updateOfferUi(PayPalMessageOfferType.PAYPAL_CREDIT_NO_INTEREST, isChecked) + } + + val amount = findViewById(R.id.amount) + val buyerCountry = findViewById(R.id.buyerCountry) + val stageTag = findViewById(R.id.stageTag) + + + val ignoreCache = findViewById(R.id.ignoreCache) + val devTouchpoint = findViewById(R.id.devTouchpoint) + + // Get the data from the selected options + fun updateMessageData() { + Api.devTouchpoint = devTouchpoint.isChecked + Api.ignoreCache = ignoreCache.isChecked + + if ( editedClientId?.text.toString().isNotBlank() ) { + payPalMessage.setClientId(editedClientId?.text.toString()) + } else { + payPalMessage.setClientId("") + } + + if ( amount?.text.toString().isNotBlank() ) { + payPalMessage.setAmount(amount?.text.toString().toDouble()) + } else { + payPalMessage.setAmount(null) + } + if ( buyerCountry?.text.toString().isNotBlank() ) { + payPalMessage.setBuyerCountry(buyerCountry?.text.toString()) + } else { + payPalMessage.setBuyerCountry("US") + } + + if ( color === PayPalMessageColor.WHITE ) { + payPalMessage.setBackgroundColor(Color.Black.hashCode()) + } else { + payPalMessage.setBackgroundColor(Color.White.hashCode()) + } + + if ( stageTag?.text.toString().isNotBlank() ) { + Api.stageTag = stageTag?.text.toString() + } else { + Api.stageTag = null + } + + payPalMessage.setStyle(PayPalMessageStyle(textAlign = alignment, color = color, logoType = logoType)) + payPalMessage.refresh() + } + + // Restore default options + val resetButton = findViewById