zenkkor / ngx-credit-cards

A Credit Card Directives and Form Validators package for Angular X (2+)
MIT License
30 stars 36 forks source link

ERROR TypeError: Payment.fns.restrictNumeric is not a function #10

Open imme64 opened 6 years ago

imme64 commented 6 years ago

I could only use your great directives by adding the following code to my project:

import * as Payment from 'payment';
Payment.fns.restrictNumeric = Payment.restrictNumeric;
Payment.fns.formatCardExpiry = Payment.formatCardExpiry;
Payment.fns.formatCardCVC = Payment.formatCardCVC;

Somehow the 'payment' dependency seems to have changed. Otherwise I cannot explain why it does work for you but not for me.

bnussey commented 6 years ago

Same for me

Nightbr commented 6 years ago

same here: Uncaught (in promise): TypeError: Payment.fns.restrictNumeric is not a function

Any fix or PR for this could be appreciated

ermamud commented 6 years ago

I found the issue in the code:

directives/cc-cvc-format.directive.ts:

change this:

        Payment.fns.formatCardCVC(element);
        Payment.fns.restrictNumeric(element);

for:

        Payment.formatCardCVC(element);
        Payment.restrictNumeric(element);

directives/cc-expiry-format.directive.ts:

change:

        Payment.fns.formatCardExpiry(element);
        Payment.fns.restrictNumeric(element);

for this:

        Payment.formatCardExpiry(element);
        Payment.restrictNumeric(element);

directives/cc-number-format.directive.ts:

change:

        Payment.fns.restrictNumeric(element);

for this:

        Payment.restrictNumeric(element);

this should fixed all the issues. I haven't fully tested everything, but taking a look to the payment library, some of the functions are inside the fns property and some other are not. Please create a PR with this fix right away.