Adyen react-native-adyen-cse

Has anybody successfully installed react-native-adyen-cse from react-native-adyen-cse - npm

Thanks!

What have you tried and what errors/problems did you encounter?

Here is the code

import React, { Component } from "react";
import { Text, View, Button } from "react-native";
import { encrypt } from "react-native-adyen-cse";
const publicKey =  "PUBLIC KEY";
async function testCardDetailsEncrypt() {
  const card = {
    holderName: "John Doe",
    number: "4111111111111111",
    cvc: "737",
    expiryMonth: "08",
    expiryYear: "2018"
  };

  const token = await encrypt(card, publicKey);
  return token;
}
export default class App extends Component {
  state = {
    encryptedCard: ""
  };
  handleBtnClick = () => {
    testCardDetailsEncrypt().then(encryptedCard =>
      this.setState({ encryptedCard })
    );
  };
  render() {
    return (
      <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
        <View
          style={{
            flexDirection: "row",
            alignSelf: "stretch",
            justifyContent: "space-around"
          }}
        >
          <Button
            title="Test AdYen CSE"
            onPress={() => this.handleBtnClick()}
          />
        </View>
        <Text style={{ color: "black", fontSize: 16 }}>
          {this.state.encryptedCard}
        </Text>
      </View>
    );
  }
}

The first error was at the import level

Could not find a declaration file for module 'react-native-adyen-cse'. 'g:/Expo/mobshed/node_modules/react-native-adyen-cse/index.js' implicitly has an 'any' type.
  Try `npm install @types/react-native-adyen-cse` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-native-adyen-cse';`ts(7016)
Could not find a declaration file for module 'react-native-adyen-cse'. 'g:/Expo/mobshed/node_modules/react-native-adyen-cse/index.js' implicitly has an 'any' type.
  Try `npm install @types/react-native-adyen-cse` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-native-adyen-cse';`ts(7016)

I managed to (kinda) fix it by adding an index.d.ts file - duplicate version of index.js with the “.d.ts” extension.
Then, when I run the script I get the following error

 [Unhandled promise rejection: TypeError: null is not an object (evaluating 'RNAdyenCse.encrypt')]
- node_modules\react-native-adyen-cse\index.js:7:20 in encrypt
* screens\BalanceScreen.js:17:30 in testCardDetailsEncrypt$
- node_modules\regenerator-runtime\runtime.js:45:44 in tryCatch
- node_modules\regenerator-runtime\runtime.js:271:30 in invoke
- node_modules\regenerator-runtime\runtime.js:45:44 in tryCatch
- node_modules\regenerator-runtime\runtime.js:135:28 in invoke
- node_modules\regenerator-runtime\runtime.js:170:17 in <unknown>
- node_modules\promise\setimmediate\core.js:45:7 in tryCallTwo
- node_modules\promise\setimmediate\core.js:200:23 in doResolve
- ... 21 more stack frames from framework internals

Hey @mobshed,

This library requires native code changes via the link command or manually doing so. As a result, it can not be used with a Managed Expo project. If you need to use this library, you’ll want to use the Bare workflow.

Cheers,
Adam

Thanks @adamjnav for the info!

1 Like

You’re most welcome! Good luck moving forward.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.