Reputation: 2693
I used the module react-native-paypal, But while integrating in Android, it throws some error during the running of Android, here is the screenshot of the error .
Here is the code where it shows error MainActivity.java
package com.camp;
import com.facebook.react.ReactActivity;
import android.content.Intent; // <--
public class MainActivity extends ReactActivity {
//public static Activity activity;
//private static final int PAY_PAL_REQUEST_ID = 9
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 9) {
payPalPackage.handleActivityResult(requestCode, resultCode, data); // <--
} else {
otherModulesHandlers(requestCode, resultCode, data);
}
}
@Override
protected String getMainComponentName() {
return "Camp";
}
}
MainApplication.java
package com.camp;
import android.app.Application;
import android.util.Log;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import br.com.vizir.rn.paypal.PayPalPackage;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private static final int PAY_PAL_REQUEST_ID = 9; // <-- Can be any unique number
private PayPalPackage payPalPackage; // <--
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
payPalPackage = new PayPalPackage(PAY_PAL_REQUEST_ID); // <--
return Arrays.<ReactPackage>asList(
payPalPackage, // <--
new MainReactPackage()
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
Please give me suggestions on how to resolve this error. Any help is much appreciated
After all changes in my code, But still facing some problem please see the below image
please give me suggestions that how to solve these type of errors
paypalcode in react-native
paypal(){
PayPalAndroid.paymentRequest({
clientId: '............',
environment: PayPalAndroid.SANDBOX,
price: '0.01',
currency: 'EUR',
description: 'PayPal Test'
}).then((confirm, payment) => console.log('Paid'))
.catch((error_code) => console.error('Failed to pay through PayPal'));
}
here instead of console i wrote alert but it doen't show alert, i tried for many times, i didn't get success alert or catch alert, Please give me suggestions that how to resolve it
Upvotes: 1
Views: 429
Reputation: 8678
The react-native-paypal version on npm registry and its repository hasn't been updated to work latest react-native versions. You can use this fork https://github.com/sharafat/react-native-paypal instead.
package.json
"dependencies": {
"react": "15.4.1",
"react-native": "0.38.0",
"react-native-paypal": "https://github.com/sharafat/react-native-paypal.git"
},
MainActivity.java
...
import android.content.Intent;
import com.facebook.react.ReactActivity;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "ReactNativePayPalTest";
}
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == MainApplication.PAY_PAL_REQUEST_ID) { // <--
((MainApplication) getApplication()).payPalPackage.handleActivityResult(requestCode, resultCode, data); // <--
} else {
// otherModulesHandlers(requestCode, resultCode, data);
}
}
}
MainApplication.java
...
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import java.util.Arrays;
import java.util.List;
import br.com.vizir.rn.paypal.PayPalPackage;
public class MainApplication extends Application implements ReactApplication {
public static final int PAY_PAL_REQUEST_ID = 9; // <-- Can be any unique number
public PayPalPackage payPalPackage;
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
payPalPackage = new PayPalPackage(PAY_PAL_REQUEST_ID);
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
payPalPackage
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
Upvotes: 1