triniwiz / nativescript-stripe

Apache License 2.0
49 stars 32 forks source link

iOS bug in Strpe.createPaymentMethod() #119

Closed shahzebkhowaja closed 4 years ago

shahzebkhowaja commented 4 years ago

I think, I found a bug in the library, if you are using Stripe class to make createPaymentMethod with card and billingDetails, then you will get a null object error.

Ref: Error: Uncaught (in promise): TypeError: null is not an object (evaluating 'billing.address.line1 = card.addressLine1')

in src/stripe.ios.ts we are just verifying if the card.value exists, if so then we call billing.address.value. However when billing object is created there is no value assigned to address, and that leads to an error in iOS.

Ref:

https://github.com/triniwiz/nativescript-stripe/blob/master/src/stripe.ios.ts line # 77

const billing = STPPaymentMethodBillingDetails.new();
if (card.addressLine1) billing.address.line1 = card.addressLine1;
if (card.addressLine2) billing.address.line2 = card.addressLine2;
if (card.addressCity) billing.address.city = card.addressCity;
if (card.addressState) billing.address.state = card.addressState;
if (card.addressZip) billing.address.postalCode = card.addressZip;
if (card.addressCountry) billing.address.country = card.addressCountry;

Which platform(s) does your issue occur on?

Please, tell us how to recreate the issue in as much detail as possible.

Just need to use Stripe class and call createPaymentMethod onSubmit of payment

const card: Card = cardView.card;

card.addressLine1 = this.addressLine1;
card.addressLine2 = this.addressLine2;
card.addressCity = this.addressCity;
card.addressZip = this.addressZip;
card.addressState = this.addressState;
card.addressCountry = this.addressCountry;
card.name = this.cardHolderName;

this.stripe.createPaymentMethod(card, (error, pm: PaymentMethod) => {
  if (error) {
    this.errorMessage = error.message;
    this.loading = false;
  } else {
    // do the next step
    this.loading = false;

  }
});
RobertGardner commented 4 years ago

I confirmed this. Thanks. Easy fix (surprisingly, STPPaymentMethodBillingDetails.new() doesn't initialize the address field).

A fix is being built and tested. Should be available soon.