gpt4 book ai didi

paypal - 集成在使用 react-native-papal 的 android 中抛出错误

转载 作者:太空宇宙 更新时间:2023-11-03 15:58:26 27 4
gpt4 key购买 nike

我使用了模块react-native-paypal,但是在集成到Android中时,在Android运行过程中会抛出一些错误,这里是错误的截图。 enter image description here

这是显示错误的代码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;
}
}

请给我有关如何解决此错误的建议。非常感谢任何帮助

在我的代码进行了所有更改之后,但仍然面临一些问题,请参见下图 enter image description here

请给我建议如何解决这些类型的错误

react-native 中的 paypalcode

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'));
}

这里我写了警报而不是控制台但它没有显示警报,我试了很多次,我没有得到成功警报或捕获警报,请给我建议如何解决它

最佳答案

npm 注册表及其存储库中的 react-native-paypal 版本尚未更新以支持最新的 react-native 版本。你可以使用这个 fork https://github.com/sharafat/react-native-paypal相反。

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);
}
}

关于paypal - 集成在使用 react-native-papal 的 android 中抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40785561/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com