android - 为什么最新版本的 Stripe gradle 不允许 .setName?
问题描述
我正在尝试将 Stripe 付款和最新版本的 gradle 集成为com.stripe:stripe-android:9.2.0
. 但是我无法使用该.setName
功能添加到卡数据中。为什么会这样?我必须恢复到旧9.1.1
版本才能做到这一点。
我的代码目前如下所示:
Card cardToSave = mCardInputWidget.getCard();
Card.Builder builder = new Card.Builder(cardToSave.getName()); // pass the arguments here
builder.setName(cardHolderName);
Card newCard = builder.build();
Stripe stripe = new Stripe(paymentContext, publishableApiKey );
stripe.createToken(newCard, publishableApiKey, new TokenCallback() {
@Override
public void onSuccess(@NonNull Token result) {
// Create plan
}
@Override
public void onError(@NonNull Exception e) {
// Handle error
}
});
解决方案
当您使用构造函数时,我发现它接收名称作为参数。在最新的库com.stripe:stripe-android:9.2.0
中,它改变了以前的方式
private Card(@NonNull Builder builder) {
this.number = StripeTextUtils.nullIfBlank(normalizeCardNumber(builder.number));
this.expMonth = builder.expMonth;
this.expYear = builder.expYear;
this.cvc = StripeTextUtils.nullIfBlank(builder.cvc);
this.name = StripeTextUtils.nullIfBlank(builder.name);
this.addressLine1 = StripeTextUtils.nullIfBlank(builder.addressLine1);
this.addressLine1Check = StripeTextUtils.nullIfBlank(builder.addressLine1Check);
this.addressLine2 = StripeTextUtils.nullIfBlank(builder.addressLine2);
this.addressCity = StripeTextUtils.nullIfBlank(builder.addressCity);
this.addressState = StripeTextUtils.nullIfBlank(builder.addressState);
this.addressZip = StripeTextUtils.nullIfBlank(builder.addressZip);
this.addressZipCheck = StripeTextUtils.nullIfBlank(builder.addressZipCheck);
this.addressCountry = StripeTextUtils.nullIfBlank(builder.addressCountry);
this.last4 = StripeTextUtils.nullIfBlank(builder.last4) == null
? calculateLast4(number, builder.last4)
: builder.last4;
this.brand = asCardBrand(builder.brand) == null
? calculateBrand(builder.brand)
: builder.brand;
this.fingerprint = StripeTextUtils.nullIfBlank(builder.fingerprint);
this.funding = asFundingType(builder.funding);
this.country = StripeTextUtils.nullIfBlank(builder.country);
this.currency = StripeTextUtils.nullIfBlank(builder.currency);
this.customerId = StripeTextUtils.nullIfBlank(builder.customer);
this.cvcCheck = StripeTextUtils.nullIfBlank(builder.cvcCheck);
this.id = StripeTextUtils.nullIfBlank(builder.id);
this.tokenizationMethod = StripeTextUtils.nullIfBlank(builder.tokenizationMethod);
this.metadata = builder.metadata;
}
或者你可以使用 Builder 方法,它也有.name(@Nullable String name)
你可以使用的方法。
推荐的方法
是在构建器本身中使用Card.Builder()
和传递参数。如果您需要任何帮助,请告诉我
编辑
目前您可以像这样解决以下情况:
Card cardToSave = mCardInputWidget.getCard();
Card.Builder builder = new Card.Builder( String number, Integer expMonth, Integer expYear, String cvc); // pass the arguments here
builder.setName("");
Card newCard = builder.build();
newCard.setName(cardHolderName);
// use this **newCard** for payment
推荐阅读
- unit-testing - Mockito 单元测试 lombok.extern.slf4j @Slf4j 注释日志?
- django - 模板标签未在 HTML 中呈现
- c - 对数计算器
- javascript - Knockout JS 订阅 2 个 observables 的方式是,如果 2 个 observables 中的任何一个发生变化,我只会收到一次通知
- python-3.x - Google 电子邮件 api .docx 损坏
- jmeter - 如何将 .Net 单元测试与 JMeter 集成
- c++ - Windows控制台C ++中的RGB颜色
- ruby-on-rails - Rails 按范围订购其他型号的 Draper/Decorate
- django - 如何使用带有 AbstractBaseUser 扩展的自定义用户模型的 post_save 信号
- python - 如何从文本文件中分割数字?