Why Won't The Latest Version Of Stripe Gradle Allow .setName?
I am trying to integrate Stripe payments and the latest version for gradle stated to be com.stripe:stripe-android:9.2.0
. Yet I am not able to use the .setName
function to add to the card data. Why is this the case? I had to revert to an older 9.1.1
version to be able to accomplish this.
My code currently looks like this:
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
}
});
Answer
I figured it out when you use constructor it receives name as argument.
On the latest library com.stripe:stripe-android:9.2.0
it changes the way it was before
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;
}
or you can use Builder method to it also has .name(@Nullable String name)
method which you can use.
Recommended way
is to use Card.Builder()
and pass the arguments in the builder itself. Let me know if you need any help
EDIT
currently you can workaround the below condition like this:
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
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View