React Native Conekta SDK for iOS and Android
npm install react-native-conekta
Please see: Linking Libraries iOS
Library folder: your-project/node_modules/react-native-conekta/RNConekta
In android/settings.gradle
...
include ':react-native-conekta'
project(':react-native-conekta').projectDir = file('../node_modules/react-native-conekta/RNConektaAndroid')
In android/app/build.gradle
...
dependencies {
...
compile project(':react-native-conekta')
}
Register module (in MainActivity.java
)
import com.dieam.reactnativeconekta.ReactNativeConektaPackage; // <--- import
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
......
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new ReactNativeConektaPackage(this))// <------ add the package
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
mReactRootView.startReactApplication(mReactInstanceManager, "ExampleApp", null);
setContentView(mReactRootView);
}
......
}
var conektaApi = new Conekta();
conektaApi.setPublicKey( 'YOUR_PUBLIC_KEY' );
conektaApi.createToken({
cardNumber: '4242424242424242',
name: 'Manolo Virolo',
cvc: '111',
expMonth: '11',
expYear: '21',
}, function(data){
console.log( 'DATA:', data ); // data.id to get the Token ID
}, function(){
console.log( 'Error!' );
});