PayPal将来的付款活动授权null



我正在使用paypal移动SDK(Android),因为我需要访问REST API,并且我正在使用Sandbox。立即付款正常,但我无法获得未来付款的授权代码。我已经检查了开发人员门户网站,并启用了未来的付款,尽管我认为这是沙箱的默认值。我正在使用Xamarin Android(C#):

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="ShoezApp.Android">
  <!--This will default to ShoezApp.ShoezApp if no second part is specified-->
  <uses-sdk android:minSdkVersion="19" />
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <!-- admob permissions-->
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

  <application android:label="ShoezApp" android:icon="@drawable/icon">
    <activity android:name="com.microsoft.windowsazure.mobileservices.authentication.RedirectUrlActivity" android:launchMode="singleTop" android:noHistory="true">
      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="shoezapp" android:host="easyauth.callback" />
      </intent-filter>
    </activity>
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
    <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" />
  </application>
</manifest>

代码:

public class PayPalDroid : IPayPalService
    {
        private PayPalConfiguration config = new PayPalConfiguration()
            .Environment(PayPalConfiguration.EnvironmentSandbox)
            .ClientId("AeX06w97L702sEFGK5ZB4Tc4Veyo4oOzopS9DgKiHCDVgD4O0mGeZoNl1t-sFWAmRXyzyx87Y1mupJ1W")
            .MerchantName("Example Merchant")
            .MerchantPrivacyPolicyUri(Android.Net.Uri.Parse("https://www.example.com/privacy"))
            .MerchantUserAgreementUri(Android.Net.Uri.Parse("https://www.example.com/legal"));
        //only calls default constructor with dependency injection, so this is necessary
        public PayPalDroid()  {}
        private int REQUEST_CODE_PAYMENT = 1;
        private int REQUEST_CODE_FUTURE_PAYMENT = 2;
        private int REQUEST_CODE_PROFILE_SHARING = 3;
        public Task<string> RequestPayPal()
        {
            Context context = MainActivity.Instance;
            MainActivity activity = (MainActivity)context;
            //create the listener
            var listener = new ActivityResultListener(activity);
            // start paypal service - this must be done each time
            var intent = new Intent(context, typeof(PayPalService));
            intent.PutExtra(PayPalService.ExtraPaypalConfiguration, config);
            context.StartActivity(Intent.CreateChooser(intent, "Request PayPal transaction"));
            var payment = new PayPalPayment(new Java.Math.BigDecimal("2.45"), "USD", "the item",
                PayPalPayment.PaymentIntentSale);
            intent = new Intent(context, typeof(PaymentActivity));
            intent.PutExtra(PayPalService.ExtraPaypalConfiguration, config);
            intent.PutExtra(PaymentActivity.ExtraPayment, payment);
            activity.StartActivityForResult(Intent.CreateChooser(intent, "PayPal transaction complete"), REQUEST_CODE_FUTURE_PAYMENT);
            return listener.Task;
        }

        private class ActivityResultListener
        {
            private TaskCompletionSource<string> Complete = new TaskCompletionSource<string>();
            public Task<string> Task { get { return this.Complete.Task; } }
            MainActivity Activity;
            public ActivityResultListener(MainActivity activity)
            {
                Activity = activity;
                // subscribe to activity results
                activity.ActivityResult += OnActivityResult;
            }
            private void OnActivityResult(int requestCode, Result resultCode, Intent data)
            {
                // unsubscribe from activity results
                Activity.ActivityResult -= OnActivityResult;
                // process result
                if (resultCode == Result.Ok)
                {
                    Object auth = data.GetParcelableExtra(PayPalFuturePaymentActivity.ExtraResultAuthorization);
                    if (auth != null) //**THIS IS ALWAYS NULL**//
                    {
                        try
                        {
                            //string authorization_code = auth.AuthorizationCode;
                            //sendAuthorizationToServer(auth);
                        }
                        catch (Exception e)
                        {
                            //Log.e("FuturePaymentExample", "an extremely unlikely failure occurred: ", e);
                        }
                    }
                }
                Complete.TrySetResult(resultCode.ToString());
                Context context = MainActivity.Instance;
                var intent = new Intent(context, typeof(PayPalService));
                context.StopService(intent);
            }
        }
    }

没有授权代码,我将无法进一步(即服务器端编码)。问题是" auth"对象始终为空,我看不到代码的任何错误,因为它基本上是示例代码。我想念什么?还是仅在实时环境中起作用?谢谢。

犯了一个简单的错误,活动必须是paypalfuturepaypaypaysactivity,而不是支付额。付款确认对象可用于支付性,而不是paypalauthorization对象。

我在这里找到了一些非常好的贝宝集成示例代码,这可能对他人有帮助:https://www.csharpcodi.com/vs2/?source=176/paypal.forms/mobileapps/paypal.forms/paypal.forms/paypalandroidtest/paypalmanager.cs

相关内容

  • 没有找到相关文章

最新更新