在 Braintree 中存储和检索借记卡和信用卡详细信息

Store and retrieve debit and credit card details in Braintree

我正在使用 Braintree's v2 drop-in ui android 进行支付,我的后端服务器在 node.js。我已成功实施付款部分,但现在我需要存储 card details 并自动从存储的 debit/credit cardpaypal account.

中扣除金额

我正在生成客户端令牌并将该令牌存储在我的数据库中。使用该令牌,我正在生成随机数。然后我将 transaction.sale().

的随机数发送到后端服务器

这是支付部分的代码片段

if (!TextUtils.isEmpty(braintreeClientToken)) {
    DropInRequest dropInRequest = new DropInRequest()
                    .clientToken(braintreeClientToken);
    startActivityForResult(dropInRequest.getIntent(this), REQUEST_CODE);
}

OnActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
            PaymentMethodNonce paymentMethodNonce = result.getPaymentMethodNonce();
            String nonce = "";
            if (paymentMethodNonce != null)
                nonce = paymentMethodNonce.getNonce();
            // use the result to update your UI and send the payment method nonce to your server
            if (!TextUtils.isEmpty(nonce)) {
                NonceRequest obj = new NonceRequest("ANDROID", "1",
                            "DRIVER-SAVE-PAYMENT", "1", nonce);
                Call<NonceResponse> call = RestService.getInstance().restInterface.sendNonceToServer(userId, userToken, obj);
                    call.enqueue(new Callback<NonceResponse>() {
                    @Override
                    public void onResponse(Call<NonceResponse> call, Response<NonceResponse> response) {

                    }

                    @Override
                    public void onFailure(Call<NonceResponse> call, Throwable t) {

                    }
                });
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // the user canceled
        } else {
            // handle errors here, an exception may be available in
            Exception error = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
        }
    }
}

谁能告诉我存储 credit/debit cardpaypal account 详细信息并从存储的 payment-method

生成随机数的步骤

完全披露:我在 Braintree 工作。如果您有任何其他问题,请随时联系 support

您想要完成的大部分工作将是在您的服务器端进行更改。如果要存储卡,可以将选项参数 storeInVaultOnSuccess, which will save that card on success and create an associated customer with that card. Otherwise, you can also pass that nonce into a PaymentMethod.Create call. If these calls are successful, a token will be created for those cards which you will then be able to reuse. Based on the fact you stated you wanted to "deduct amount automatically", I think you may want to setup a subscription using that token. For this, you'd need to create a plan, which is a template for your subscriptions in the control panel. Then you'd want to actually create the subscription using the stored token that you've created. If you want these saved cards to show up in the Drop-in for a customer to select, you'll want to pass the customer_id 传递到 ClientToken.generate 调用中。这将允许客户从他们的列表中 select 存储卡并在 Drop-in 中重复使用。