zyra / cordova-plugin-stripe

A Cordova plugin that lets you use Stripe's Native SDKs for Android and iOS.
MIT License
93 stars 57 forks source link

Validation crashing on iOS #47

Open whitecat opened 6 years ago

whitecat commented 6 years ago

The following three methods are crashing out when run on iOS. I do not get an error. Calling these functions cause iOS to crash. validateCardNumber validateCVC validateExpiryDate

Here is my ionic info:

cli packages: (/Users/leetcat/.nvm/versions/node/v9.8.0/lib/node_modules)
    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:
    cordova (Cordova CLI) : 7.0.1

local packages:
    @ionic/app-scripts : 1.3.0
    Cordova Platforms  : android 7.0.0 browser 4.1.0 ios 4.4.0
    Ionic Framework    : ionic-angular 3.0.1

System:
    ios-deploy        : 1.9.2
    Node              : v9.8.0
    npm               : 5.6.0
    OS                : macOS High Sierra
    Xcode             : Xcode 9.2 Build version 9C40b

Misc:
    backend : pro

I call the methods like this:

        self.stripe.validateCardNumber(stripeRequest.number).then(resp => {
            console.log("CC Validated")
            self.stripe.validateCVC(stripeRequest.cvc).then(resp => {
                console.log("CVC Validated")
                self.stripe.validateExpiryDate(stripeRequest.expMonth, stripeRequest.expYear).then(resp => {
                    console.log("Date Validated")
                    // Everything is valid now let's submit this to Stripe!
                    self.stripe.createCardToken(stripeRequest)
                        .then(token => {
                            //Do Stuff with token
                        })
                        .catch(error => {
                            self.service.hideLoader();
                            console.error(error);
                        });
                }).catch(resp => {
                    this.service.notify('Invalid Expiration Date', 'warning');
                    self.service.hideLoader();
                    return;
                })
            }).catch(resp => {
                this.service.notify('Invalid CVC', 'warning');
                self.service.hideLoader();
                return;
            })
        }).catch(resp => {
            this.service.notify('Invalid Credit Card number', 'warning');
            self.service.hideLoader();
            return;
        })
hcassar93 commented 6 years ago

I am also having this issue. It was previously working.

Peter1234444 commented 5 years ago

I'm getting the same issue. Version 1.5.3

I made sure to to make each validation function a knock on and instead used "Await", so I could log any errors between each method. What happens is that it successfully goes through the card number and expiry validation methods, but fails at the CVC validation method.

The highlighted code in Xcode is STPCardValidationState state = [STPCardValidator validationStateForCVC:[command.arguments objectAtIndex:0] cardBrand:STPCardBrandUnknown];

The error being logged is [NSNull rangeOfCharacterFromSet:]: unrecognized selector sent to instance 0x1dd96d9d0

When you check out the Stripe docs I can see that their method for validating the CVC actually takes in both CVC number "cvc" and the card brand "brand". Apparently the brand has another method for finding it, called brandForNumber.

Problematically, this error is occurring regardless of the validity of card details entered. My theory is the the issue is something to do with the card brand not being passed as a parameter correctly. Perhaps exposing the brandForNumber method and making the user pass in the brand as an argument may help to stop this issue?