open-pay / openpay-react-native

openpay-react-native is a package that generates the device_session_id and tokenize credit cards with Openpay.
MIT License
8 stars 10 forks source link

ERROR TypeError: identifierForVendor.replace is not a function. (In 'identifierForVendor.replace(/-/g, '')', 'identifierForVendor.replace' is undefined) #5

Open Marioegarcia opened 2 years ago

Marioegarcia commented 2 years ago

ERROR TypeError: identifierForVendor.replace is not a function. (In 'identifierForVendor.replace(/-/g, '')', 'identifierForVendor.replace' is undefined)

marlon07021 commented 2 years ago

Any updates on this ?

hernancasillas commented 1 year ago

Any updates on this ? x2

slashweb commented 1 year ago

Same here, how did you solve this?

LuisEGV commented 9 months ago

Got it to "almost" work by changing the package function createDeviceSessionId to by async.

let identifierForVendor = this.identifierForVendor(); returns a promise, but is not fulfilled unless you add an await.

So I made the function async like this:

 createDeviceSessionId = async () => {
        let identifierForVendor = await this.identifierForVendor() || "testing this";
        console.log("identifierForVendor",identifierForVendor)
        identifierForVendor = identifierForVendor.replace(/-/g, '');

        const uri = vsprintf('%s/oa/logo.htm?m=%s&s=%s', [
            this.props.isProductionMode ? API_URL_PRODUCTION : API_URL_SANDBOX,
            this.props.merchantId,
            sessionId,
        ]);
        const injectedJavaScript = vsprintf('var identifierForVendor = "%s";', [
            identifierForVendor,
        ]);

        this.setState(() => ({uri, injectedJavaScript}));
        this.props.deviceSession(sessionId);
    };

Not an openpay worker lol, but this fixes the crash. It still by no means fixes other validation errors that you get via interacting with the card.