我正在使用 Braintree 的 v2 drop-in ui
android 进行支付,我的后端服务器在 node.js
中。我已成功实现付款部分,但现在我需要存储卡详细信息
并自动从存储的借记卡/信用卡
或paypal帐户
中扣除金额.
我正在生成客户端 token 并将该 token 存储在我的数据库中。使用该 token ,我正在生成随机数。然后我将 nonce 发送到后端服务器以用于 transaction.sale()
。
这是支付部分的代码 fragment
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);
}
}
}
谁能告诉我存储信用卡/借记卡
或paypal帐户
详细信息并从存储的payment-method
生成随机数的步骤
最佳答案
全面披露:我在 Braintree 工作。如果您还有任何疑问,请随时联系support 子>
您想要完成的大部分工作都是在您的服务器端进行更改。如果要存储卡,可以传入选项参数 storeInVaultOnSuccess ,这将在成功时保存该卡并使用该卡创建关联客户。否则,您也可以将该随机数传递给 PaymentMethod.Create称呼。如果这些调用成功,将为这些卡片创建一个 token ,然后您就可以重复使用该 token 。基于你说你想“自动扣除金额”这一事实,我认为你可能想使用该 token 设置订阅。为此,您需要创建一个 plan ,这是您在控制面板中订阅的模板。然后你想实际创建 subscription使用您创建的存储 token 。如果您希望这些保存的卡片显示在 Drop-in 中供客户选择,您需要传递 customer_id进入 ClientToken.generate 调用。这将允许客户从他们的列表中选择存储的卡并在 Drop-in 中重复使用。
关于android - 在 Braintree 中存储和检索借记卡和信用卡详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44778686/