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

How to generate token with bank account in stripe?

我在我的 android 项目中集成了 stripe。现在,我正在用条带卡生成令牌。那工作正常。但是,我想用银行账户生成令牌。我在 Whosebug 中搜索了一些链接。但是,它对我不起作用。 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());
        }

我的代码有误。即 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();

    }

我遇到了同样的问题,我通过更改此行修复了它

compile 'com.stripe:stripe-android:+

进入这一行

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

在我的 app.gradle 文件中。 这可能会在未来的版本中改变。

根据新文档,您需要将以下行添加到 gradle build:

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());
    }
});

这应该很有魅力。