ezet / stripe-sdk

A simple and flexible Stripe library for Flutter with complete support for SCA and PSD2.
https://pub.dev/packages/stripe_sdk
Other
137 stars 137 forks source link

StripeCard.validateExpDate() fails when expMonth is below 11 #104

Closed ghost closed 3 years ago

ghost commented 3 years ago

This is due to a bug in the following code:

bool validateDate() { return _ccValidator.validateExpDate('$expMonth/$expYear').isValid; }

For example, if expMonth is 01 and expYear is 12, and since expMonth is an int, the resulting String passed to _ccValidator.validateExpDate would be "1/12" instead of "01/12", which fails while matching with RegExp(r'((0[1-9])|(1[0-2]))(/)+(\d{2,4})')

Replacing the line return _ccValidator.validateExpDate('$expMonth/$expYear').isValid;

with the following should fix: return _ccValidator.validateExpDate('${expMonth.toString().padLeft(2, '0')}/${expYear.toString().padLeft(2, '0')}').isValid;

musthafa1996 commented 3 years ago

I have created a fix in this PR: https://github.com/ezet/stripe-sdk/pull/105

ezet commented 3 years ago

Fixed in #105