PayPal期货付款活动授权无效

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PayPal期货付款活动授权无效相关的知识,希望对你有一定的参考价值。

我正在使用PayPal移动SDK(android)因为我需要访问REST API,而我正在使用Sandbox。即时付款工作正常,但我无法获得未来付款的授权码。我检查了开发人员门户网站并启用了未来付款,但我认为这是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'对象总是为null,我看不出代码有什么问题,因为它基本上是示例代码。我错过了什么?或者这仅适用于现场环境?谢谢。

答案

做了一个简单的错误,活动需要是PayPalFuturePaymentActivity,而不是PaymentActivity。 PaymentConfirmation对象可用于PaymentActivity,而不是PayPalAuthorization对象。

我在这里找到了一些非常好的PayPal集成示例代码,这可能对其他人有帮助:https://www.csharpcodi.com/vs2/?source=176/PayPal.Forms/MobileApps/PayPal.Forms/PayPalAndroidTest/PayPalManager.cs

以上是关于PayPal期货付款活动授权无效的主要内容,如果未能解决你的问题,请参考以下文章

PayPal 已收费,但付款响应为“无效”

安全标头在 PayPal 批量付款中无效

在 asp.net 中使用 paypal 授权后链式付款

Payflow 使用 PayPal 帐户创建定期付款

Django Paypal 无效的付款日期

PayPal 自适应付款 - 预批准请求导致“无效请求”错误