如何使用条带中的银行帐户生成令牌?

时间:2016-11-14 17:40:24

标签: android stripe-payments stripe-connect

我在我的android项目中集成了条带。现在,我正在使用条带卡生成令牌。这工作正常。但是,我想用银行账户生成令牌。我在StackOverflow中搜索了一些链接。但是,它对我不起作用。有没有办法在android中用银行账号生成条带令牌?

我使用的代码如下。但是,它没有用。

        Stripe.apiKey = "sk_test_...";

        Map<String, Object> tokenParams = new HashMap<String, Object>();
        Map<String, Object> bank_accountParams = new HashMap<String, Object>();
        bank_accountParams.put("country", "US");
        bank_accountParams.put("currency", "usd");
        bank_accountParams.put("account_holder_name", "Jane Austen");
        bank_accountParams.put("account_holder_type", "individual");
        bank_accountParams.put("routing_number", "11000000");
        bank_accountParams.put("account_number", "000123456789");
        tokenParams.put("bank_account", bank_accountParams);

        try {
            Token s = Token.create(tokenParams);
            Log.d("Token",s.getId());
            tokens = s.getId();
        } catch (AuthenticationException e) {
            showAlertMessage("",e.getMessage());
        } catch (CardException e) {
            showAlertMessage("",e.getMessage());
        } catch (APIException e) {
            showAlertMessage("",e.getMessage());
        } catch (InvalidRequestException e) {
            showAlertMessage("", e.getMessage());
        } catch (APIConnectionException e) {
            showAlertMessage("",e.getMessage());
        }

3 个答案:

答案 0 :(得分:2)

根据新文档,您需要在gradle构建中添加以下行:

compile 'com.stripe:stripe-android:4.0.1'

检查此link

的最新版本

然后使用以下代码段:

Stripe stripe = new Stripe(this);
stripe.setDefaultPublishableKey("your_publishable_key");
BankAccount bankAccount = new BankAccount("accountNumber","countryCode","currency","routingNumber");
stripe.createBankAccountToken(bankAccount, new TokenCallback() {
    @Override
    public void onError(Exception error) {
        Log.e("Stripe Error",error.getMessage());
    }

    @Override
    public void onSuccess(com.stripe.android.model.Token token) {
        Log.e("Bank Token", token.getId());
    }
});

这应该像魅力一样。

答案 1 :(得分:0)

我在代码中犯了一个错误。那个Token.create(tokenParams);应该在AysncTask处理。因为它处理网络。经过their git repository后,我才知道。所以,我在异步任务中处理了创建令牌部分。我改变的代码如下:

int SDK_INT = android.os.Build.VERSION.SDK_INT;
        final String[] tokens = {"new"};
        Stripe.apiKey = "sk_test_0wgmvQOVjIpspIgKsoW7wtTp";
        final Map<String, Object> tokenParams = new HashMap<String, Object>();
        Map<String, Object> bank_accountParams = new HashMap<String, Object>();
        bank_accountParams.put("country", "US");
        bank_accountParams.put("currency", "usd");
        bank_accountParams.put("account_holder_name", "Jayden Moore");
        bank_accountParams.put("account_holder_type", "individual");
        bank_accountParams.put("routing_number", "110000000");
        bank_accountParams.put("account_number", "000123456789");
        tokenParams.put("bank_account", bank_accountParams);
        final Token[] responseToken = {null};

        if (SDK_INT > 8)
        {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                    .permitAll().build();
            StrictMode.setThreadPolicy(policy);
            //your codes here
            com.stripe.Stripe.apiKey = "sk_test_0wgmvQOVjIpspIgKsoW7wtTp";
            new AsyncTask<Void, Void, Token>() {
                String errorMsg = null;

                @Override
                protected Token doInBackground(Void... params) {
                    try {
                        return Token.create(tokenParams);
                    } catch (AuthenticationException e) {
                        e.printStackTrace();
                        return null;
                    } catch (InvalidRequestException e) {
                        e.printStackTrace();
                        return null;
                    } catch (APIConnectionException e) {
                        e.printStackTrace();
                        return null;
                    } catch (CardException e) {
                        e.printStackTrace();
                        return null;
                    } catch (APIException e) {
                        e.printStackTrace();
                        return null;
                    }
                }

                protected void onPostExecute(Token result) {
                    if (errorMsg == null) {
//                      success
                    } else {
//                        handleError(errorMsg);
                    }
                }
            }.execute();

    }

答案 2 :(得分:0)

我有同样的问题,我通过更改此行来修复它

compile 'com.stripe:stripe-android:+

进入这一行

compile 'com.stripe:stripe-android:1.1.1'

在我的app.gradle文件中。 这可能会在将来的版本中发生变化。

相关问题