Beispiel #1
0
        public void Payment(PaymentViewModel payment, JudoSuccessCallback success, JudoFailureCallback failure, Activity context)
        {
            EvaluateRootCheck(failure);
            var innerModel = payment.Clone();

            _judoSdkApi.Payment(innerModel, success, failure, context);
        }
        public void BuyBeer(BeerPaymentViewModel beerPaymentModel)
        {
            PaymentViewModel judoModel = new PaymentViewModel()
            {
                Amount            = beerPaymentModel.GetSubTotal(),
                Currency          = "GBP",
                ConsumerReference = "ImHereForTheBeer01",
                Card = new CardViewModel()
            };
            JudoSuccessCallback successCallback = SuccessPayment;
            JudoFailureCallback failureCallback = FailurePayment;

            if (String.IsNullOrEmpty(Client.Instance.PaymentToken.CardToken))
            {
                Judo.Instance.Payment(judoModel, successCallback, failureCallback);
            }
            else
            {
                TokenPaymentViewModel tokenModel = new TokenPaymentViewModel()
                {
                    Amount            = beerPaymentModel.GetSubTotal(),
                    Currency          = "GBP",
                    ConsumerReference = "ImHereForTheBeer01",
                    Token             = Client.Instance.PaymentToken.CardToken,
                    ConsumerToken     = Client.Instance.PaymentToken.ConsumerToken,
                    LastFour          = Client.Instance.PaymentToken.CardLastfour,
                    CardType          = (CardType)Client.Instance.PaymentToken.CardType
                };
                Judo.Instance.TokenPayment(tokenModel, successCallback, failureCallback);
            }
        }
        /// <summary>
        /// Process a card payment
        /// </summary>
        /// <param name="payment">PaymentViewModel to pass Amount and card detail</param>
        /// <param name="success">Callback for success transaction</param>
        /// <param name="failure">Callback for fail transaction</param>
        /// <param name="navigationController">Navigation controller from UI this can be Null for non-UI Mode API</param>
        public void Payment(PaymentViewModel payment, JudoSuccessCallback success, JudoFailureCallback failure)
        {
            RootCheck(failure);

            var innerModel = payment.Clone();

            _judoSdkApi.Payment(innerModel, success, failure);
        }
		public JudoPKPaymentAuthorizationViewControllerDelegate(Judo judo, ApplePayModel applePayModel, JudoSuccessCallback success, JudoFailureCallback failure, IApplePayRequest applePayRequest)
		{
			_successCallBack = success;
			_failureCallback = failure;
			_applePayModel = applePayModel;
			_judo = judo;
			_applePayRequest = applePayRequest;
		}
        private void HandleResponse(JudoSuccessCallback success, JudoFailureCallback failure, Task <IResult <ITransactionResult> > reponse)
        {
            var result = reponse.Result;

            if (result != null && !result.HasError && result.Response.Result != "Declined")
            {
                var secureReceipt = result.Response as PaymentRequiresThreeDSecureModel;
                if (secureReceipt != null)
                {
                    var judoError = new JudoError {
                        ApiError = result != null ? result.Error : null
                    };
                    failure(new JudoError {
                        ApiError = new JudoPayDotNet.Errors.JudoApiErrorModel {
                            ErrorMessage = "Account requires 3D Secure but non UI Mode does not support this",
                            ErrorType    = JudoApiError.General_Error,
                            ModelErrors  = null
                        }
                    });
                }

                var paymentReceipt = result.Response as PaymentReceiptModel;

                if (success != null)
                {
                    success(paymentReceipt);
                }
                else
                {
                    throw new Exception("SuccessCallback is not set.");
                }
            }
            else
            {
                // Failure
                if (failure != null)
                {
                    var judoError = new JudoError {
                        ApiError = result != null ? result.Error : null
                    };
                    var paymentreceipt = result != null ? result.Response as PaymentReceiptModel : null;

                    if (paymentreceipt != null)
                    {
                        // send receipt even we got card declined
                        failure(judoError, paymentreceipt);
                    }
                    else
                    {
                        failure(judoError);
                    }
                }
                else
                {
                    throw new Exception("FailureCallback is not set.");
                }
            }
        }
Beispiel #6
0
 public JudoPKPaymentAuthorizationViewControllerDelegate(IApplePayService applePayService, PKPaymentRequest request, string customerRef, ApplePaymentType type, JudoSuccessCallback success, JudoFailureCallback failure)
 {
     _applePayService = applePayService;
     _runningTotal    = request.PaymentSummaryItems [request.PaymentSummaryItems.Length - 1].Amount;
     _paymentAction   = type;
     _successCallBack = success;
     _failureCallback = failure;
     _customerRef     = customerRef;
 }
 public void PreAuth(PaymentViewModel payment, JudoSuccessCallback success, JudoFailureCallback failure, Activity context)
 {
     try {
         _paymentService.PreAuthoriseCard(payment, new ClientService()).ContinueWith(reponse => HandleResponse(success, failure, reponse));
     } catch (Exception ex) {
         // Failure
         HandleFailure(failure, ex);
     }
 }
Beispiel #8
0
 public void Payment(PaymentViewModel payment, JudoSuccessCallback success, JudoFailureCallback failure)
 {
     try {
         _paymentService.MakePayment(payment, new ClientService()).ContinueWith(reponse => HandResponse(success, failure, reponse));
     } catch (Exception ex) {
         // Failure
         HandleFailure(failure, ex);
     }
 }
        public void BuyBeerApplePay(BeerPaymentViewModel beerModel)
        {
            if (_clientService.ApplePayAvailable)
            {
                JudoSuccessCallback successCallback = SuccessPayment;
                JudoFailureCallback failureCallback = FailurePayment;

                Judo.Instance.MakeApplePreAuth(GetApplePayViewModel(beerModel), successCallback, failureCallback);        
            }
        }
 private void HandleFailure(JudoFailureCallback failure, Exception ex)
 {
     if (failure != null)
     {
         var judoError = new JudoError {
             Exception = ex
         };
         failure(judoError);
     }
 }
Beispiel #11
0
 void EvaluateRootCheck(JudoFailureCallback failure)
 {
     if (!AllowRooted && isRooted)
     {
         failure(new JudoError()
         {
             Exception = new Exception("Users Device is rooted and app is configured to block calls from rooted Device"),
             ApiError  = null
         });
     }
 }
 void RootCheck(JudoFailureCallback failure)
 {
     if (!AllowRooted && JudoShield.IsiOSRooted())
     {
         failure(new JudoError()
         {
             Exception = new Exception("Users Device is rooted and app is configured to block calls from rooted Device"),
             ApiError  = null
         });
     }
 }
        public void Payment(PaymentViewModel payment, JudoSuccessCallback success, JudoFailureCallback failure, Activity context)
        {
            Intent i = new Intent(context, typeof(UIMethods));

            i.PutExtra(JudoSDKManager.REQUEST_CODE, ACTION_CARD_PAYMENT.ToString());
            i.PutExtra(JudoSDKManager.JUDO_PAYMENT_REF, payment.PaymentReference);
            i.PutExtra(JudoSDKManager.JUDO_CONSUMER, JsonConvert.SerializeObject(new Consumer()
            {
                YourConsumerReference = payment.ConsumerReference
            }));
            i.PutExtra(JudoSDKManager.JUDO_AMOUNT, payment.Amount.ToString());
            i.PutExtra(JudoSDKManager.JUDO_ID, (String.IsNullOrWhiteSpace(payment.JudoID) ? JudoConfiguration.Instance.JudoId : payment.JudoID));
            i.PutExtra(JudoSDKManager.JUDO_CURRENCY, payment.Currency);
            _judoSuccessCallback = new Lazy <JudoSuccessCallback> (() => success);
            _judoFailureCallback = new Lazy <JudoFailureCallback> (() => failure);

            context.StartActivityForResult(i, ACTION_CARD_PAYMENT);
        }
Beispiel #14
0
		void PerformApplePayAction(Judo judo, ApplePayModel model, JudoSuccessCallback success, JudoFailureCallback failure, IApplePayRequest applePayRequest)
		{
			try
			{
				PKPaymentRequest request = GetPKPaymentRequest(model);
				var rootView = GetCurrentViewController();
				var pkDelegate = new JudoPKPaymentAuthorizationViewControllerDelegate(judo, model, success, failure, applePayRequest);

				PKPaymentAuthorizationViewController pkController = new PKPaymentAuthorizationViewController(request) { Delegate = pkDelegate };
				rootView.PresentViewController(pkController, true, null);

			}
			catch (Exception e)
			{
				var judoError = new JudoError { Exception = e.InnerException };
				failure(judoError);
			}
		}
Beispiel #15
0
        public void Payment(PaymentViewModel payment, JudoSuccessCallback success, JudoFailureCallback failure)
        {
            var vc = GetCurrentViewController();

            if (JudoSDKManager.UIMode && vc == null)
            {
                var error = new JudoError {
                    Exception = new Exception("Navigation controller cannot be null with UIMode enabled.")
                };
                failure(error);
            }
            else
            {
                var view = _viewLocator.GetPaymentView();
                view.successCallback = success;
                view.failureCallback = failure;
                view.cardPayment     = payment;

                PresentView(vc as UINavigationController, view);
            }
        }
        public static void FlattenToJudoFailure(this AggregateException errors, JudoFailureCallback failureCallback)
        {
            if (failureCallback != null)
            {
                List <JudoModelError> models = new List <JudoModelError> ();
                foreach (Exception em in errors.InnerExceptions)
                {
                    models.Add(new JudoModelError()
                    {
                        ErrorMessage = em.Message
                    });
                }
                var judoError = new JudoError()
                {
                    Exception = errors.InnerException,
                    ApiError  = new JudoApiErrorModel()
                    {
                        ModelErrors = models
                    }
                };

                failureCallback(judoError);
            }
        }
Beispiel #17
0
        public void PreAuth(PaymentViewModel preAuthorisation, JudoSuccessCallback success, JudoFailureCallback failure)
        {
            var vc = GetCurrentViewController();

            if (JudoSDKManager.UIMode && vc == null)
            {
                var error = new JudoError {
                    Exception = new Exception("Navigation controller cannot be null with UIMode enabled.")
                };
                failure(error);
            }
            else
            {
                var view = _viewLocator.GetPreAuthView();

                // register card and pre Auth sharing same view so we need to set this property to false
                view.successCallback    = success;
                view.failureCallback    = failure;
                view.authorisationModel = preAuthorisation;
                PresentView(vc as UINavigationController, view);
            }
        }
Beispiel #18
0
		public void PreAuth(Judo judo, ApplePayModel model, JudoSuccessCallback success, JudoFailureCallback failure)
		{
			var paymentService = GetPaymentService(judo);
			PerformApplePayAction(judo, model, success, failure, new ApplePayPreAuthRequest(paymentService));
		}
Beispiel #19
0
        public void MakeApplePayment(ApplePayViewModel payment, JudoSuccessCallback success, JudoFailureCallback failure, UINavigationController controller, ApplePaymentType type)
        {
            try {
                PKPaymentRequest request = new PKPaymentRequest();

                request.CurrencyCode = payment.CurrencyCode;

                request.CountryCode = payment.CountryCode;

                request.MerchantCapabilities = (PKMerchantCapability)payment.MerchantCapabilities;


                request.SupportedNetworks = payment.SupportedNetworks;


                request.PaymentSummaryItems = payment.Basket;

                request.MerchantIdentifier = payment.MerchantIdentifier;// @"merchant.com.judo.Xamarin"; // do it with configuration/overwrite

                var pkDelegate = new JudoPKPaymentAuthorizationViewControllerDelegate(this, request, payment.ConsumerRef.ToString(), type, success, failure);



                PKPaymentAuthorizationViewController pkController = new PKPaymentAuthorizationViewController(request)
                {
                    Delegate = pkDelegate
                };
                controller.PresentViewController(pkController, true, null);
            } catch (Exception e) {
                Console.WriteLine(e.InnerException.ToString());

                var judoError = new JudoError()
                {
                    Exception = e
                };
                failure(judoError);
            }
        }
        public void ApplePayment(ApplePayViewModel viewModel, JudoSuccessCallback success, JudoFailureCallback failure, ApplePaymentType type)
        {
            if (!_clientService.ApplePayAvailable)
            {
                failure(new JudoError {
                    ApiError = new JudoPayDotNet.Errors.JudoApiErrorModel {
                        ErrorMessage = "Apple Pay is not enabled on device, application entitlement or setup by user.",
                        ErrorType    = JudoApiError.General_Error,
                        ModelErrors  = null
                    }
                });
            }
            try {
                var vc = GetCurrentViewController();

                if (JudoSDKManager.UIMode && vc == null)
                {
                    var error = new JudoError {
                        Exception = new Exception("Navigation controller cannot be null with UIMode enabled.")
                    };
                    failure(error);
                }
                else
                {
                    _paymentService.MakeApplePayment(viewModel, success, failure, vc as UINavigationController, type);
                }
            } catch (Exception ex) {
                HandleFailure(failure, ex);
            }
        }
Beispiel #21
0
        public async Task <IResult <ITransactionResult> > HandlePKPayment(PKPayment payment, string customerRef, NSDecimalNumber amount, ApplePaymentType type, JudoFailureCallback failure)
        {
            try {
                CardPaymentModel paymentmodel = new CardPaymentModel {
                    JudoId        = JudoConfiguration.Instance.JudoId,
                    ClientDetails = _clientService.GetClientDetails(),
                    UserAgent     = _clientService.GetSDKVersion()
                };


                var            test    = payment.Token.PaymentData.ToString(NSStringEncoding.UTF8);
                JObject        jo      = JObject.Parse(test.ToString());
                PKPaymentModel pkModel = new PKPaymentModel()
                {
                    JudoId = JudoConfiguration.Instance.JudoId,
                    YourPaymentReference  = "paymentRef12343",
                    YourConsumerReference = customerRef,
                    Amount        = amount.ToDecimal(),
                    ClientDetails = _clientService.GetClientDetails(),
                    UserAgent     = _clientService.GetSDKVersion(),
                    PkPayment     = new PKPaymentInnerModel()
                    {
                        Token = new PKPaymentTokenModel()
                        {
                            PaymentData           = jo,
                            PaymentInstrumentName = payment.Token.PaymentInstrumentName,
                            PaymentNetwork        = payment.Token.PaymentNetwork
                        }
                    }
                };
                Task <IResult <ITransactionResult> > task = null;
                if (type == ApplePaymentType.Payment)
                {
                    task = _judoAPI.Payments.Create(pkModel);
                }
                else if (type == ApplePaymentType.PreAuth)
                {
                    task = _judoAPI.PreAuths.Create(pkModel);
                }
                if (task == null)
                {
                    var judoError = new JudoError()
                    {
                        Exception = new Exception("Judo server did not return response. Please contact customer support")
                    };
                    failure(judoError);
                }
                return(await task);
            } catch (Exception e) {
                Console.WriteLine(e.InnerException.ToString());
                var judoError = new JudoError()
                {
                    Exception = e
                };
                failure(judoError);
                return(null);
            }
        }
Beispiel #22
0
        void SetUpTableView()
        {
            Dictionary <string, Action> buttonDictionary = new Dictionary <string, Action> ();
            JudoSuccessCallback         successCallback  = SuccessPayment;
            JudoFailureCallback         failureCallback  = FailurePayment;

            var tokenPayment = new TokenPaymentViewModel()
            {
                Amount            = 3.5m,
                ConsumerReference = consumerRef,
                CV2 = cv2
            };

            buttonDictionary.Add("Make a Payment", delegate {
                Judo.Instance.Payment(GetCardViewModel(), successCallback, failureCallback);
            });



            buttonDictionary.Add("PreAuthorise", delegate {
                Judo.Instance.PreAuth(GetCardViewModel(), successCallback, failureCallback);
            });


            buttonDictionary.Add("Token Payment", delegate {
                tokenPayment.Token         = cardToken;
                tokenPayment.ConsumerToken = consumerToken;
                tokenPayment.LastFour      = lastFour;
                tokenPayment.CardType      = cardType;

                Judo.Instance.TokenPayment(tokenPayment, successCallback, failureCallback);
            });

            buttonDictionary.Add("Token PreAuthorise", delegate {
                tokenPayment.Token         = cardToken;
                tokenPayment.ConsumerToken = consumerToken;
                tokenPayment.LastFour      = lastFour;
                tokenPayment.CardType      = cardType;

                Judo.Instance.TokenPreAuth(tokenPayment, successCallback, failureCallback);
            });

            buttonDictionary.Add("Register a Card", delegate {
                var payment    = GetCardViewModel();
                payment.Amount = 1.01m; //Minimum amount Gateways accept without question

                Judo.Instance.RegisterCard(payment, successCallback, failureCallback);
            });
            if (_clientService.ApplePayAvailable)
            {
                buttonDictionary.Add("Make a ApplePay Payment", delegate {
                    Judo.Instance.MakeApplePayment(GetApplePayViewModel(), successCallback, failureCallback);
                });

                buttonDictionary.Add("Make a ApplePay PreAuthorise", delegate {
                    Judo.Instance.MakeApplePreAuth(GetApplePayViewModel(), successCallback, failureCallback);
                });
            }

            MainMenuSource menuSource = new MainMenuSource(buttonDictionary);

            ButtonTable.Source            = menuSource;
            TableHeightConstrant.Constant = menuSource.GetTableHeight() + 60f;
        }
        public void MakeApplePreAuth(ApplePayViewModel payment, JudoSuccessCallback success, JudoFailureCallback failure)
        {
            RootCheck(failure);

            _applePayMethods.ApplePayment(payment, success, failure, ApplePaymentType.PreAuth);
        }
        /// <summary>
        /// Process a RegisterCard
        /// </summary>
        /// <param name="registerCard">TokenPaymentViewModel to pass Amount and Token detail</param>
        /// <param name="success">Callback for success transaction</param>
        /// <param name="failure">Callback for fail transaction</param>
        /// <param name="navigationController">Navigation controller from UI this can be Null for non-UI Mode API</param>
        public void RegisterCard(PaymentViewModel registerCard, JudoSuccessCallback success, JudoFailureCallback failure)
        {
            if (registerCard.Amount == 0)
            {
                registerCard.Amount = 1.01m;
            }

            RootCheck(failure);

            var innerModel = registerCard.Clone();

            _judoSdkApi.RegisterCard(innerModel, success, failure);
        }
        /// <summary>
        /// Process a pre-authorisation payment
        /// </summary>
        /// <param name="preAuthorisation">PaymentViewModel to pass Amount and card detail</param>
        /// <param name="success">Callback for success transaction</param>
        /// <param name="failure">Callback for fail transaction</param>
        /// <param name="navigationController">Navigation controller from UI this can be Null for non-UI Mode API</param>
        public void PreAuth(PaymentViewModel preAuthorisation, JudoSuccessCallback success, JudoFailureCallback failure)
        {
            RootCheck(failure);

            var innerModel = preAuthorisation.Clone();

            _judoSdkApi.PreAuth(innerModel, success, failure);
        }
Beispiel #26
0
        public void PreAuth(PaymentViewModel preAuthorisation, JudoSuccessCallback success, JudoFailureCallback failure, Activity context)
        {
            EvaluateRootCheck(failure);
            var innerModel = preAuthorisation.Clone();

            _judoSdkApi.PreAuth(innerModel, success, failure, context);
        }
Beispiel #27
0
 public void SetupWebView(IPaymentService paymentService, JudoSuccessCallback successCallback, JudoFailureCallback failureCallback)
 {
     _paymentService  = paymentService;
     _successCallback = successCallback;
     _failureCallback = failureCallback;
 }