2017-03-14 33 views
1

我有以下代碼,我想在Android應用程序中實現條紋支付任何告訴如何這個問題我如果我在this:card = new Card("4242424242421111", 12, 2019, "123");這樣的代碼中給出了卡號,那麼可以解決,然後在成功令牌創建後,我不能每次都動態地給卡號。所以,我在我的XML佈局添加CardInputWidget和編寫這些代碼:在android中條帶支付集成錯誤java.lang.RuntimeException:必需參數:'卡'是創建令牌所必需的

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

則j ava.lang.RuntimeException: Required Parameter:「牌」需要創建令牌如何解決這個問題,我試圖解決這個問題自去年1天但無法解決

我全碼:

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> 

這是我的xml包含CardInputWidget請嘗試幫助提前致謝。

回答

1
Finally i got my solution to get Card Information using CardInputWidget code: 
I am giving my own answer here to get card Information.` 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);`