0

我正在尝试向我的 monodroid 应用程序添加贝宝付款。

我正在使用这个库:https ://github.com/paypal/PayPal-Android-SDK 。当然,它的单体版本在这里http://forums.xamarin.com/discussion/4496/creating-java-library-binding-for-paypal-sdk

现在我的代码是这样的:

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

        // Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);

//



// Get our button from the layout resource,
//          // and attach an event to it
//          Button button = FindViewById<Button> (Resource.Id.myButton);
//          
//          button.Click += delegate {
//
//          };



        Intent intent = new Intent(this,typeof(PayPalService));

        // live: don't put any environment extra
        // sandbox: use PaymentActivity.ENVIRONMENT_SANDBOX

        intent.PutExtra (PaymentActivity.ExtraPaypalEnvironment , PaymentActivity.EnvironmentNoNetwork   );
        intent.PutExtra (PaymentActivity.ExtraClientId , "credential from developer.paypal.com");
        intent.PutExtra (PaymentActivity.ExtraReceiverEmail , "matching paypal email address");


        StartService  (intent);

    }


    public   void OnBuyPressed(View pressed) {
        PayPalPayment thingToBuy = new PayPalPayment(new BigDecimal("1.75"), "USD", "hipster jeans");

        Intent intent = new Intent(this, typeof(PaymentActivity));

        intent.PutExtra (PaymentActivity.ExtraPaypalEnvironment , PaymentActivity.EnvironmentNoNetwork   );
        intent.PutExtra (PaymentActivity.ExtraClientId , "credential from developer.paypal.com");
        intent.PutExtra (PaymentActivity.ExtraReceiverEmail , "matching paypal email address");

        // It's important to repeat the clientId here so that the SDK has it if Android restarts your 
        // app midway through the payment UI flow.
        intent.PutExtra (PaymentActivity.ExtraClientId, "credential from developer.paypal.com");
        intent.PutExtra (PaymentActivity.ExtraPayerId, "your-customer-id-in-your-system");
        intent.PutExtra (PaymentActivity.ExtraPayment, thingToBuy);

        StartActivityForResult(intent, 0);
    }

    protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
    {
        if (resultCode == Result.Ok ) {
            PaymentConfirmation confirm =(PaymentConfirmation) data.GetParcelableExtra (PaymentActivity.ExtraResultConfirmation);
            if (confirm != null) {
                try {
                    Log.Info ("paymentExample", confirm.ToJSONObject ().ToString (4));
                    // TODO: send 'confirm' to your server for verification.
                    // see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
                    // for more details.\
                } catch (JSONException e) {
                    Log.Error ("paymentExample", "an extremely unlikely failure occurred: ", e);
                }
            }
        }else if (resultCode == Result.Canceled ) {
            Log.Info ("paymentExample", "The user canceled.");
        }else {
            Log.Info ("paymentExample", "An invalid payment was submitted. Please see the docs.");
        }
    }

    protected override void OnDestroy ()
    {
        StopService (new Intent(this,typeof( PayPalService)));
        base.OnDestroy ();
    }

但是当我运行应用程序时,应用程序中没有任何内容。虽然 githup 中的示例代码有效。

任何人都可以就我的问题给我建议吗?

4

1 回答 1

0

您应该在 OnBuyPressed 方法中添加一个按钮 onclick 事件。在示例中,该方法已设置为布局代码上的事件。

于 2013-10-12T10:35:36.887 回答