-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from Tinkoff/2.9.0
2.9.0 Added ability to launch 3DS authentication via `ThreeDsHelper`
- Loading branch information
Showing
27 changed files
with
545 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
VERSION_NAME=2.8.2 | ||
VERSION_NAME=2.9.0 | ||
VERSION_CODE=15 | ||
GROUP=ru.tinkoff.acquiring | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
sample/src/main/java/ru/tinkoff/acquiring/sample/ui/AttachCardManuallyDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package ru.tinkoff.acquiring.sample.ui | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.DialogFragment | ||
import kotlinx.android.synthetic.main.dialog_attach_card_manually.* | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import ru.tinkoff.acquiring.sample.R | ||
import ru.tinkoff.acquiring.sample.SampleApplication | ||
import ru.tinkoff.acquiring.sample.ui.MainActivity.Companion.toast | ||
import ru.tinkoff.acquiring.sample.utils.SessionParams | ||
import ru.tinkoff.acquiring.sample.utils.SettingsSdkManager | ||
import ru.tinkoff.acquiring.sdk.models.enums.ResponseStatus | ||
import ru.tinkoff.acquiring.sdk.models.options.screen.BaseAcquiringOptions | ||
import ru.tinkoff.acquiring.sdk.models.paysources.CardData | ||
import ru.tinkoff.acquiring.sdk.threeds.ThreeDsHelper | ||
|
||
class AttachCardManuallyDialogFragment : DialogFragment() { | ||
|
||
private val coroutineScope = CoroutineScope(Dispatchers.Main) | ||
|
||
private val sdk = SampleApplication.tinkoffAcquiring.sdk | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return inflater.inflate(R.layout.dialog_attach_card_manually, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
close.setOnClickListener { dismiss() } | ||
|
||
attach.setOnClickListener { | ||
val cardData = CardData(pan.text.toString(), date.text.toString(), cvv.text.toString()) | ||
try { | ||
cardData.validate() | ||
} catch (e: Throwable) { | ||
requireActivity().toast(e.message!!) | ||
return@setOnClickListener | ||
} | ||
addCardManually(cardData) | ||
} | ||
} | ||
|
||
private fun addCardManually(cardData: CardData) { | ||
val settings = SettingsSdkManager(requireContext()) | ||
val params = SessionParams[settings.terminalKey] | ||
|
||
val addCard = sdk.addCard { | ||
customerKey = params.customerKey | ||
checkType = "3DS" | ||
} | ||
|
||
coroutineScope.launch(Dispatchers.IO) { | ||
addCard.execute({ | ||
attachCardManually(params, it.requestKey!!, cardData) | ||
}, { }) | ||
} | ||
} | ||
|
||
private fun attachCardManually(params: SessionParams, requestKey: String, cardData: CardData) { | ||
val attachCard = sdk.attachCard { | ||
this.requestKey = requestKey | ||
this.cardData = cardData | ||
} | ||
val options = BaseAcquiringOptions().apply { | ||
setTerminalParams(params.terminalKey, params.publicKey) | ||
} | ||
|
||
coroutineScope.launch(Dispatchers.IO) { | ||
attachCard.execute({ | ||
when (it.status) { | ||
ResponseStatus.THREE_DS_CHECKING -> ThreeDsHelper.Launch.launchBrowserBased( | ||
requireActivity(), MainActivity.THREE_DS_REQUEST_CODE, options, it.getThreeDsData()) | ||
null -> { | ||
requireActivity().toast("Attach success") | ||
dismiss() | ||
} | ||
else -> requireActivity().toast("Attach failure: ${it.status}") | ||
} | ||
}, { requireActivity().toast("Attach failure: ${it.message}") }) | ||
} | ||
} | ||
|
||
companion object { | ||
|
||
const val TAG = "AttachCardManuallyDialogFragment" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
sample/src/main/res/layout/dialog_attach_card_manually.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginHorizontal="16dp" | ||
android:padding="16dp"> | ||
|
||
<TextView | ||
android:id="@+id/header" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_horizontal" | ||
android:text="Example of attaching card without SDK UI" /> | ||
|
||
<EditText | ||
android:id="@+id/pan" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/header" | ||
android:layout_marginTop="16dp" | ||
android:hint="Card number" /> | ||
|
||
<LinearLayout | ||
android:id="@+id/container" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/pan" | ||
android:layout_marginBottom="16dp" | ||
android:orientation="horizontal"> | ||
|
||
<EditText | ||
android:id="@+id/date" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:hint="MM/YY" /> | ||
|
||
<EditText | ||
android:id="@+id/cvv" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:hint="CVV" /> | ||
|
||
</LinearLayout> | ||
|
||
<TextView | ||
android:id="@+id/attach" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/container" | ||
android:layout_alignParentEnd="true" | ||
android:text="ATTACH" | ||
android:textColor="@color/acq_colorAccent" | ||
android:textSize="16sp" /> | ||
|
||
<TextView | ||
android:id="@+id/close" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/container" | ||
android:layout_marginRight="32dp" | ||
android:layout_toLeftOf="@id/attach" | ||
android:text="CLOSE" | ||
android:textSize="16sp" /> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.