BrainTree, tokenize card

Hi everyone, i want to tokenize card i my Xamarin.Android application. I already did it in IOS with Naxam.BrainTreee.IOS. For Android exist the same solution, but it doesn't work for me. Do somebody know other ways?
Here is my implementation in IOS with Naxam:

using BraintreeCore;
using BraintreeCard;
` public void TokenizeCard(ICard model)
{
var client = new BTAPIClient(apikey);

        var card = new BTCard(model.Number, model.ExpirationMonth.ToString(), model.ExpirationYear.ToString(), model.CvcCheck);

        var request = new BTCardRequest(card);

        var cardClient = new BTCardClient(client);

        cardClient.TokenizeCard(request, null, (nonce, error) =>
        {
            if (nonce != null)
            {
                result = nonce;
            }
            else
                throw new Exception(error.Description.ToString());
        });
    }`

I have to do the same for Android. I've tried with webview (use in webview JS SDK, but i have some troubles with passing and getting results between app and webview).

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    What have you tried in Xamarin Android?

  • yourzbuddhayourzbuddha Member ✭✭
    edited April 1

    @jezh, hi!
    ` public void TokenizeCard(ICard model)
    {
    var cardModel = new CardBuilder();
    //fill the card
    var fragment = new BraintreeFragment();
    var listener = new Listener();
    fragment.AddListener(listener);

            var btfragment = BraintreeFragment.NewInstance(GetCurrentActivity(), apikey);
    
            Com.Braintreepayments.Api.Card.Tokenize(btfragment, cardModel);
        }
    
    }
    
    class Listener : Java.Lang.Object, IPaymentMethodNonceCreatedListener
    {
    
        PaymentMethodNonce result;
    
        public void OnPaymentMethodNonceCreated(PaymentMethodNonce p0)
        {
            result = p0;
        }`
    

    I'm not sure about listener, also about current activity, maybe you can suggest something. How to subscribe to result and how to get it?

Sign In or Register to comment.