gpt4 book ai didi

android - 条纹支付集成在 android 错误 java.lang.RuntimeException : Required Parameter: 'card' is required to create a token

转载 作者:行者123 更新时间:2023-11-30 00:39:24 26 4
gpt4 key购买 nike

我有以下代码,我想在 android 应用程序中实现 Stripe 支付。请告诉我如何解决这个问题,如果我在像 this:card = new Card("4242424242421111"这样的代码中动态地给出卡号, 12, 2019, "123"); 然后在成功创建 token 后,但我无法每次都动态提供卡号。这样我就在我的 xml 布局中添加了 CardInputWidget 并编写了这段代码:

CardInputWidget mCardInputWidget = (CardInputWidget) findViewById(R.id.card_input_widget);
card = mCardInputWidget.getCard();

then java.lang.RuntimeException: Required Parameter: 'card' is required to create a token 我怎样才能解决这个问题我从最后一天开始就试图解决这个问题但无法解决

我的完整代码:

  Card card;
public static final String PUBLISHABLE_KEY = "pk_test_djaC9oh3D3xwh8FxOjh7pnew";
private ProgressDialog progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maincard);
btnsubmit= (Button) findViewById(R.id.btnsubmit);

CardInputWidget mCardInputWidget = (CardInputWidget) findViewById(R.id.card_input_widget);

card = mCardInputWidget.getCard();

// card = new Card("4242424242424242", 12, 2018, "123");
if (card == null) {
// mErrorDialogHandler.showError("Invalid Card Data");

Stripe stripe = null;
try {
stripe = new Stripe(MainActivity.this, PUBLISHABLE_KEY);
} catch (AuthenticationException e) {
e.printStackTrace();
}
stripe.createToken(
card,
new TokenCallback() {
public void onSuccess(Token token) {
// Send token to your server
Log.d("token","token"+token);
}
public void onError(Exception error) {
// Show localized error message
Log.d("token","excep"+error.getMessage());

}
}
);
}`

activity_maincard.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.mspl.stripepay.MainActivity"
xmlns:wallet="http://schemas.android.com/apk/res-auto">

<com.stripe.android.view.CardInputWidget
android:id="@+id/card_input_widget"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>

这是我的包含 CardInputWidget 的 xml,请提前致谢。

最佳答案

最后,我得到了使用 CardInputWidget 代码获取卡片信息的解决方案。这是我的做法:

if(mCardInputWidget.getCard()!=null){
String cvv= mCardInputWidget.getCard().getCVC();
int exp= mCardInputWidget.getCard().getExpMonth();
int exp_year= mCardInputWidget.getCard().getExpYear();
String card_num= mCardInputWidget.getCard().getNumber();

card = new Card(card_num, exp, exp_year, cvv);
}

关于android - 条纹支付集成在 android 错误 java.lang.RuntimeException : Required Parameter: 'card' is required to create a token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42784423/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com