我正在尝试将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
}
});
答案 0 :(得分:2)
当您使用构造函数时,我发现它会接收名称作为参数。
在最新的图书馆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