diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6294a70..9e3f5d3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,6 +24,8 @@ jobs: exit 1 - name: Run test run: ./gradlew test + - name: Run lint + run: ./gradlew lint - name: Create release in artifactory env: REPOSITORY_USERNAME: ${{ secrets.REPOSITORY_USERNAME }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9d85ec1..8e9df7f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,5 +12,7 @@ jobs: java-version: 17 - name: Run test run: ./gradlew test + - name: Run lint + run: ./gradlew lint - name: Run build run: ./gradlew assembleDebug diff --git a/.java-version b/.java-version new file mode 100644 index 0000000..98d9bcb --- /dev/null +++ b/.java-version @@ -0,0 +1 @@ +17 diff --git a/app/build.gradle b/app/build.gradle index 5c807bb..3545168 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,6 +26,11 @@ android { namespace 'com.payu.android.front.sdk.frontsdk' } + +kotlin { + jvmToolchain(project.javaVersion) +} + dependencies { implementation "androidx.fragment:fragment:$fragmentVersion" @@ -43,10 +48,10 @@ dependencies { kapt "com.github.bumptech.glide:compiler:$project.glideVersion" // Dagger - kapt "com.google.dagger:dagger-compiler:2.50" - kapt "com.google.dagger:dagger-android-processor:2.50" - implementation "com.google.dagger:dagger:2.50" - implementation "com.google.dagger:dagger-android-support:2.50" + kapt "com.google.dagger:dagger-compiler:$project.daggerVersion" + kapt "com.google.dagger:dagger-android-processor:$project.daggerVersion" + implementation "com.google.dagger:dagger:$project.daggerVersion" + implementation "com.google.dagger:dagger-android-support:$project.daggerVersion" // RxJava implementation 'io.reactivex.rxjava2:rxjava:2.2.8' @@ -66,7 +71,6 @@ dependencies { implementation project(path: ':payment-library-webview-module') implementation project(path: ':payment-library-google-pay-module') implementation project(path: ':payment-library-google-pay-adapter') - implementation project(path: ':payment-installments') implementation project(path: ':marketplace-terms-condition') testImplementation "junit:junit:$project.junitVersion" diff --git a/app/src/main/java/com/payu/android/front/sdk/demo/config/PaymentMethodsProvider.kt b/app/src/main/java/com/payu/android/front/sdk/demo/config/PaymentMethodsProvider.kt index 66ff3d4..1b872ef 100644 --- a/app/src/main/java/com/payu/android/front/sdk/demo/config/PaymentMethodsProvider.kt +++ b/app/src/main/java/com/payu/android/front/sdk/demo/config/PaymentMethodsProvider.kt @@ -8,9 +8,6 @@ import com.payu.android.front.sdk.demo.repository.InstallmentRepository import com.payu.android.front.sdk.demo.repository.PaymentMethodsRepository import com.payu.android.front.sdk.demo.repository.PersistentRepository import com.payu.android.front.sdk.demo.ui.login.LoginActivity -import com.payu.android.front.sdk.payment_library_core.external.listener.InstallmentCallback -import com.payu.android.front.sdk.payment_library_core.external.model.Installment -import com.payu.android.front.sdk.payment_library_core.external.model.InstallmentOption import com.payu.android.front.sdk.payment_library_payment_chooser.payment_method.external.listener.PaymentMethodsCallback import com.payu.android.front.sdk.payment_library_payment_chooser.payment_method.external.listener.PosIdListener import com.payu.android.front.sdk.payment_library_payment_chooser.payment_method.internal.providers.PaymentMethodActions @@ -79,49 +76,4 @@ class PaymentMethodsProvider(context: Context) : PaymentMethodActions(context) { } ) } - - override fun provideInstallments(callback: InstallmentCallback) { - val disposable = installmentRepository.getInstallmentOption(persistenceRepository.proposalId) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe( - { - if (it.installmentDecision != null) { - //merchant could display an information regarding this flow - println("Installment previously taken: $it") - return@subscribe - } - - val installmentList: ArrayList = ArrayList() - it.installmentOptions.forEach { item -> - installmentList.add( - InstallmentOption.Builder() - .withId(item.id) - .withFirstInstallments(item.firstInstallmentAmount ?: 0) - .withNumberOfInstallments(item.numberOfInstallments ?: 0) - .withTotalValue(item.totalAmountDue) - .withAnnualPercentageRate(item.annualPercentageRate) - .withInstallmentAmount(item.installmentAmount ?: 0) - .withInstallmentFeeAmount(item.installmentFeeAmount) - .withInterestRate(item.interestRate) - .build() - ) - - } - - val installment: Installment = Installment.Builder() - .withCurrency(it.currencyCode) - .withProposalId(persistenceRepository.proposalId) - .withInstallmentType(it.installmentOptionFormat) - .withInstallmentOptionList(installmentList) - .withMaxNumberOfInstallments(it.maxNumberOfInstallments ?: 0) - .withMinNumberOfInstallments(it.minNumberOfInstallments ?: 0) - .build() - callback.onFetched(installment) - - }, { - println("Error during fetching installments: $it") - }) - - } } diff --git a/app/src/main/java/com/payu/android/front/sdk/demo/ui/samples/WebPaymentDemoActivity.kt b/app/src/main/java/com/payu/android/front/sdk/demo/ui/samples/WebPaymentDemoActivity.kt index e228cfc..18d0b42 100644 --- a/app/src/main/java/com/payu/android/front/sdk/demo/ui/samples/WebPaymentDemoActivity.kt +++ b/app/src/main/java/com/payu/android/front/sdk/demo/ui/samples/WebPaymentDemoActivity.kt @@ -2,6 +2,7 @@ package com.payu.android.front.sdk.demo.ui.samples import android.content.Intent import android.os.Bundle +import android.os.Build import androidx.appcompat.app.AppCompatActivity import com.payu.android.front.sdk.payment_library_core_android.events.AuthorizationDetails import com.payu.android.front.sdk.payment_library_webview_module.web.event.PaymentDetails @@ -21,8 +22,12 @@ class WebPaymentDemoActivity : AppCompatActivity() { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { if (requestCode == WebPaymentService.REQUEST_CODE) { - val paymentDetails: PaymentDetails? = data?.getParcelableExtra(WebPaymentService.INTENT_WEB_PAYMENT_EXTRA) - + val paymentDetails: PaymentDetails? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + data?.getParcelableExtra(WebPaymentService.INTENT_WEB_PAYMENT_EXTRA, PaymentDetails::class.java) + } else { + @Suppress("DEPRECATION") + data?.getParcelableExtra(WebPaymentService.INTENT_WEB_PAYMENT_EXTRA) + } println(paymentDetails.toString()) finish() } else { diff --git a/app/src/main/java/com/payu/android/front/sdk/demo/ui/summary/RollSummaryActivity.kt b/app/src/main/java/com/payu/android/front/sdk/demo/ui/summary/RollSummaryActivity.kt index 24fd198..d4671f8 100644 --- a/app/src/main/java/com/payu/android/front/sdk/demo/ui/summary/RollSummaryActivity.kt +++ b/app/src/main/java/com/payu/android/front/sdk/demo/ui/summary/RollSummaryActivity.kt @@ -2,6 +2,7 @@ package com.payu.android.front.sdk.demo.ui.summary import android.app.Activity import android.content.Intent +import android.os.Build import android.os.Bundle import android.util.Log import android.view.View @@ -9,7 +10,6 @@ import android.widget.Toast import androidx.annotation.StringRes import androidx.databinding.DataBindingUtil import androidx.lifecycle.Observer -import com.payu.android.front.sdk.demo.api.model.installments.InstallmentSelected import com.payu.android.front.sdk.demo.model.RollModel import com.payu.android.front.sdk.demo.ui.base.ActivityWithMenu import com.payu.android.front.sdk.demo.ui.login.LoginActivity @@ -17,12 +17,8 @@ import com.payu.android.front.sdk.demo.ui.main.BUNDLE_DATA import com.payu.android.front.sdk.frontsdk.R import com.payu.android.front.sdk.frontsdk.databinding.ActivityRollSummaryBinding import com.payu.android.front.sdk.payment_add_card_module.service.CvvValidationService -import com.payu.android.front.sdk.payment_installments.mastercard.offer.model.SelectedInstallment -import com.payu.android.front.sdk.payment_installments.mastercard.offer.view.OfferInstallmentsActivity import com.payu.android.front.sdk.payment_library_card_scanner.scanner.pay.card.PayCardScanner -import com.payu.android.front.sdk.payment_library_core.external.model.InstallmentType import com.payu.android.front.sdk.payment_library_core_android.events.AuthorizationDetails -import com.payu.android.front.sdk.payment_library_core_android.events.PaymentAuthorization import com.payu.android.front.sdk.payment_library_google_pay_adapter.GooglePayAdapter import com.payu.android.front.sdk.payment_library_google_pay_module.builder.Cart import com.payu.android.front.sdk.payment_library_google_pay_module.model.Currency @@ -52,7 +48,13 @@ class RollSummaryActivity : ActivityWithMenu() { } private fun populateData() { - val rollModel = intent.getParcelableExtra(BUNDLE_DATA) + val rollModel: RollModel? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + intent.getParcelableExtra(BUNDLE_DATA, RollModel::class.java) + } else { + @Suppress("DEPRECATION") + intent.getParcelableExtra(BUNDLE_DATA) + } + viewModel.rollModel = rollModel viewModel.paymentChooserController = getPaymentChooserController() @@ -96,12 +98,6 @@ class RollSummaryActivity : ActivityWithMenu() { }) } - private fun observeInstallmentAlreadyTaken() { - viewModel.installmentAlreadyTaken.observe(this, { - Toast.makeText(this, getString(R.string.installment_taken), Toast.LENGTH_SHORT).show() - }) - } - private fun observeMessageSuccessEvent() { viewModel.paymentSuccessEvent.observe(this, Observer { messageStringRes -> messageStringRes?.let { showSuccess(it) } @@ -132,12 +128,6 @@ class RollSummaryActivity : ActivityWithMenu() { }) } - private fun observeInstallmentEvent() { - viewModel.installmentProposalEvent.observe(this, { - OfferInstallmentsActivity.startForResult(this) - }) - } - private fun observePaymentEvent() { viewModel.paymentEvent.observe(this, Observer { authorizationDetails -> authorizationDetails?.let { WebPaymentService.pay(this, it) } @@ -166,17 +156,18 @@ class RollSummaryActivity : ActivityWithMenu() { private fun showSuccess(message: String) { showToast(message) - binding.success.postDelayed({ - binding.success.visibility = View.VISIBLE - }, 1 + binding.success.postDelayed( + { + binding.success.visibility = View.VISIBLE + }, 1 ) binding.success.postDelayed( - { - binding.success.visibility = View.GONE - viewModel.showProgress.set(false) - }, - 2000 + { + binding.success.visibility = View.GONE + viewModel.showProgress.set(false) + }, + 2000 ) } @@ -188,19 +179,19 @@ class RollSummaryActivity : ActivityWithMenu() { showToast(message) binding.error.visibility = View.VISIBLE binding.error.postDelayed( - { - binding.error.visibility = View.GONE - viewModel.showProgress.set(false) - }, - 2000 + { + binding.error.visibility = View.GONE + viewModel.showProgress.set(false) + }, + 2000 ) } private fun createCart() = viewModel.rollModel?.rollPrice?.let { price -> Cart.Builder() - .withTotalPrice(price) - .withCurrency(Currency.PLN) - .build() + .withTotalPrice(price) + .withCurrency(Currency.PLN) + .build() } ?: Cart.Builder().build() private fun handlePaymentResult(requestCode: Int, data: Intent, resultCode: Int) { @@ -213,17 +204,11 @@ class RollSummaryActivity : ActivityWithMenu() { showToast(getString(R.string.payment_blik_ambiguity, it.toString())) } } - GooglePayService.REQUEST_CODE_GOOGLE_PAY_PAYMENT -> handleGooglePayResult(resultCode, data) - //TODO: create a service for it - OfferInstallmentsActivity.INSTALLMENT_REQUEST_CODE -> { - val selectedInstallment: SelectedInstallment = data.getParcelableExtra(OfferInstallmentsActivity.INSTALLMENT_KEY)!! - val installmentSelected: InstallmentSelected = - if (selectedInstallment.installmentType == InstallmentType.OPTIONS.toString()) - InstallmentSelected(selectedInstallment.id) - else InstallmentSelected(numberOfInstallments = selectedInstallment.id.toInt()) - viewModel.requestInstallment(installmentSelected, selectedInstallment.proposalId!!) - Toast.makeText(this, "Installment finished", Toast.LENGTH_SHORT).show() - } + + GooglePayService.REQUEST_CODE_GOOGLE_PAY_PAYMENT -> handleGooglePayResult( + resultCode, + data + ) } } @@ -236,19 +221,21 @@ class RollSummaryActivity : ActivityWithMenu() { showToast(R.string.payment_status_warning_continue_cvv) handleCvvValidation(paymentDetails.continuePaymentUrl.get()) } + WebPaymentStatus.CANCEL_PAYMENT -> showError(R.string.payment_cancel) WebPaymentStatus.PAYMENT_ERROR, WebPaymentStatus.SSL_VALIDATION_ERROR -> showError(R.string.payment_status_error) + else -> showError(R.string.payment_status_error) } } private fun handleCvvValidation(cvvPaymentUrl: String) { CvvValidationService.validateCvv( - supportFragmentManager, - AuthorizationDetails.Builder() - .withLink(cvvPaymentUrl) - .build() + supportFragmentManager, + AuthorizationDetails.Builder() + .withLink(cvvPaymentUrl) + .build() ) { showSuccess("Cvv validation completed!") } } @@ -260,14 +247,17 @@ class RollSummaryActivity : ActivityWithMenu() { viewModel.createOrder(it, googlePayTokenResponse?.googlePayToken) } } + Activity.RESULT_CANCELED -> { //User has canceled payment showError("Payment canceled") } + GooglePayService.RESULT_ERROR -> { val status = googlePayService.handleGooglePayErrorStatus(data) showError(status.errorMessage ?: "GooglePay Error") } + else -> showError("Payment process has failed for the user") } } @@ -289,9 +279,7 @@ class RollSummaryActivity : ActivityWithMenu() { observeGooglePayEvent() observeBlikAmbiguityEvent() observePaymentEvent() - observeInstallmentEvent() observePaymentMethodChange() - observeInstallmentAlreadyTaken() //for 3DS SoftAccept Test retrieveStatusFromSoftAccept() @@ -312,10 +300,21 @@ class RollSummaryActivity : ActivityWithMenu() { } fun retrieveStatusFromSoftAccept() { - supportFragmentManager.setFragmentResultListener(SoftAcceptService.KEY_REQUEST_BUNDLE, this, { _, bundle -> - val result = bundle.getParcelable(SoftAcceptService.KEY_SOFT_ACCEPT_RESPONSE_DETAIL) - Log.v("SoftAcceptTest", "Response with: " + result?.softAcceptTransactionStatus.toString()) + supportFragmentManager.setFragmentResultListener( + SoftAcceptService.KEY_REQUEST_BUNDLE, + this, + { _, bundle -> + val result: SoftAcceptTransactionDetail? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + bundle.getParcelable(SoftAcceptService.KEY_SOFT_ACCEPT_RESPONSE_DETAIL, SoftAcceptTransactionDetail::class.java) + } else { + @Suppress("DEPRECATION") + bundle.getParcelable(SoftAcceptService.KEY_SOFT_ACCEPT_RESPONSE_DETAIL) + } + Log.v( + "SoftAcceptTest", + "Response with: " + result?.softAcceptTransactionStatus.toString() + ) - }); + }); } } diff --git a/build.gradle b/build.gradle index 2578f65..fa746bf 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.7.22' + ext.kotlin_version = '2.0.21' repositories { mavenCentral() @@ -9,10 +9,10 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:8.0.2' + classpath 'com.android.tools.build:gradle:8.8.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.33.12" + classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.33.23" } } @@ -26,7 +26,7 @@ allprojects { } tasks.register('clean', Delete) { - delete rootProject.buildDir + delete rootProject.layout.buildDirectory } tasks.register("version") { @@ -35,40 +35,40 @@ tasks.register("version") { project.ext { //libraries - guavaVersion = "33.0.0-android" + guavaVersion = "33.4.0-android" appCompatVersion = "1.5.1" - recyclerViewVersion = "1.2.1" - annotationVersion = "1.1.0" + recyclerViewVersion = "1.3.2" + annotationVersion = "1.9.1" materialVersion = "1.1.0" - espressoVersion = "3.1.0" - constraintLayoutVersion = "2.1.4" - robolectricVersion = "4.9" + espressoVersion = "3.6.1" + constraintLayoutVersion = "2.2.0" + robolectricVersion = "4.14.1" glideVersion = "4.16.0" architectureComponentsCoreVersion = "2.0.0" lifecycleComponentVersion = "2.4.1" - gsonVersion = "2.8.6" - retrofit2Version = "2.9.0" - okhttpLogInterceptorVersion = "4.8.0" - playServicesVersion = "18.0.0" + gsonVersion = "2.11.0" + retrofit2Version = "2.11.0" + okhttpLogInterceptorVersion = "4.12.0" + playServicesVersion = "19.4.0" cardsPayVersion = "1.0.2" - fragmentVersion = '1.5.2' - androidxActivityVersion = '1.5.1' - rxJava3 = '3.0.13' - rxJava3Android = '3.0.0' + fragmentVersion = '1.8.5' + rxJava3 = '3.1.10' + rxJava3Android = '3.0.2' + daggerVersion = '2.55' // testing junitVersion = "4.13.2" junitDataproviderVersion = "2.10" - junitAssertionsVersion = "1.1.5" - assertJsVersion = "3.24.2" - assertJGuavaVersion = "3.24.2" - mockitoVersion = "5.8.0" + junitAssertionsVersion = "1.2.1" + assertJsVersion = "3.27.2" + mockitoVersion = "5.15.2" } project.ext { //android configuration - compileSdkVersion = 33 - targetSdkVersion = 33 + javaVersion = 17 + compileSdkVersion = 35 + targetSdkVersion = 35 minSdkVersion = 21 versionCode = 6 versionName = "1.0.30" diff --git a/gradle.properties b/gradle.properties index 19a455b..bc926eb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,10 +14,6 @@ android.useAndroidX=true org.gradle.jvmargs=-Xmx4608m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 android.jetifier.ignorelist=bcprov-jdk15on -Xjvm-default=enable -android.defaults.buildfeatures.buildconfig=true +kotlin.code.style=official android.nonTransitiveRClass=false android.nonFinalResIds=false -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b73be3f..6e22938 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Sat Oct 15 22:38:33 CEST 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/marketplace-terms-condition/build.gradle b/marketplace-terms-condition/build.gradle index 797eb1b..5614715 100644 --- a/marketplace-terms-condition/build.gradle +++ b/marketplace-terms-condition/build.gradle @@ -33,6 +33,10 @@ android { namespace 'com.payu.android.front.sdk.marketplace_terms_condition' } +kotlin { + jvmToolchain(project.javaVersion) +} + dependencies { implementation project(path: ':payment-library-core-android') diff --git a/payment-installments/.gitignore b/payment-installments/.gitignore deleted file mode 100644 index 42afabf..0000000 --- a/payment-installments/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/payment-installments/build.gradle b/payment-installments/build.gradle deleted file mode 100644 index ffeab82..0000000 --- a/payment-installments/build.gradle +++ /dev/null @@ -1,50 +0,0 @@ -project.ext { - name = "payment-library-installments" - fileExtension = "aar" -} - -apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-parcelize' -apply from: "../artifactory/release.gradle" - -android { - compileSdk project.compileSdkVersion - - defaultConfig { - minSdkVersion project.minSdkVersion - targetSdkVersion project.targetSdkVersion - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - testOptions { - unitTests { - includeAndroidResources = true - } - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - namespace 'com.payu.android.front.sdk.payment_installments' -} - -dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib:$project.kotlin_version" - implementation "com.google.android.material:material:$project.materialVersion" - implementation "androidx.constraintlayout:constraintlayout:$project.constraintLayoutVersion" - implementation "androidx.appcompat:appcompat:$project.appCompatVersion" - implementation "androidx.activity:activity-ktx:$project.androidxActivityVersion" - - implementation "androidx.recyclerview:recyclerview:$project.recyclerViewVersion" - implementation "com.google.guava:guava:$project.guavaVersion" - implementation "com.github.bumptech.glide:glide:$project.glideVersion" - implementation project(path: ':payment-library-core-android') - implementation project(path: ':payment-library-api-client') - implementation project(path: ':payment-library-chooser-module') - implementation project(path: ':payment-add-card-module') - annotationProcessor "com.github.bumptech.glide:compiler:$project.glideVersion" -} \ No newline at end of file diff --git a/payment-installments/consumer-rules.pro b/payment-installments/consumer-rules.pro deleted file mode 100644 index e69de29..0000000 diff --git a/payment-installments/proguard-rules.pro b/payment-installments/proguard-rules.pro deleted file mode 100644 index 481bb43..0000000 --- a/payment-installments/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/payment-installments/src/main/AndroidManifest.xml b/payment-installments/src/main/AndroidManifest.xml deleted file mode 100644 index 1494fa2..0000000 --- a/payment-installments/src/main/AndroidManifest.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/adapter/RowInstallmentAdapter.kt b/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/adapter/RowInstallmentAdapter.kt deleted file mode 100644 index 1de0a6a..0000000 --- a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/adapter/RowInstallmentAdapter.kt +++ /dev/null @@ -1,79 +0,0 @@ -package com.payu.android.front.sdk.payment_installments.mastercard.offer.adapter - -import android.content.Context -import android.graphics.Typeface -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.ImageView -import android.widget.TextView -import androidx.appcompat.content.res.AppCompatResources -import androidx.core.graphics.drawable.DrawableCompat -import androidx.recyclerview.widget.RecyclerView -import com.payu.android.front.sdk.payment_installments.R -import com.payu.android.front.sdk.payment_installments.mastercard.offer.model.InstallmentAdapterCell -import com.payu.android.front.sdk.payment_library_core.external.model.InstallmentType -import com.payu.android.front.sdk.payment_library_core.translation.Translation -import com.payu.android.front.sdk.payment_library_core.translation.TranslationKey -import com.payu.android.front.sdk.payment_library_core_android.styles.TextViewStyle -import com.payu.android.front.sdk.payment_library_core_android.styles.model.LibraryStyleInfo -import com.payu.android.front.sdk.payment_library_core_android.styles.model.TextStyleInfo -import com.payu.android.front.sdk.payment_library_core_android.styles.providers.FontProvider - -class RowInstallmentAdapter(private val installmentList: List, - private val listener: (InstallmentAdapterCell) -> Unit, - private val libraryStyle: LibraryStyleInfo, - private val translations: Translation, - private val context: Context) : - RecyclerView.Adapter() { - - class RowInstallmentViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - - - fun bindItem(installment: InstallmentAdapterCell, - libraryStyle: LibraryStyleInfo, - translations: Translation, - context: Context) { - val imageView = itemView.findViewById(R.id.row_installments_image) - val unwrappedDrawable = AppCompatResources.getDrawable(context, R.drawable.baseline_date_range_black_24dp) - val wrappedDrawable = DrawableCompat.wrap(unwrappedDrawable!!) - DrawableCompat.setTint(wrappedDrawable, libraryStyle.accentColor) - - imageView.setImageDrawable(wrappedDrawable) - - val subtitle = itemView.findViewById(R.id.row_installments_number_text) - subtitle.text = installment.formatSubtitle(translations.translate(TranslationKey.CHOOSE_INSTALLMENTS_LIST_SUBTITLE_SINGULAR), - translations.translate(TranslationKey.CHOOSE_INSTALLMENTS_LIST_SUBTITLE_PLURAL), - translations.translate(TranslationKey.CHOOSE_INSTALLMENTS_LIST_SUBTITLE_MANY) - ) - subtitle.setTypeface(subtitle.typeface, Typeface.BOLD) - createStyleFromInfo(libraryStyle.textStyleTitle, context).applyTo(subtitle) - - val additionalText = if (installment.installmentType == InstallmentType.OPTIONS) translations.translate(TranslationKey.CHOOSE_INSTALLMENTS_LIST_1ST_INSTALLMENT) else "" - - itemView.findViewById(R.id.row_installments_one_text).text = installment.formatTopBody(additionalText) - itemView.findViewById(R.id.row_installments_total_text).text = installment.formatLowerBody(translations.translate(TranslationKey.CHOOSE_INSTALLMENTS_LIST_TOTAL_INSTALLMENTS)) - } - - private fun createStyleFromInfo(styleInfo: TextStyleInfo?, context: Context): TextViewStyle { - return TextViewStyle(styleInfo, FontProvider(context)) - } - - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RowInstallmentViewHolder { - val layoutInflater = LayoutInflater.from(parent.context) - val inflate: View = layoutInflater.inflate(R.layout.row_installment, parent, false) - return RowInstallmentViewHolder(inflate) - - } - - override fun onBindViewHolder(holder: RowInstallmentViewHolder, position: Int) { - holder.bindItem(installmentList[position], libraryStyle, translations, context) - holder.itemView.setOnClickListener { listener(installmentList[position]) } - } - - override fun getItemCount(): Int { - return installmentList.size - } -} \ No newline at end of file diff --git a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/event/SingleLiveEvent.kt b/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/event/SingleLiveEvent.kt deleted file mode 100644 index dceb305..0000000 --- a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/event/SingleLiveEvent.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.payu.android.front.sdk.payment_installments.mastercard.offer.event - -import androidx.annotation.MainThread -import androidx.lifecycle.LifecycleOwner -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.Observer -import java.util.concurrent.atomic.AtomicBoolean - -/** - * A lifecycle-aware observable that sends only new updates after subscription, used for events like - * navigation and Snackbar messages. - * - * - * This avoids a common problem with events: on configuration change (like rotation) an update - * can be emitted if the observer is active. This LiveData only calls the observable if there's an - * explicit call to setValue() or call(). - * - * - * Note that only one observer is going to be notified of changes. - */ -open class SingleLiveEvent : MutableLiveData() { - - private val mPending = AtomicBoolean(false) - - @MainThread - override fun observe(owner: LifecycleOwner, observer: Observer) { - // Observe the internal MutableLiveData - super.observe(owner, Observer { t -> - if (mPending.compareAndSet(true, false)) { - observer.onChanged(t) - } - }) - } - - @MainThread - override fun setValue(t: T?) { - mPending.set(true) - super.setValue(t) - } -} \ No newline at end of file diff --git a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/model/InstallmentAdapterCell.kt b/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/model/InstallmentAdapterCell.kt deleted file mode 100644 index c1bad72..0000000 --- a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/model/InstallmentAdapterCell.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.payu.android.front.sdk.payment_installments.mastercard.offer.model - -import android.text.Spanned -import com.payu.android.front.sdk.payment_library_core.external.model.InstallmentType -import java.text.DecimalFormat - -abstract class InstallmentAdapterCell(val installmentType: InstallmentType, val numberOfInstallments: Int, - val totalValue: Float, val currency: String) { - private val patternDisplayValue = "#0.00" - private val singularInstallmentValue = 1 - private val pluralInstallmentValue = 4 - - abstract fun formatTopBody(additionalText: String): Spanned - abstract fun getId(): String - - fun formatSubtitle(singleInstallment: String, pluralInstallment: String, otherInstallment: String): String = when { - numberOfInstallments == singularInstallmentValue -> "$numberOfInstallments $singleInstallment" - numberOfInstallments <= pluralInstallmentValue -> "$numberOfInstallments $pluralInstallment" - else -> "$numberOfInstallments $otherInstallment" - - } - - fun formatLowerBody(leadingText: String): String = - leadingText + " " + formatValue(totalValue) + " " + currency - - - protected fun formatValue(value: Float): String = DecimalFormat(patternDisplayValue).format(value) -} \ No newline at end of file diff --git a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/model/InstallmentAdapterInstallment.kt b/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/model/InstallmentAdapterInstallment.kt deleted file mode 100644 index 5f5e29d..0000000 --- a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/model/InstallmentAdapterInstallment.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.payu.android.front.sdk.payment_installments.mastercard.offer.model - -import android.text.Html -import android.text.Spanned -import com.payu.android.front.sdk.payment_library_core.external.model.InstallmentType - -class InstallmentAdapterInstallment(private val interestRate: Float, numberOfInstallments: Int, totalValue: Float, currency: String) : - InstallmentAdapterCell(InstallmentType.INSTALLMENT, numberOfInstallments, totalValue, currency) { - - override fun formatTopBody(additionalText: String): Spanned { - val formattedValue = formatValue(interestRate) - val sourceString = " $formattedValue%" - return Html.fromHtml(additionalText + sourceString) - } - - override fun getId(): String { - return numberOfInstallments.toString() - } -} \ No newline at end of file diff --git a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/model/InstallmentAdapterOptions.kt b/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/model/InstallmentAdapterOptions.kt deleted file mode 100644 index 1e03ca0..0000000 --- a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/model/InstallmentAdapterOptions.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.payu.android.front.sdk.payment_installments.mastercard.offer.model - -import android.text.Html -import android.text.Spanned -import com.payu.android.front.sdk.payment_library_core.external.model.InstallmentType - -class InstallmentAdapterOptions(private val optionsId: String, - private val installmentValue: Float, numberOfInstallments: Int, - totalValue: Float, currency: String) : - InstallmentAdapterCell(InstallmentType.OPTIONS, numberOfInstallments, totalValue, currency) { - - override fun formatTopBody(additionalText: String): Spanned { - val formattedValue = formatValue(installmentValue) - val sourceString = " $formattedValue $currency" - return Html.fromHtml(additionalText + sourceString) - } - - override fun getId(): String { - return optionsId - } - -} \ No newline at end of file diff --git a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/model/SelectedInstallment.kt b/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/model/SelectedInstallment.kt deleted file mode 100644 index 7a79486..0000000 --- a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/model/SelectedInstallment.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.payu.android.front.sdk.payment_installments.mastercard.offer.model - -import android.os.Parcelable -import kotlinx.parcelize.Parcelize - -@Parcelize -class SelectedInstallment(val id: String, val installmentType: String, val proposalId: String?) : Parcelable \ No newline at end of file diff --git a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/repository/InstallmentRepository.kt b/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/repository/InstallmentRepository.kt deleted file mode 100644 index cd06bc7..0000000 --- a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/repository/InstallmentRepository.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.payu.android.front.sdk.payment_installments.mastercard.offer.repository - -import androidx.lifecycle.MutableLiveData -import com.payu.android.front.sdk.payment_library_core.external.listener.InstallmentCallback -import com.payu.android.front.sdk.payment_library_core.external.model.Installment -import com.payu.android.front.sdk.payment_library_payment_chooser.payment_method.internal.providers.PaymentMethodActions - -class InstallmentRepository(private val paymentMethodActions: PaymentMethodActions) : InstallmentCallback { - private val localInstallment = MutableLiveData() - override fun onFetched(installment: Installment?) { - localInstallment.postValue(installment) - } - - fun getInstallment(): MutableLiveData { - if (localInstallment.value == null) { - paymentMethodActions.provideInstallments(this) - } - return localInstallment - } -} \ No newline at end of file diff --git a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/util/InstallmentMapper.kt b/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/util/InstallmentMapper.kt deleted file mode 100644 index 963e15c..0000000 --- a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/util/InstallmentMapper.kt +++ /dev/null @@ -1,29 +0,0 @@ -import com.payu.android.front.sdk.payment_installments.mastercard.offer.model.InstallmentAdapterCell -import com.payu.android.front.sdk.payment_installments.mastercard.offer.model.InstallmentAdapterInstallment -import com.payu.android.front.sdk.payment_installments.mastercard.offer.model.InstallmentAdapterOptions -import com.payu.android.front.sdk.payment_library_core.external.model.CurrencyHelper -import com.payu.android.front.sdk.payment_library_core.external.model.InstallmentType - -//TODO: documentation -fun mapDataFromApp(installment: com.payu.android.front.sdk.payment_library_core.external.model.Installment): List { - val installmentList = arrayListOf() - - installment.installmentOptionList.forEach { item -> - if (installment.type == InstallmentType.OPTIONS) { - installmentList.add(InstallmentAdapterOptions(item.id, divideCurrency(item.firstInstallmentValue), - item.numberOfInstallments, - divideCurrency(item.totalValue), - CurrencyHelper.getCurrencySymbol(installment.currency))) - } else { - for (numberOfInstallment in installment.minNumberOfInstallments..installment.maxNumberOfInstallments) { - installmentList.add(InstallmentAdapterInstallment(item.interestRate, numberOfInstallment, - divideCurrency(item.totalValue), CurrencyHelper.getCurrencySymbol(installment.currency))) - } - } - } - return installmentList -} - -private fun divideCurrency(value: Float): Float { - return value / 100.00f; -} \ No newline at end of file diff --git a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/view/ChooseInstallmentsActivity.kt b/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/view/ChooseInstallmentsActivity.kt deleted file mode 100644 index 83cfc34..0000000 --- a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/view/ChooseInstallmentsActivity.kt +++ /dev/null @@ -1,129 +0,0 @@ -package com.payu.android.front.sdk.payment_installments.mastercard.offer.view - -import android.app.Activity -import android.content.Intent -import android.os.Bundle -import android.view.View -import android.widget.Button -import android.widget.ImageView -import android.widget.TextView -import androidx.appcompat.widget.Toolbar -import androidx.lifecycle.ViewModelProvider -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.bumptech.glide.Glide -import com.payu.android.front.sdk.payment_add_card_module.issuer.CardIssuer -import com.payu.android.front.sdk.payment_installments.R -import com.payu.android.front.sdk.payment_installments.mastercard.offer.adapter.RowInstallmentAdapter -import com.payu.android.front.sdk.payment_installments.mastercard.offer.model.SelectedInstallment -import com.payu.android.front.sdk.payment_installments.mastercard.offer.view.OfferInstallmentsActivity.Companion.INSTALLMENT_KEY -import com.payu.android.front.sdk.payment_installments.mastercard.offer.view.OfferInstallmentsActivity.Companion.INSTALLMENT_REQUEST_CODE -import com.payu.android.front.sdk.payment_installments.mastercard.offer.viewmodel.ChooseInstallmentsViewModel -import com.payu.android.front.sdk.payment_installments.mastercard.offer.viewmodel.ChooseInstallmentsViewModelFactory -import com.payu.android.front.sdk.payment_library_api_client.internal.rest.content.StaticContentUrlProvider -import com.payu.android.front.sdk.payment_library_core.translation.TranslationFactory -import com.payu.android.front.sdk.payment_library_core_android.ConfigurationEnvironmentProvider -import com.payu.android.front.sdk.payment_library_core_android.base.BaseActivity -import com.payu.android.front.sdk.payment_library_core_android.styles.ButtonStyle -import com.payu.android.front.sdk.payment_library_core_android.styles.model.LibraryStyleInfo -import com.payu.android.front.sdk.payment_library_core_android.styles.providers.LibraryStyleProvider -import mapDataFromApp - -class ChooseInstallmentsActivity : BaseActivity() { - private lateinit var viewModel: ChooseInstallmentsViewModel - private lateinit var appToolbar: Toolbar - private lateinit var toolbarTitleText: TextView - private lateinit var subTitleText: TextView - private lateinit var negativeButton: Button - private lateinit var logoImageView: ImageView - - private lateinit var libraryStyleInfo: LibraryStyleInfo - - companion object { - @JvmStatic - fun startForResult(activity: Activity) { - val intent = Intent(activity, ChooseInstallmentsActivity::class.java) - activity.startActivityForResult(intent, INSTALLMENT_REQUEST_CODE) - } - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - viewModel = ViewModelProvider(this, - ChooseInstallmentsViewModelFactory(this, StaticContentUrlProvider( - ConfigurationEnvironmentProvider.provideEnvironment(this)), - CardIssuer.MASTER_CARD, - TranslationFactory.getInstance())) - .get(ChooseInstallmentsViewModel::class.java) - - viewModel.onClickEvent.observe(this, { - setResult(RESULT_CANCELED) - finish() - }) - libraryStyleInfo = LibraryStyleProvider.fromContext(this) - translation = TranslationFactory.getInstance() - Glide.with(this).load(viewModel.provideImagePath()).into(logoImageView) - setupTranslations() - setupStyles() - setupActions() - } - - override fun provideToolbar(): Toolbar { - return appToolbar - } - - override fun bindViews() { - appToolbar = findViewById(R.id.payu_toolbar) - toolbarTitleText = findViewById(R.id.title_payu_toolbar_textView) - subTitleText = findViewById(R.id.choose_installment_subtitle_text) - negativeButton = findViewById(R.id.choose_installment_negative_button) - logoImageView = findViewById(R.id.choose_installment_logo_image) - } - - override fun getLayoutResource(): Int { - return R.layout.activity_choose_installments - } - - private fun setupTranslations() { - subTitleText.text = viewModel.provideTranslationForSubTitle() - negativeButton.text = viewModel.provideTranslationForButtonNegative() - toolbarTitleText.text = viewModel.provideTranslationForHeader() - - } - - private fun setupStyles() { - appToolbar.setBackgroundColor(libraryStyleInfo.toolbarColor) - findViewById(R.id.choose_installments_view).setBackgroundColor(libraryStyleInfo.backgroundColor) - - //buttons - ButtonStyle(libraryStyleInfo.textStyleButtonPrimary).applyTo(negativeButton) - createStyleFromInfo(libraryStyleInfo.textStyleButtonPrimary.textStyleInfo).applyTo(negativeButton) - negativeButton.setOnClickListener { viewModel.onDeclineInstallments() } - //textViews - createStyleFromInfo(libraryStyleInfo.textStyleText).applyTo(subTitleText) - createStyleFromInfo(libraryStyleInfo.textStyleTitle).applyTo(toolbarTitleText) - - - } - - private fun setupAdapter() { - val recyclerView = findViewById(R.id.choose_installment_recyclerView) - recyclerView.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) - - viewModel.installment.observe(this, { - val rowInstallmentAdapter = RowInstallmentAdapter(mapDataFromApp(it), { selectedItem -> - val intent = Intent() - intent.putExtra(INSTALLMENT_KEY, SelectedInstallment(selectedItem.getId(), - selectedItem.installmentType.toString(), it.proposalId)) - setResult(RESULT_OK, intent) - finish() - }, - libraryStyleInfo, translation, this) - recyclerView.adapter = rowInstallmentAdapter - }) - } - - private fun setupActions() { - setupAdapter() - } -} \ No newline at end of file diff --git a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/view/OfferInstallmentsActivity.kt b/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/view/OfferInstallmentsActivity.kt deleted file mode 100644 index fc1fdee..0000000 --- a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/view/OfferInstallmentsActivity.kt +++ /dev/null @@ -1,170 +0,0 @@ -package com.payu.android.front.sdk.payment_installments.mastercard.offer.view - -import android.app.Activity -import android.content.Intent -import android.os.Bundle -import android.view.View -import android.widget.Button -import android.widget.ImageView -import android.widget.TextView -import androidx.appcompat.widget.Toolbar -import androidx.lifecycle.ViewModelProvider -import com.bumptech.glide.Glide -import com.payu.android.front.sdk.payment_add_card_module.issuer.CardIssuer -import com.payu.android.front.sdk.payment_installments.R -import com.payu.android.front.sdk.payment_installments.mastercard.offer.model.SelectedInstallment -import com.payu.android.front.sdk.payment_installments.mastercard.offer.viewmodel.OfferInstallmentsViewModel -import com.payu.android.front.sdk.payment_installments.mastercard.offer.viewmodel.OfferInstallmentsViewModelFactory -import com.payu.android.front.sdk.payment_library_api_client.internal.rest.content.StaticContentUrlProvider -import com.payu.android.front.sdk.payment_library_core.translation.TranslationFactory -import com.payu.android.front.sdk.payment_library_core_android.ConfigurationEnvironmentProvider -import com.payu.android.front.sdk.payment_library_core_android.base.BaseActivity -import com.payu.android.front.sdk.payment_library_core_android.styles.ButtonStyle -import com.payu.android.front.sdk.payment_library_core_android.styles.model.LibraryStyleInfo -import com.payu.android.front.sdk.payment_library_core_android.styles.model.TextStyleInfo -import com.payu.android.front.sdk.payment_library_core_android.styles.providers.LibraryStyleProvider - - -class OfferInstallmentsActivity : BaseActivity() { - private lateinit var viewModel: OfferInstallmentsViewModel - private lateinit var appToolbar: Toolbar - private lateinit var libraryStyleInfo: LibraryStyleInfo - private lateinit var toolbarTitleText: TextView - private lateinit var titleText: TextView - private lateinit var subTitleText: TextView - private lateinit var bodyText: TextView - private lateinit var positiveButton: Button - private lateinit var negativeButton: Button - private lateinit var logoImageView: ImageView - - companion object { - const val INSTALLMENT_REQUEST_CODE = 167; - const val INSTALLMENT_KEY = "INSTALLMENT_KEY" - - /** - * Calling this method will trigger the installment flow of the app - * Before please check if transaction can have an installment using call to: "/api/v2_1/orders/{orderId}/transactions" - * on your endpoint - * - * REQUEST CODE: - * @see OfferInstallmentsActivity.INSTALLMENT_REQUEST_CODE - * BUNDLE KEY -> - * @see OfferInstallmentsActivity.INSTALLMENT_KEY - * Bundle object: - * @see SelectedInstallment - * After that please send selected installment using endpoint: - * "/api/v2_1/card-installment-proposals/{proposalId}/decisions" - * @see [online documentation](https://developers.payu.com/en/mci.html) - */ - @JvmStatic - fun startForResult(activity: Activity) { - val intent = Intent(activity, OfferInstallmentsActivity::class.java) - activity.startActivityForResult(intent, INSTALLMENT_REQUEST_CODE) - } - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - viewModel = ViewModelProvider(this, - OfferInstallmentsViewModelFactory(StaticContentUrlProvider( - ConfigurationEnvironmentProvider.provideEnvironment(this)), - CardIssuer.MASTER_CARD, - TranslationFactory.getInstance())) - .get(OfferInstallmentsViewModel::class.java) - - libraryStyleInfo = LibraryStyleProvider.fromContext(this) - - - Glide.with(this).load(viewModel.provideImagePath()).into(logoImageView) - setupTranslations() - setupStyles() - setupActions() - observeUserAction() - - } - - override fun provideToolbar(): Toolbar { - return appToolbar - } - - override fun bindViews() { - appToolbar = findViewById(R.id.payu_toolbar) - toolbarTitleText = findViewById(R.id.title_payu_toolbar_textView) - logoImageView = findViewById(R.id.installment_provider_logo_image) - titleText = findViewById(R.id.installment_provider_title_text) - subTitleText = findViewById(R.id.installment_provider_subtitle_text) - bodyText = findViewById(R.id.installment_provider_body_text) - positiveButton = findViewById(R.id.installment_provider_positive_button) - negativeButton = findViewById(R.id.installment_provider_negative_button) - - } - - override fun getLayoutResource(): Int { - return R.layout.activity_offer_installments - } - - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - if (INSTALLMENT_REQUEST_CODE == requestCode) { - setResult(RESULT_OK, data) - } else { - setResult(RESULT_CANCELED) - } - finish() - } - - private fun setupTranslations() { - titleText.text = viewModel.provideTranslationForTitle() - subTitleText.text = viewModel.provideTranslationForSubTitle() - bodyText.text = viewModel.provideTranslationForBody() - positiveButton.text = viewModel.provideTranslationForButtonPositive() - negativeButton.text = viewModel.provideTranslationForButtonNegative() - toolbarTitleText.text = viewModel.provideTranslationForHeader() - - } - - private fun setupStyles() { - appToolbar.setBackgroundColor(libraryStyleInfo.toolbarColor) - findViewById(R.id.main_view).setBackgroundColor(libraryStyleInfo.backgroundColor) - - //buttons - ButtonStyle(libraryStyleInfo.textStyleButtonPrimary).applyTo(positiveButton) - createStyleFromInfo(libraryStyleInfo.textStyleButtonPrimary.textStyleInfo).applyTo(positiveButton) - ButtonStyle(libraryStyleInfo.textStyleButtonBasic).applyTo(negativeButton) - createStyleFromInfo(libraryStyleInfo.textStyleButtonBasic.textStyleInfo).applyTo(negativeButton) - - //textViews - val titleWithoutPadding = TextStyleInfo.Builder().withFont(libraryStyleInfo.textStyleTitle.font) - .withFontPath(libraryStyleInfo.textStyleTitle.fontPath) - .withPaddingBottom(libraryStyleInfo.textStyleTitle.paddingBottom) - .withPaddingLeft(0f) - .withPaddingRight(0f) - .withPaddingTop(libraryStyleInfo.textStyleTitle.paddingTop) - .withTextColor(libraryStyleInfo.textStyleTitle.textColor) - .withTextSize(libraryStyleInfo.textStyleTitle.textSize) - .build() - - createStyleFromInfo(titleWithoutPadding).applyTo(titleText) - createStyleFromInfo(libraryStyleInfo.textStyleText).applyTo(subTitleText) - createStyleFromInfo(libraryStyleInfo.textStyleText).applyTo(bodyText) - createStyleFromInfo(libraryStyleInfo.textStyleTitle).applyTo(toolbarTitleText) - - - } - - private fun setupActions() { - positiveButton.setOnClickListener { viewModel.onAcceptInstallments() } - negativeButton.setOnClickListener { viewModel.onDeclineInstallments() } - } - - private fun observeUserAction() { - viewModel.onClickEvent.observe(this, { action -> - if (action) { - ChooseInstallmentsActivity.startForResult(this) - } else { - setResult(RESULT_CANCELED) - finish() - } - }) - } -} diff --git a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/viewmodel/ChooseInstallmentsViewModel.kt b/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/viewmodel/ChooseInstallmentsViewModel.kt deleted file mode 100644 index 6604ca9..0000000 --- a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/viewmodel/ChooseInstallmentsViewModel.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.payu.android.front.sdk.payment_installments.mastercard.offer.viewmodel - -import androidx.lifecycle.ViewModel -import com.payu.android.front.sdk.payment_add_card_module.issuer.CardIssuer -import com.payu.android.front.sdk.payment_installments.mastercard.offer.event.SingleLiveEvent -import com.payu.android.front.sdk.payment_installments.mastercard.offer.repository.InstallmentRepository -import com.payu.android.front.sdk.payment_library_api_client.internal.rest.content.StaticContentUrlProvider -import com.payu.android.front.sdk.payment_library_core.translation.Translation -import com.payu.android.front.sdk.payment_library_core.translation.TranslationKey - -class ChooseInstallmentsViewModel(var staticContentProvider: StaticContentUrlProvider, var cardIssuer: CardIssuer, - var translation: Translation, - installmentRepository: InstallmentRepository) : ViewModel() { - - val onClickEvent = SingleLiveEvent() - val installment = installmentRepository.getInstallment() - - fun provideTranslationForSubTitle(): String = translation.translate(TranslationKey.CHOOSE_INSTALLMENTS_SUBTITLE) - fun provideTranslationForButtonNegative(): String = translation.translate(TranslationKey.CHOOSE_INSTALLMENTS_BUTTON_NEGATIVE) - fun provideTranslationForHeader(): String = translation.translate(TranslationKey.OFFER_INSTALLMENTS_HEADER) - - fun provideImagePath(): String = staticContentProvider.get(cardIssuer.path) - - - fun onDeclineInstallments() { - onClickEvent.value = Unit - } - -} \ No newline at end of file diff --git a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/viewmodel/ChooseInstallmentsViewModelFactory.kt b/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/viewmodel/ChooseInstallmentsViewModelFactory.kt deleted file mode 100644 index 32f6ca9..0000000 --- a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/viewmodel/ChooseInstallmentsViewModelFactory.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.payu.android.front.sdk.payment_installments.mastercard.offer.viewmodel - -import android.content.Context -import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider -import androidx.lifecycle.viewmodel.CreationExtras -import com.payu.android.front.sdk.payment_add_card_module.issuer.CardIssuer -import com.payu.android.front.sdk.payment_installments.mastercard.offer.repository.InstallmentRepository -import com.payu.android.front.sdk.payment_library_api_client.internal.rest.content.StaticContentUrlProvider -import com.payu.android.front.sdk.payment_library_core.translation.Translation -import com.payu.android.front.sdk.payment_library_payment_chooser.payment_method.internal.providers.PaymentMethodConfigurationProviderFactory - -class ChooseInstallmentsViewModelFactory(var context: Context, var staticContentProvider: StaticContentUrlProvider, - var cardIssuer: CardIssuer, var translation: Translation) : ViewModelProvider.Factory { - - override fun create(modelClass: Class): T { - return ChooseInstallmentsViewModel(staticContentProvider, cardIssuer, translation, - InstallmentRepository(PaymentMethodConfigurationProviderFactory.createProvider(context).paymentMethodsActions)) as T - } - - override fun create(modelClass: Class, extras: CreationExtras): T { - return ChooseInstallmentsViewModel(staticContentProvider, cardIssuer, translation, - InstallmentRepository(PaymentMethodConfigurationProviderFactory.createProvider(context).paymentMethodsActions)) as T - - } -} diff --git a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/viewmodel/OfferInstallmentsViewModel.kt b/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/viewmodel/OfferInstallmentsViewModel.kt deleted file mode 100644 index 0764a03..0000000 --- a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/viewmodel/OfferInstallmentsViewModel.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.payu.android.front.sdk.payment_installments.mastercard.offer.viewmodel - -import androidx.lifecycle.ViewModel -import com.payu.android.front.sdk.payment_add_card_module.issuer.CardIssuer -import com.payu.android.front.sdk.payment_installments.mastercard.offer.event.SingleLiveEvent -import com.payu.android.front.sdk.payment_library_api_client.internal.rest.content.StaticContentUrlProvider -import com.payu.android.front.sdk.payment_library_core.translation.Translation -import com.payu.android.front.sdk.payment_library_core.translation.TranslationKey - -class OfferInstallmentsViewModel(var staticContentProvider: StaticContentUrlProvider, - var cardIssuer: CardIssuer, - var translation: Translation) : ViewModel() { - - val onClickEvent = SingleLiveEvent() - - fun provideTranslationForTitle(): String = - translation.translate(TranslationKey.OFFER_INSTALLMENTS_TITLE) - - - fun provideTranslationForSubTitle(): String = translation.translate(TranslationKey.OFFER_INSTALLMENTS_SUBTITLE) - fun provideTranslationForBody(): String = translation.translate(TranslationKey.OFFER_INSTALLMENTS_BODY) - fun provideTranslationForButtonPositive(): String = translation.translate(TranslationKey.OFFER_INSTALLMENTS_BUTTON_ACCEPT) - fun provideTranslationForButtonNegative(): String = translation.translate(TranslationKey.OFFER_INSTALLMENTS_BUTTON_NEGATIVE) - fun provideTranslationForHeader(): String = translation.translate(TranslationKey.OFFER_INSTALLMENTS_HEADER) - - fun provideImagePath(): String = staticContentProvider.get(cardIssuer.path) - - - fun onAcceptInstallments() { - onClickEvent.value = true - } - - fun onDeclineInstallments() { - onClickEvent.value = false - } - -} \ No newline at end of file diff --git a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/viewmodel/OfferInstallmentsViewModelFactory.kt b/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/viewmodel/OfferInstallmentsViewModelFactory.kt deleted file mode 100644 index e0fc177..0000000 --- a/payment-installments/src/main/java/com/payu/android/front/sdk/payment_installments/mastercard/offer/viewmodel/OfferInstallmentsViewModelFactory.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.payu.android.front.sdk.payment_installments.mastercard.offer.viewmodel - -import androidx.lifecycle.ViewModel -import androidx.lifecycle.ViewModelProvider -import androidx.lifecycle.viewmodel.CreationExtras -import com.payu.android.front.sdk.payment_add_card_module.issuer.CardIssuer -import com.payu.android.front.sdk.payment_library_api_client.internal.rest.content.StaticContentUrlProvider -import com.payu.android.front.sdk.payment_library_core.translation.Translation -class OfferInstallmentsViewModelFactory(var staticContentProvider: StaticContentUrlProvider, var cardIssuer: CardIssuer, - var translation: Translation) : ViewModelProvider.Factory { - override fun create(modelClass: Class, extras: CreationExtras): T { - return OfferInstallmentsViewModel(staticContentProvider, cardIssuer, translation) as T - } - override fun create(modelClass: Class): T { - return OfferInstallmentsViewModel(staticContentProvider, cardIssuer, translation) as T - } -} \ No newline at end of file diff --git a/payment-installments/src/main/res/drawable/baseline_date_range_black_24dp.png b/payment-installments/src/main/res/drawable/baseline_date_range_black_24dp.png deleted file mode 100644 index 81c01b8..0000000 Binary files a/payment-installments/src/main/res/drawable/baseline_date_range_black_24dp.png and /dev/null differ diff --git a/payment-installments/src/main/res/layout/activity_choose_installments.xml b/payment-installments/src/main/res/layout/activity_choose_installments.xml deleted file mode 100644 index d17c899..0000000 --- a/payment-installments/src/main/res/layout/activity_choose_installments.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - -