Skip to content

Commit

Permalink
Merge pull request #200 from tinkoff-mobile-tech/v2.13
Browse files Browse the repository at this point in the history
V2.13
  • Loading branch information
jQwout authored Feb 10, 2023
2 parents 6131e39 + 41af880 commit 2e5afef
Show file tree
Hide file tree
Showing 57 changed files with 266 additions and 390 deletions.
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 2.13.0

#### Fixed
#### Changes
- google pay methods are deprecated now
- yandex pay has combi-init method for use /init request on merch-side
#### Additions

## 2.12.0

#### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ import ru.tinkoff.acquiring.sdk.models.PaymentSource
*
* @author Mariya Chernyadieva
*/
@Deprecated("Not supported yet")
class GooglePay(var googlePayToken: String? = null) : PaymentSource
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class FinishAuthorizeRequest : AcquiringRequest<FinishAuthorizeResponse>(FINISH_
return AttachedCard().apply(attachedCard)
}

@Deprecated("Not supported yet")
fun googlePay(googlePay: GooglePay.() -> Unit): PaymentSource {
return GooglePay().apply(googlePay)
}
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_NAME=2.12.0
VERSION_CODE=19
VERSION_NAME=2.13.0
VERSION_CODE=20
GROUP=ru.tinkoff.acquiring

POM_DESCRIPTION=Library which allows you to use internet acquiring in your android app
Expand All @@ -16,4 +16,4 @@ org.gradle.daemon=true
org.gradle.jvmargs=-Xmx8096m -XX:+UseConcMarkSweepGC -Dfile.encoding=UTF-8 -XX:MaxMetaspaceSize=512m

android.useAndroidX=true
android.enableJetifier=true
android.enableJetifier=true
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ class CartActivity : PayableActivity(), CartListAdapter.DeleteCartItemListener {
textViewTotalPrice.text = stringTotalPrice
if (totalPrice.coins > 0L) {
buttonPay.isEnabled = true
if (settings.isGooglePayEnabled) {
setupGooglePay()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,23 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import ru.tinkoff.acquiring.sample.R
import ru.tinkoff.acquiring.sample.models.Book
import ru.tinkoff.acquiring.sample.models.BooksRegistry
import ru.tinkoff.acquiring.sample.models.Cart
import ru.tinkoff.acquiring.sdk.AcquiringSdk
import ru.tinkoff.acquiring.sdk.models.options.screen.PaymentOptions
import ru.tinkoff.acquiring.sdk.payment.PaymentProcess.Companion.configure
import ru.tinkoff.acquiring.yandexpay.models.YandexPayData
import ru.tinkoff.acquiring.sdk.requests.performSuspendRequest
import ru.tinkoff.acquiring.yandexpay.*

/**
* @author Mariya Chernyadieva
Expand Down Expand Up @@ -86,10 +95,6 @@ class DetailsActivity : PayableActivity() {

setupTinkoffPay()

if (settings.isGooglePayEnabled) {
setupGooglePay()
}

setupYandexPay(savedInstanceState = savedInstanceState)

fillViews()
Expand Down Expand Up @@ -118,6 +123,47 @@ class DetailsActivity : PayableActivity() {
}
}

override fun createYandexButtonFragment(
savedInstanceState: Bundle?,
paymentOptions: PaymentOptions,
yandexPayData: YandexPayData,
theme: Int?
): YandexButtonFragment {
return savedInstanceState?.let {
try {
(supportFragmentManager.getFragment(
savedInstanceState,
YANDEX_PAY_FRAGMENT_KEY
) as? YandexButtonFragment)?.also {
tinkoffAcquiring.addYandexResultListener(
fragment = it,
activity = this,
yandexPayRequestCode = YANDEX_PAY_REQUEST_CODE,
onYandexErrorCallback = { showErrorDialog() },
onYandexCancelCallback = {
Toast.makeText(this, R.string.payment_cancelled, Toast.LENGTH_SHORT)
.show()
},
onYandexSuccessCallback = ::handleYandexSuccess
)
}
} catch (i: IllegalStateException) {
null
}
} ?: tinkoffAcquiring.createYandexPayButtonFragment(
activity = this,
yandexPayData = yandexPayData,
options = paymentOptions,
yandexPayRequestCode = YANDEX_PAY_REQUEST_CODE,
themeId = theme,
onYandexErrorCallback = { showErrorDialog() },
onYandexCancelCallback = {
Toast.makeText(this, R.string.payment_cancelled, Toast.LENGTH_SHORT).show()
},
onYandexSuccessCallback = ::handleYandexSuccess
)
}

private fun fillViews() {
imageViewCover.setImageResource(book!!.coverDrawableId)
textViewTitle.text = book!!.title
Expand All @@ -129,6 +175,28 @@ class DetailsActivity : PayableActivity() {
textViewPrice.text = price
}

protected fun handleYandexSuccess(it: AcqYandexPayResult.Success) {
showProgressDialog()
lifecycleScope.launch(Dispatchers.IO) {
try {
AcquiringSdk.log("=== ASDK combi init call")
val result = tinkoffAcquiring.sdk.init { configure(it.paymentOptions) }.performSuspendRequest().getOrThrow()
hideProgressDialog()
tinkoffAcquiring.openYandexPaymentScreen(
this@DetailsActivity,
YANDEX_PAY_REQUEST_CODE,
it,
result.paymentId
)
} catch (e: java.lang.Exception) {
if (e !is CancellationException) {
hideProgressDialog()
showErrorDialog()
}
}
}
}

companion object {

private const val EXTRA_BOOK = "book"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package ru.tinkoff.acquiring.sample.ui

import android.annotation.SuppressLint
import android.app.Activity
import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
Expand Down Expand Up @@ -105,7 +104,6 @@ open class PayableActivity : AppCompatActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
PAYMENT_REQUEST_CODE, DYNAMIC_QR_PAYMENT_REQUEST_CODE -> handlePaymentResult(resultCode, data)
GOOGLE_PAY_REQUEST_CODE -> handleGooglePayResult(resultCode, data)
YANDEX_PAY_REQUEST_CODE -> handleYandexPayResult(resultCode, data)
else -> super.onActivityResult(requestCode, resultCode, data)
}
Expand Down Expand Up @@ -197,26 +195,6 @@ open class PayableActivity : AppCompatActivity() {
})
}

protected fun setupGooglePay() {
val googlePayButton = findViewById<View>(R.id.btn_google_pay)

val googleParams = GooglePayParams(TerminalsManager.selectedTerminalKey,
environment = SessionParams.GPAY_TEST_ENVIRONMENT)

val googlePayHelper = GooglePayHelper(googleParams)

googlePayHelper.initGooglePay(this) { ready ->
if (ready) {
googlePayButton.visibility = View.VISIBLE
googlePayButton.setOnClickListener {
googlePayHelper.openGooglePay(this@PayableActivity, totalPrice, GOOGLE_PAY_REQUEST_CODE)
}
} else {
googlePayButton.visibility = View.GONE
}
}
}

private fun createPaymentOptions(): PaymentOptions {
val sessionParams = TerminalsManager.selectedTerminal

Expand Down Expand Up @@ -310,24 +288,7 @@ open class PayableActivity : AppCompatActivity() {
}
}

private fun handleGooglePayResult(resultCode: Int, data: Intent?) {
val a = createPaymentOptions()
if (data != null && resultCode == Activity.RESULT_OK) {
val token = GooglePayHelper.getGooglePayToken(data)
if (token == null) {
showErrorDialog()
} else {
SampleApplication.paymentProcess = tinkoffAcquiring
.initPayment(token, createPaymentOptions())
.subscribe(paymentListener)
.start()
}
} else if (resultCode != Activity.RESULT_CANCELED) {
showErrorDialog()
}
}

private fun showErrorDialog() {
protected fun showErrorDialog() {
errorDialog = AlertDialog.Builder(this).apply {
setTitle(R.string.error_title)
setMessage(getString(R.string.error_message))
Expand All @@ -353,7 +314,7 @@ open class PayableActivity : AppCompatActivity() {
}
}

private fun createYandexButtonFragment(savedInstanceState: Bundle?,
open fun createYandexButtonFragment(savedInstanceState: Bundle?,
paymentOptions: PaymentOptions,
yandexPayData: YandexPayData,
theme: Int?) : YandexButtonFragment {
Expand Down Expand Up @@ -400,13 +361,12 @@ open class PayableActivity : AppCompatActivity() {

const val PAYMENT_REQUEST_CODE = 1
const val DYNAMIC_QR_PAYMENT_REQUEST_CODE = 2
const val GOOGLE_PAY_REQUEST_CODE = 5
const val YANDEX_PAY_REQUEST_CODE = 6

private const val STATE_PAYMENT_AMOUNT = "payment_amount"
private const val STATE_LOADING_SHOW = "loading_show"
private const val STATE_ERROR_SHOW = "error_show"

private const val YANDEX_PAY_FRAGMENT_KEY = "yandex_fragment_key"
const val YANDEX_PAY_FRAGMENT_KEY = "yandex_fragment_key"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,11 @@ object PaymentNotificationManager {
flags))
}

val googlePayIntent = getGooglePayIntent(activity,
requireNotNull(priceMap[selectedButtonId]))
notificationLayout.setOnClickPendingIntent(R.id.googlePayButton, googlePayIntent)

val tinkoffPayIntent = getTinkoffPayIntent(activity,
requireNotNull(priceMap[selectedButtonId]))
notificationLayout.setOnClickPendingIntent(R.id.buttonPayOther, tinkoffPayIntent)

val notification = createNotification(activity, googlePayIntent, notificationLayout)
val notification = createNotification(activity, tinkoffPayIntent, notificationLayout)
NotificationManagerCompat.from(activity).notify(NOTIFICATION_ID, notification)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ class SettingsSdkManager(private val context: Context) {
val isRecurrentPayment: Boolean
get() = preferences.getBoolean(context.getString(R.string.acq_sp_recurrent_payment), false)

val isGooglePayEnabled: Boolean
get() = preferences.getBoolean(context.getString(R.string.acq_sp_android_pay), true)

val isFpsEnabled: Boolean
get() = preferences.getBoolean(context.getString(R.string.acq_sp_fps), false)

Expand Down

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
48 changes: 0 additions & 48 deletions sample/src/main/res/drawable/googlepay_button_content_white.xml

This file was deleted.

Loading

0 comments on commit 2e5afef

Please sign in to comment.