1

I'm using PayPal in my monodroid application. I used the libraray that has been shared in this topic: http://forums.xamarin.com/discussion/comment/15331/#Comment_15331

But i have a problem at getting PaymentConfirmation object at OnActivityResult method. This is my code:

protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
    {
        if (resultCode == Result.Ok ) {
            var confirm =  data.GetParcelableExtra ("com.paypal.android.sdk.paymentConfirmation") ;

            PaymentConfirmation pc = (PaymentConfirmation)confirm;
        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.");
    }
}

at the third line of the method. Compiler can not cast confirm to PaymentConfirmation. Do I need any other classes or codes in order to use data.GetParcelableExtra?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Husein Behboudi Rad
  • 5,434
  • 11
  • 57
  • 115

1 Answers1

1

As written in a comment JavaCast should be used in this case. I think this happens when the binding generated for the type, does not contain a GetType method. Hence .NET does not know what to cast it to.

So your line:

PaymentConfirmation pc = (PaymentConfirmation)confirm;

will need to be:

PaymentConfirmation pc = confirm.JavaCast<PaymentConfirmation>();
Cheesebaron
  • 24,131
  • 15
  • 66
  • 118