6

我正在开发一个 Xamarin 项目集成 Google Pay。我得到了立即购买按钮,但是当我按下它时,我收到了这条消息:“此付款选项在此应用程序中不再可用”

我使用 Stripe 作为支付网关,并使用测试环境。这是我正在使用的活动。它继承了 FragmentActivity,并实现了 GoogleApiClient.IConnectionCallbacks 和 GoogleApiClient.IOnConnectionFailedListener

 public void SetupWallet()
            {
                _walletFragment = SupportWalletFragment.NewInstance(WalletFragmentOptions.NewBuilder()
                    .SetEnvironment(WalletConstants.EnvironmentTest)
                     .SetMode(WalletFragmentMode.BuyButton)
                    .SetTheme(WalletConstants.ThemeLight)
                    .SetFragmentStyle(new WalletFragmentStyle()
                    .SetBuyButtonText(BuyButtonText.BuyWithGoogle)
                    .SetBuyButtonAppearance(BuyButtonAppearance.Classic)
                    .SetBuyButtonWidth(Dimension.MatchParent))
                    .Build());

                var maskedWalletRequest = MaskedWalletRequest.NewBuilder()

                // Request credit card tokenization with Stripe
                .SetPaymentMethodTokenizationParameters(
                    PaymentMethodTokenizationParameters.NewBuilder()
                        .SetPaymentMethodTokenizationType(PaymentMethodTokenizationType.PaymentGateway)
                        .AddParameter("gateway", "stripe")
                        .AddParameter("stripe:publishableKey", AppConfig.StripeApiKey)
                        .AddParameter("stripe:version", "2018-02-06")
                        .Build())
                    .SetMerchantName("My Name")
                    .SetPhoneNumberRequired(false)
                    .SetShippingAddressRequired(false)
                    .SetEstimatedTotalPrice("20.00")
                    .SetCurrencyCode("USD")
                    .Build();

                _walletFragment.Initialize(WalletFragmentInitParams.NewBuilder()
                    .SetMaskedWalletRequest(maskedWalletRequest)
                    .SetMaskedWalletRequestCode(LOAD_MASKED_WALLET_REQ_CODE)
                    .Build());

                SupportFragmentManager.BeginTransaction()
                    .Replace(Resource.Id.dynamic_wallet_button_fragment, _walletFragment).Commit();
            }




       protected override void OnStart()
        {
            base.OnStart();
            _googleApiClient.Connect();
        }

        protected override void OnStop()
        {
            base.OnStop();
            _googleApiClient.Disconnect();
        }

        private void CheckAndroidPayAvailable()
        {
            var result = WalletClass.Payments.IsReadyToPay(_googleApiClient);
            result.SetResultCallback(new AndroidPayCallback(_walletFragment));

        }

protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.google_play_activity);

            _googleApiClient = new GoogleApiClient.Builder(((MainActivity)Forms.Context).ApplicationContext)
               .AddConnectionCallbacks(this)
               .AddOnConnectionFailedListener(this)
               .AddApi(WalletClass.API, new WalletClass.WalletOptions.Builder()
                     .SetEnvironment(WalletConstants.EnvironmentTest)
                     .Build())
                     .EnableAutoManage(this, this)
               .Build();

            SetupWallet();
            CheckAndroidPayAvailable();
        }
4

0 回答 0