Exemplo n.º 1
0
        /// <summary>
        /// Gets a <see cref="IPaymentGatewayMethod"/> by it's unique 'key'
        /// </summary>
        /// <param name="paymentMethodKey">The key of the <see cref="IPaymentMethod"/></param>
        /// <returns>A <see cref="IPaymentGatewayMethod"/></returns>
        public override IPaymentGatewayMethod GetPaymentGatewayMethodByKey(Guid paymentMethodKey)
        {
            var paymentMethod = PaymentMethods.FirstOrDefault(x => x.Key == paymentMethodKey);

            if (paymentMethod == null)
            {
                throw new NullReferenceException("PaymentMethod not found");
            }

            return(new CashPaymentGatewayMethod(GatewayProviderService, paymentMethod));
        }
Exemplo n.º 2
0
        public override IPaymentGatewayMethod GetPaymentGatewayMethodByPaymentCode(string paymentCode)
        {
            var paymentMethod = PaymentMethods.FirstOrDefault(x => x.PaymentCode == paymentCode);

            if (paymentMethod == null)
            {
                throw new NullReferenceException("PaymentMethod not found");
            }

            return(new TestingPaymentGatewayMethod(GatewayProviderService, paymentMethod));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a <see cref="IPaymentGatewayMethod"/> by it's unique 'key'
        /// </summary>
        /// <param name="paymentMethodKey">The key of the <see cref="IPaymentMethod"/></param>
        /// <returns>A <see cref="IPaymentGatewayMethod"/></returns>
        public override IPaymentGatewayMethod GetPaymentGatewayMethodByKey(Guid paymentMethodKey)
        {
            var paymentMethod = PaymentMethods.FirstOrDefault(x => x.Key == paymentMethodKey);

            if (paymentMethod == null)
            {
                throw new NullReferenceException("PaymentMethod not found");
            }

            return(new PurchaseOrderPaymentGatewayMethod(GatewayProviderService, paymentMethod, GatewayProviderSettings.ExtendedData));
        }
        /// <summary>
        /// Get's a <see cref="SagePayFormPaymentGatewayMethod"/> by it's payment code (service code).
        /// </summary>
        /// <param name="paymentCode">
        /// The payment code.
        /// </param>
        /// <returns>
        /// The <see cref="IPaymentGatewayMethod"/>.
        /// </returns>
        public override IPaymentGatewayMethod GetPaymentGatewayMethodByPaymentCode(string paymentCode)
        {
            var paymentMethod = PaymentMethods.FirstOrDefault(x => x.PaymentCode == paymentCode);


            if (paymentMethod != null)
            {
                return(paymentMethod.PaymentCode == "SagePay Form" ?
                       (IPaymentGatewayMethod) new SagePayFormPaymentGatewayMethod(GatewayProviderService, paymentMethod, GatewayProviderSettings.ExtendedData) :
                       new SagePayDirectPaymentGatewayMethod(GatewayProviderService, paymentMethod, GatewayProviderSettings.ExtendedData));
            }

            throw new NullReferenceException("Failed to find PaymentMethod with key specified");
        }
Exemplo n.º 5
0
        protected override async Task OnParametersSetAsync()
        {
            OrderParams = CartService.GetOrderParams(SellerId);

            if (OrderParams != null)
            {
                PaymentMethods = await HttpClient.GetFromJsonAsync <string[]>($"api/payments/{SellerId}");

                if (string.IsNullOrEmpty(OrderParams.PaymentMethod))
                {
                    await ChangePaymentMethod(PaymentMethods.FirstOrDefault());
                }
            }

            isLoaded = true;
        }
        /// <summary>
        /// Gets a <see cref="IPaymentGatewayMethod"/> by it's payment code
        /// </summary>
        /// <param name="paymentCode">The payment code of the <see cref="IPaymentGatewayMethod"/></param>
        /// <returns>A <see cref="IPaymentGatewayMethod"/></returns>
        public override IPaymentGatewayMethod GetPaymentGatewayMethodByPaymentCode(string paymentCode)
        {
            var paymentMethod = PaymentMethods.FirstOrDefault(x => x.PaymentCode == paymentCode);

            if (paymentMethod != null)
            {
                return(paymentMethod.PaymentCode == "Transaction" ?
                       (IPaymentGatewayMethod) new BraintreeSimpleTransactionPaymentGatewayMethod(GatewayProviderService, paymentMethod, BraintreeApiService) :
                       new BraintreeVaultTransactionPaymentGatewayMethod(GatewayProviderService, paymentMethod, BraintreeApiService));
            }

            var error = new NullReferenceException("Failed to find BraintreePaymentGatewayMethod with key specified");

            LogHelper.Error <BraintreePaymentGatewayProvider>("Failed to find BraintreePaymentGatewayMethod with key specified", error);
            throw error;
        }
Exemplo n.º 7
0
 private bool NextStepEnable()
 {
     if (_showCustomerInfo)
     {
         //return !(string.IsNullOrEmpty(Customer.Address) || string.IsNullOrEmpty(Customer.Apt) || string.IsNullOrEmpty(Customer.City) ||
         //    string.IsNullOrEmpty(Customer.Coutry) || string.IsNullOrEmpty(Customer.Email) ||
         //    string.IsNullOrEmpty(Customer.FirstName) ||
         //    string.IsNullOrEmpty(Customer.LastName) ||
         //    string.IsNullOrEmpty(Customer.PostalCode));
         return(CustomerFields().Any(String.IsNullOrEmpty));
     }
     if (_showShippingInfo)
     {
         return(!string.IsNullOrEmpty(_shippingMethodId));
     }
     return(PaymentMethods.FirstOrDefault(x => x.IsSelect) != null);
 }
        public async Task Refresh()
        {
            var selectedPaymentMethodId = PaymentMethods.FirstOrDefault(p => p.Selected)?.PaymentMethod.Id;

            PaymentMethods.Clear();
            try {
                var stripeClient = await EphemeralService.Instance.GetClient();

                var customerId = await EphemeralService.Instance.GetCustomerId();

                var customerService = new CustomerService(stripeClient);
                _customer = await customerService.GetAsync(customerId);


                var paymentMethodService     = new PaymentMethodService(stripeClient);
                var paymentMethodListOptions = new PaymentMethodListOptions {
                    Customer = _customer.Id,
                    Type     = "card"
                };
                var methods = await paymentMethodService.ListAsync(paymentMethodListOptions);

                foreach (var paymentMethod in methods)
                {
                    PaymentMethods.Add(new PaymentMethodViewModel(paymentMethod, PaymentMethodSelected));
                }

                if (PaymentMethods.Any())
                {
                    var toSelect = PaymentMethods.FirstOrDefault(pm => pm.PaymentMethod.Id == selectedPaymentMethodId) ??
                                   PaymentMethods.First();
                    SelectPaymentMethod(toSelect);
                }
            }
            catch (Exception ex) {
                await Navigator.ShowMessage("Error", ex.Message);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets a <see cref="IPaymentGatewayMethod"/> by it's payment code
        /// </summary>
        /// <param name="paymentCode">The payment code of the <see cref="IPaymentGatewayMethod"/></param>
        /// <returns>A <see cref="IPaymentGatewayMethod"/></returns>
        public override IPaymentGatewayMethod GetPaymentGatewayMethodByPaymentCode(string paymentCode)
        {
            var paymentMethod = PaymentMethods.FirstOrDefault(x => x.PaymentCode == paymentCode);

            if (paymentMethod != null)
            {
                switch (paymentMethod.PaymentCode)
                {
                case Constants.PaymentCodes.VaultTransaction:
                    return(new BraintreeVaultTransactionPaymentGatewayMethod(this.GatewayProviderService, paymentMethod, this.GetBraintreeApiService()));

                case Constants.PaymentCodes.RecordSubscriptionTransaction:
                    return(new BraintreeSubscriptionRecordPaymentMethod(GatewayProviderService, paymentMethod, this.GetBraintreeApiService()));

                default:
                    return(new BraintreeStandardTransactionPaymentGatewayMethod(GatewayProviderService, paymentMethod, this.GetBraintreeApiService()));
                }
            }

            var error = new NullReferenceException("Failed to find BraintreePaymentGatewayMethod with key specified");

            LogHelper.Error <BraintreePaymentGatewayProvider>("Failed to find BraintreePaymentGatewayMethod with key specified", error);
            throw error;
        }
Exemplo n.º 10
0
        private async Task InitData(string cartParam)
        {
            ShippingAddress = "You don't have a shipping address";
            bool hasShipppingAddress = false;
            int  customerId          = 0;

            CustomerInfo = await _wooCommerceService.GetCustomerInfo(GlobalSettings.User.Id);

            if (CustomerInfo != null && CustomerInfo.Shipping != null && !string.IsNullOrEmpty(CustomerInfo.Shipping.Address1))
            {
                ShippingAddress     = CustomerInfo.Shipping.Address1;
                hasShipppingAddress = true;
            }

            Name = GlobalSettings.User.Name;

            var taxRatesListRequest = new TaxRatesListRequest();
            await WebRequestExecuter.Execute(async() => await _wooCommerceService.GetTaxRates(taxRatesListRequest), myTaxRates =>
            {
                if (myTaxRates.Count != 0)
                {
                    TaxRates       = new ObservableCollection <TaxRatesModel>(myTaxRates);
                    DefaultTaxRate = TaxRates.FirstOrDefault();
                }
                return(Task.CompletedTask);
            });

            var carts = QueryStringHelpers.GetData <List <CartItemModel> >(cartParam);

            Carts = new ObservableCollection <CartItemModel>(carts);

            UpdateOrderSummaryUI();

            var paymentMethods = await _wooCommerceService.GetPaymentMethods();

            if (paymentMethods != null)
            {
                PaymentMethods = paymentMethods.Where(x => x.Enabled).OrderBy(x => x.Order).ToList();
                SelectedMethod = PaymentMethods.FirstOrDefault();

                UpdateSelectedPaymentMethod();
            }

            bool isGranted = await AppHelpers.RequestPermission(Permission.Location);

            if (isGranted && !hasShipppingAddress)
            {
                var myPosition = await AppHelpers.GetCurrentPosition();

                if (myPosition != null)
                {
                    try
                    {
                        var placemarks = await Geocoding.GetPlacemarksAsync(myPosition.Latitude, myPosition.Longitude);

                        var place = placemarks.FirstOrDefault();

                        ShippingAddress    = $"{place.FeatureName} {place.Thoroughfare ?? place.SubThoroughfare}, {place.SubAdminArea}, {place.AdminArea}";
                        MapCameraInitPoint = $"{place.Location.Latitude}, {place.Location.Longitude}, 13, 30, 60";

                        var pin = new Pin
                        {
                            Type     = PinType.Place,
                            Label    = place.CountryName,
                            Address  = place.FeatureName,
                            Icon     = BitmapDescriptorFactory.FromBundle(GlobalSettings.AppConst.StorePinImage),
                            Position = new Xamarin.Forms.GoogleMaps.Position(myPosition.Latitude, myPosition.Longitude)
                        };
                        MessagingCenter.Send(pin, MessagingCenterKeys.OnDrawMapsPinSelectedStore);
                    }
                    catch (FeatureNotSupportedException fnsEx)
                    {
                        // Feature not supported on device
                    }
                    catch (Exception ex)
                    {
                        // Handle exception that may have occurred in geocoding
                    }
                }
            }
        }