[英]Stripe Android - Scan Card
我正在整合条纹添加卡。
这是我的 XML 代码。 我正在使用“CardInputWidget”来获取卡片详细信息。
有没有办法实现扫描卡功能? 启用扫描卡的任何默认方法。 谁能帮我这个? 条带 android SDK 是否提供扫描卡功能
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/grey_300"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include layout="@layout/actionbar_layout" />
<LinearLayout
android:layout_below="@+id/citygoToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="@+id/emailInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
app:layout_constraintTop_toTopOf="parent" android:layout_margin="20dp"
android:hint="Enter your email" />
<com.stripe.android.view.CardInputWidget
android:id="@+id/cardInputWidget"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:padding="20dp"
android:background="@drawable/edittext_white_border_shape" />
<Button
android:text="Save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/payButton"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
style="@style/AppTheme.Button.Pink" />
</LinearLayout>
</LinearLayout>
您可以添加自己的按钮,例如带有“camera_icon”的 imageView
实现库“io.card:android-sdk:5.4.2”
之后,您可以准备请求
fun onClickScanCard() {
val scanIntent = Intent(activity, CardIOActivity::class.java)
scanIntent.putExtra(CardIOActivity.EXTRA_HIDE_CARDIO_LOGO, true)
scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_MANUAL_ENTRY, true)
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, false)
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, false)
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, false)
scanIntent.putExtra(CardIOActivity.EXTRA_USE_PAYPAL_ACTIONBAR_ICON, false)
activity.startActivityForResult(scanIntent, yourRequestCode)
}
并处理结果。 我将设置值绑定到您可以使用另一种方式的字段中。
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == yourRequestCode && data?.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT) == true) {
val scanResult = data.getParcelableExtra<CreditCard>(CardIOActivity.EXTRA_SCAN_RESULT)
scanResult?.also { creditCard ->
val expiryDate = creditCard.expiryMonth.toString() + creditCard.expiryYear
binding.cardNumberEditText.setText(creditCard.cardNumber)
binding.expiryDateEditText.setText(expiryDate)
binding.zipCodeEditText.setText(creditCard.postalCode)
binding.cvcEditText.setText(creditCard.cvv)
}
activity.storefrontAnalytics.onScannedCard()
updateEnabledState()
}
}
Google 建议合约与 startForResult 一起使用。
最好使用来自官方库的CardScanSheet
,它提供了stripe-android
:
dependencies {
implementation 'com.stripe:stripe-android:20.5.0'
implementation 'com.stripe:stripecardscan:20.5.0'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.