BrainTree SDK Bindings for Android & iOS

Hi everyone,

Yet another binding for BrainTreePayment SDK, a PayPal service.

Please check out and report issues if any.

Cheers.

Posts

  • AndrAndr USMember ✭✭

    Greetings,

    I am trying to integrate the iOS DropIn in my project, but I am having trouble doing so.

    When calling any of the methods, I get errors such as:

    Could not create an native instance of the type "BraintreeDropIn.BTDropInRequest": the native class hasn't been loaded.

    Here is the simple code I am using, based on the documentation:
    private void ShowBraintreeDropIn(string clientTokenOrTokenizationKey)
    {
    var request = new BTDropInRequest();
    var dropIn = new BTDropInController(clientTokenOrTokenizationKey, request, HandleBTDropInControllerHandler);
    PresentViewController(dropIn, false, null);
    }

            void HandleBTDropInControllerHandler(BTDropInController controller, BTDropInResult result, Foundation.NSError error)
            {
                if (error != null)
                {
                    System.Diagnostics.Debug.WriteLine("ERROR");
                }
                else if (result != null && result.Cancelled == true)
                {
                    System.Diagnostics.Debug.WriteLine("CANCELLED");
                }
                else
                {
                    Button.SetTitle(result.PaymentDescription, UIControlState.Normal);
    
                    var selectedPaymentOptionType = result.PaymentOptionType;
                    var selectedPaymentMethod = result.PaymentMethod;
                    var selectedPaymentMethodIcon = result.PaymentIcon;
                    var selectedPaymentMethodDescription = result.PaymentDescription;
                }
                controller.DismissViewController(true, null);
            }
    

    Can anyone help?

  • tuyenvtuyenv VNUniversity ✭✭✭

    Let me try then.

  • AndrAndr USMember ✭✭
    edited June 2017

    After cleaning and rebuilding the project, the app crashes on startup without any errors.

    Simulator log:

    (UIKitApplication:com.XXXX.XXXXXXXX[0x476b][3347][3499]): Service exited due to Abort trap: 6

  • AndrAndr USMember ✭✭
    edited June 2017

    This is really weird, but the project runs without issues, with the added packages and Using statement.

    But, as soon as I add any of the IOS Dropin classes, it crashes at launch.

    Adding something as simples as the following replicates my issue:

    var request = new BTDropInRequest();

  • tuyenvtuyenv VNUniversity ✭✭✭

    Could you share the code you run?

  • AndrAndr USMember ✭✭

    Yes, sure. Here it is.

    `
    using System;

    using UIKit;
    using BraintreeDropIn;

    namespace HealthBooking.iOS
    {
    public partial class ViewController : UIViewController
    {
    public ViewController(IntPtr handle) : base(handle)
    {
    }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
    
            // Perform any additional setup after loading the view, typically from a nib.
            Button.AccessibilityIdentifier = "myButton";
            Button.TouchUpInside += delegate
            {
                ShowBraintreeDropIn("MY_KEY_HIDDEN_FOR_PUBLIC_EXPOSURE");
            };
        }
    
        public override void DidReceiveMemoryWarning()
        {
            base.DidReceiveMemoryWarning();
            // Release any cached data, images, etc that aren't in use.     
        }
    
        private void ShowBraintreeDropIn(string clientTokenOrTokenizationKey)
        {
            var request = new BTDropInRequest();
            var dropIn = new BTDropInController(clientTokenOrTokenizationKey, request, HandleBTDropInControllerHandler);
            PresentViewController(dropIn, false, null);
        }
    
        void HandleBTDropInControllerHandler(BTDropInController controller, BTDropInResult result, Foundation.NSError error)
        {
            if (error != null)
            {
                System.Diagnostics.Debug.WriteLine("ERROR");
            }
            else if (result != null && result.Cancelled == true)
            {
                System.Diagnostics.Debug.WriteLine("CANCELLED");
            }
            else
            {
                Button.SetTitle(result.PaymentDescription, UIControlState.Normal);
    
                var selectedPaymentOptionType = result.PaymentOptionType;
                var selectedPaymentMethod = result.PaymentMethod;
                var selectedPaymentMethodIcon = result.PaymentIcon;
                var selectedPaymentMethodDescription = result.PaymentDescription;
            }
            controller.DismissViewController(true, null);
        }
    
    }
    

    }`

  • tuyenvtuyenv VNUniversity ✭✭✭

    Thank you for reporting issue. It's fixed now :). Plz enjoy and report issues if any. It's better to log an issue on GitHub :).

  • AndrAndr USMember ✭✭

    I will ;) Thank you for the support.

    Cheers.

  • Yannis.0214Yannis.0214 USMember ✭✭

    @tuyenv Hi - I need to use the Braintree DropInRequest in a Xamarin Android project in order to use Paypal - I'm following this - https://developers.braintreepayments.com/start/hello-client/android/v2#present-drop-in-ui

    I've downloaded your binding here - https://github.com/NAXAM/xand-braintree-sdk it doesn't appear to build on a Mac (2 errors):

    Error CS0113: A member `Com.Braintreepayments.Api.Exceptions.ErrorWithResponse.Message' marked as override cannot be marked as new or virtual (CS0113) (Naxam.BrainTree.Droid)

    Error CS0113: A member `Com.Braintreepayments.Api.Exceptions.GoogleApiClientException.Message' marked as override cannot be marked as new or virtual (CS0113) (Naxam.BrainTree.Droid)

    I'm going to try on Windows on Visual Studio, but in the meantime can you confirm if the full DropIn library is available within this binding?

    Cheers!
    Y

  • Yannis.0214Yannis.0214 USMember ✭✭

    Hey Vu

    I've got around the build errors by using the Nuget Packages instead.

    Only thing I can't figure out is how to access them in a Xamarin Android project - using Naxam etc, does resolve?

    Could you advise please?

    Thanks again!

  • tuyenvtuyenv VNUniversity ✭✭✭

    @Yannis.0214,

    You should get it by VS QuickFix feature.

    Otherwise, plz try Com.BrainTree.

    We don't change the namespace of binding package.

    Cheers.

  • Yannis.0214Yannis.0214 USMember ✭✭

    @tuyenv Cheers! I can access

    using Com.Braintreepayments.Api;
    using Com.Braintreepayments.Browserswitch;

    Could you advise how to access the DropIn components - I'm trying to follow this tutorial:

    https://developers.braintreepayments.com/guides/drop-in/android/v2

    Thanks again!

  • tuyenvtuyenv VNUniversity ✭✭✭

    We haven't create binding for DropIn yet :).

  • Yannis.0214Yannis.0214 USMember ✭✭

    @tuyenv Ah ok! Do you have any plans on doing this? ... you would be the first to do it! ;)

    Cheers

  • tuyenvtuyenv VNUniversity ✭✭✭

    I have been the first for BrainTree already, but if it is created in few minutes I would love to create right away. :)

  • Yannis.0214Yannis.0214 USMember ✭✭

    @tuyenv Could you point me in the direction of any articles / samples which I can use to take a payment using a Paypal account which doesn't require the DropIn binding, and just uses your (excellent) Braintree binding?

    Thanks again!

  • tuyenvtuyenv VNUniversity ✭✭✭
    edited August 2017

    @Yannis.0214 Plz ask BrainTree on that case. :) I could help right away to create the binding with a paid price.

    Cheers.

  • Yannis.0214Yannis.0214 USMember ✭✭

    @tuyenv How much would you charge to create the DropIn binding for Xamarin Android?

  • tuyenvtuyenv VNUniversity ✭✭✭

    @Yannis.0214, I sent you a private message.

  • My application is crashing on launch when using your libraries. I dont get any crash message, it just drops after launch screen. Any ideas?

  • tuyenvtuyenv VNUniversity ✭✭✭

    Hi @JamesRoche.0538 ,

    Thank you for using our binding.

    With your provided info, I couldn't help.

    We provide paid service to help you integrate successfully with external library like this.

    Plz send an email to me if in case.

    Regards,
    Tuyen

  • SivaShankarArumugamSivaShankarArumugam USMember ✭✭✭

    @tuyenv We are planning to implement the BrainTree payment in Xamarin.forms for android and iOS. Can you give me some steps or guideline to implement the Braintree. Like for android which file to convert for binding library, similary for iOS.

  • veeru3112veeru3112 INMember ✭✭

    Can you please give me the link from where you got .jar files ?

  • SirAndriySirAndriy USMember ✭✭✭

    Hi @tuyenv, I have an issue with adding card.io functionality to iOS DropIn. This feature was implementing in BrainTreePayment SDK in version 5.1.0. So, can you explain, how to add card.io functionality to your binding.

    p.s. for android it's works

  • tuyenvtuyenv VNUniversity ✭✭✭
    edited May 17

    @SirAndriy Have you followed guide from BrainTree?

    @SivaShankarArumugam Have you got it done? What you have to do is to follow BrainTree document.

    Xamarin its idea is to help C# guys code Android/iOS with same APIs from Java/ObjC world, so official document in Java/ObjC is all enough.

  • SirAndriySirAndriy USMember ✭✭✭

    Hi @tuyenv, yes I followed guide from BrainTree, like on android it need only to add card.io lib, anyway now all works - build clean up and rebuild helped, thx

  • DinoNovak.3412DinoNovak.3412 USMember ✭✭

    Hi @tuyenv, I have added Naxam.BraintreeDropIn.Droid package to android project.

    also I added references to:
    using Com.Braintreepayments.Api;
    using Com.Braintreepayments.Browserswitch;
    using Com.Braintreepayments.Cardform;

    To initiate the story I need to reference DropInRequest as per Braintree Android instructions
    DropInRequest dropInRequest = new DropInRequest().clientToken(mClientToken);

    how do I reference DropInRequest, I am unable to find how it is named in the binding ?

    I have successfully created iOS project and DropIn Works.

    Thanx,
    D

  • DinoNovak.3412DinoNovak.3412 USMember ✭✭

    HI,

    found the workaround for using dropin (stupid me):
    using Com.Braintreepayments.Api.Dropin;

    so I can create a request
    var request = new DropInRequest().ClientToken(clientTokenOrTokenizationKey);

    but would appreciate some help how to show the dropin afterwards, how to you correctly translate this to xamarin.android

    startActivityForResult(dropInRequest.getIntent(context), DROP_IN_REQUEST);

  • tuyenvtuyenv VNUniversity ✭✭✭

    Plz don't just copy and past Java code directly to C# without any naming changes. Plz do it slowly and carefully.

    StartActivityForResult(dropInRequest.GetIntent(this), DROP_IN_REQUEST);
    
  • DinoNovak.3412DinoNovak.3412 USMember ✭✭

    HI,

    I am strugling to get correct context for stating the activity, in you answer if I use this then it is braintreeforms.Droid.BraintreePayment which is not correct context

    See code below:

    `[assembly: DependencyAttribute(typeof(BraintreePayment))]
    namespace braintreeforms.Droid
    {
    public class BraintreePayment : IBraintreePayment
    {
    public void ProcessPayment(string something, Action completed = null)
    {
    string clientTokenOrTokenizationKey =SOME_KEY;

            var request = new DropInRequest().ClientToken(clientTokenOrTokenizationKey);
            var appActivity = Android.App.Application.Context as Android.App.Activity;
    
            appActivity.StartActivityForResult(request.GetIntent(context), clientTokenOrTokenizationKey);
    
        }
    
        public void OnActivityResult(int requestCode, int resultCode, Intent data)
        {
    
    
        }
    
    
    
    }
    

    }`

Sign In or Register to comment.